From b0dd10f8171945e0c1f3527dd1e9d18b043e01a7 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 25 Aug 2006 17:25:49 +0000 Subject: Initial Import --- system/libraries/Benchmark.php | 117 +++ system/libraries/Calendar.php | 473 +++++++++++ system/libraries/Config.php | 181 ++++ system/libraries/Controller.php | 445 ++++++++++ system/libraries/Email.php | 1740 +++++++++++++++++++++++++++++++++++++++ system/libraries/Encrypt.php | 378 +++++++++ system/libraries/Exceptions.php | 165 ++++ system/libraries/Hooks.php | 237 ++++++ system/libraries/Image_lib.php | 1550 ++++++++++++++++++++++++++++++++++ system/libraries/Input.php | 585 +++++++++++++ system/libraries/Language.php | 113 +++ system/libraries/Loader.php | 611 ++++++++++++++ system/libraries/Log.php | 117 +++ system/libraries/Model.php | 72 ++ system/libraries/Output.php | 241 ++++++ system/libraries/Pagination.php | 207 +++++ system/libraries/Parser.php | 178 ++++ system/libraries/Router.php | 318 +++++++ system/libraries/Session.php | 499 +++++++++++ system/libraries/Sha1.php | 254 ++++++ system/libraries/Trackback.php | 561 +++++++++++++ system/libraries/URI.php | 243 ++++++ system/libraries/Unit_test.php | 331 ++++++++ system/libraries/Upload.php | 775 +++++++++++++++++ system/libraries/Validation.php | 692 ++++++++++++++++ system/libraries/Xmlrpc.php | 1409 +++++++++++++++++++++++++++++++ system/libraries/Xmlrpcs.php | 492 +++++++++++ system/libraries/index.html | 15 + 28 files changed, 12999 insertions(+) create mode 100644 system/libraries/Benchmark.php create mode 100644 system/libraries/Calendar.php create mode 100644 system/libraries/Config.php create mode 100644 system/libraries/Controller.php create mode 100644 system/libraries/Email.php create mode 100644 system/libraries/Encrypt.php create mode 100644 system/libraries/Exceptions.php create mode 100644 system/libraries/Hooks.php create mode 100644 system/libraries/Image_lib.php create mode 100644 system/libraries/Input.php create mode 100644 system/libraries/Language.php create mode 100644 system/libraries/Loader.php create mode 100644 system/libraries/Log.php create mode 100644 system/libraries/Model.php create mode 100644 system/libraries/Output.php create mode 100644 system/libraries/Pagination.php create mode 100644 system/libraries/Parser.php create mode 100644 system/libraries/Router.php create mode 100644 system/libraries/Session.php create mode 100644 system/libraries/Sha1.php create mode 100644 system/libraries/Trackback.php create mode 100644 system/libraries/URI.php create mode 100644 system/libraries/Unit_test.php create mode 100644 system/libraries/Upload.php create mode 100644 system/libraries/Validation.php create mode 100644 system/libraries/Xmlrpc.php create mode 100644 system/libraries/Xmlrpcs.php create mode 100644 system/libraries/index.html (limited to 'system/libraries') diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php new file mode 100644 index 000000000..9dd9d4ac4 --- /dev/null +++ b/system/libraries/Benchmark.php @@ -0,0 +1,117 @@ +marker[$name] = microtime(); + } + // END mark() + + // -------------------------------------------------------------------- + + /** + * Calculates the time difference between two marked points. + * + * If the first parameter is empty this function instead returns the + * {elapsed_time} pseudo-variable. This permits the the full system + * execution time to be shown in a template. The output class will + * swap the real value for this variable. + * + * @access public + * @param string a paricular marked point + * @param string a paricular marked point + * @param integer the number of decimal places + * @return mixed + */ + function elapsed_time($point1 = '', $point2 = '', $decimals = 4) + { + if ($point1 == '') + { + return '{elapsed_time}'; + } + + if ( ! isset($this->marker[$point2])) + $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); + } + // END elapsed_time() + + // -------------------------------------------------------------------- + + /** + * Memory Usage + * + * This function returns the {memory_usage} pseudo-variable. + * This permits it to be put it anywhere in a template + * without the memory being calculated until the end. + * The output class will swap the real value for this variable. + * + * @access public + * @return string + */ + function memory_usage() + { + return '{memory_usage}'; + } + // END memory_usage() + +} + +// END CI_Benchmark class +?> \ No newline at end of file diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php new file mode 100644 index 000000000..013f06796 --- /dev/null +++ b/system/libraries/Calendar.php @@ -0,0 +1,473 @@ +obj =& get_instance(); + if ( ! in_array('calendar_lang'.EXT, $this->obj->lang->is_loaded)) + { + $this->obj->lang->load('calendar'); + } + + $this->local_time = time(); + log_message('debug', "Calendar Class Initialized"); + } + // END CI_Calendar() + + // -------------------------------------------------------------------- + + /** + * Initialize the user preferences + * + * Accepts an associative array as input, containing display preferences + * + * @access public + * @param array config preferences + * @return void + */ + function initialize($config = array()) + { + foreach ($config as $key => $val) + { + if (isset($this->$key)) + { + $this->$key = $val; + } + } + } + // END initialize() + + // -------------------------------------------------------------------- + + /** + * Generate the calendar + * + * @access public + * @param integer the year + * @param integer the month + * @param array the data to be shown in the calendar cells + * @return string + */ + function generate($year = '', $month = '', $data = array()) + { + // 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) + $year = '200'.$year; + + if (strlen($year) == 2) + $year = '20'.$year; + + 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 + $out = $this->temp['table_open']; + $out .= "\n"; + + $out .= "\n"; + $out .= $this->temp['heading_row_start']; + $out .= "\n"; + + // "previous" month link + if ($this->show_next_prev == TRUE) + { + $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"; + } + + // 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 .= $this->temp['heading_row_end']; + $out .= "\n"; + + // Write the cells containing the days of the week + $out .= "\n"; + $out .= $this->temp['week_row_start']; + $out .= "\n"; + + $day_names = $this->get_day_names(); + + for ($i = 0; $i < 7; $i ++) + { + $out .= str_replace('{week_day}', $day_names[($start_day + $i) %7], $this->temp['week_day_cell']); + } + + $out .= "\n"; + $out .= $this->temp['week_row_end']; + $out .= "\n"; + + // Build the main body of the calendar + while ($day <= $total_days) + { + $out .= "\n"; + $out .= $this->temp['cal_row_start']; + $out .= "\n"; + + 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)); + } + else + { + // Cells with no content + $temp = ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_no_content_today'] : $this->temp['cal_cell_no_content']; + $out .= str_replace('{day}', $day, $temp); + } + } + else + { + // 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']; + $day++; + } + + $out .= "\n"; + $out .= $this->temp['cal_row_end']; + $out .= "\n"; + } + + $out .= "\n"; + $out .= $this->temp['table_close']; + + return $out; + } + // END generate() + + // -------------------------------------------------------------------- + + /** + * Get Month Name + * + * Generates a texual month name based on the numeric + * month provided. + * + * @access public + * @parm integer the month + * @return string + */ + function get_month_name($month) + { + if ($this->month_type == 'short') + { + $month_names = array('01' => 'cal_jan', '02' => 'cal_feb', '03' => 'cal_mar', '04' => 'cal_apr', '05' => 'cal_may', '06' => 'cal_jun', '07' => 'cal_jul', '08' => 'cal_aug', '09' => 'cal_sep', '10' => 'cal_oct', '11' => 'cal_nov', '12' => 'cal_dec'); + } + else + { + $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_novermber', '12' => 'cal_december'); + } + + $month = $month_names[$month]; + + if ($this->obj->lang->line($month) === FALSE) + { + return ucfirst(str_replace('cal_', '', $month)); + } + + return $this->obj->lang->line($month); + } + // END get_month_name() + + // -------------------------------------------------------------------- + + /** + * Get Day Names + * + * Returns an array of day names (Sunday, Monday, etc.) based + * on the type. Options: long, short, abrev + * + * @access public + * @param string + * @return array + */ + function get_day_names($day_type = '') + { + if ($day_type != '') + $this->day_type = $day_type; + + if ($this->day_type == 'long') + { + $day_names = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'); + } + elseif ($this->day_type == 'short') + { + $day_names = array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'); + } + else + { + $day_names = array('su', 'mo', 'tu', 'we', 'th', 'fr', 'sa'); + } + + $days = array(); + foreach ($day_names as $val) + { + $days[] = ($this->obj->lang->line('cal_'.$val) === FALSE) ? ucfirst($val) : $this->obj->lang->line('cal_'.$val); + } + + return $days; + } + // END get_day_names() + + // -------------------------------------------------------------------- + + /** + * Adjust Date + * + * This function makes sure that we have a valid month/year. + * For example, if you submit 13 as the month, the year will + * increment and the month will become January. + * + * @access public + * @param integer the month + * @param integer the year + * @return array + */ + function adjust_date($month, $year) + { + $date = array(); + + $date['month'] = $month; + $date['year'] = $year; + + while ($date['month'] > 12) + { + $date['month'] -= 12; + $date['year']++; + } + + while ($date['month'] <= 0) + { + $date['month'] += 12; + $date['year']--; + } + + if (strlen($date['month']) == 1) + { + $date['month'] = '0'.$date['month']; + } + + return $date; + } + // END adjust_date() + + // -------------------------------------------------------------------- + + /** + * Total days in a given month + * + * @access public + * @param integer the month + * @param integer the year + * @return integer + */ + function get_total_days($month, $year) + { + $days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); + + if ($month < 1 OR $month > 12) + { + return 0; + } + + if ($month == 2) + { + if ($year % 400 == 0 OR ($year % 4 == 0 AND $year % 100 != 0)) + { + return 29; + } + } + + return $days_in_month[$month - 1]; + } + // END get_total_days() + + // -------------------------------------------------------------------- + + /** + * Set Default Template Data + * + * This is used in the event that the user has not created their own template + * + * @access public + * @return array + */ + function default_template() + { + return array ( + 'table_open' => '', + '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_end_today' => '', + 'cal_row_end' => '', + 'table_close' => '
<<{heading}>>
{week_day}
', + 'cal_cell_start_today' => '', + 'cal_cell_content' => '{day}', + 'cal_cell_content_today' => '{day}', + 'cal_cell_no_content' => '{day}', + 'cal_cell_no_content_today' => '{day}', + 'cal_cell_blank' => ' ', + 'cal_cell_end' => '
' + ); + } + // END default_template() + + // -------------------------------------------------------------------- + + /** + * Parse Template + * + * Harvests the data within the template {pseudo-variables} + * used to display the calendar + * + * @access public + * @return void + */ + function parse_template() + { + $this->temp = $this->default_template(); + + 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)) + { + $this->temp[$val] = $match['1']; + } + else + { + if (in_array($val, $today)) + { + $this->temp[$val] = $this->temp[str_replace('_today', '', $val)]; + } + } + } + } + // END parse_template() + +} + +// END CI_Calendar class +?> \ No newline at end of file diff --git a/system/libraries/Config.php b/system/libraries/Config.php new file mode 100644 index 000000000..85b295796 --- /dev/null +++ b/system/libraries/Config.php @@ -0,0 +1,181 @@ +config =& _get_config(); + log_message('debug', "Config Class Initialized"); + } + // END CI_Config() + + + // -------------------------------------------------------------------- + + /** + * Load Config File + * + * @access public + * @param string the config file name + * @return void + */ + function load($file = '') + { + $file = ($file == '') ? 'config' : str_replace(EXT, '', $file); + + if (in_array($file, $this->is_loaded)) + { + return; + } + + include_once(APPPATH.'config/'.$file.EXT); + + if ( ! isset($config) OR ! is_array($config)) + { + show_error('Your '.$file.EXT.' file does not appear to contain a valid configuration array.'); + } + + $this->config = array_merge($this->config, $config); + + $this->is_loaded[] = $file; + unset($config); + + log_message('debug', 'Config file loaded: config/'.$file.EXT); + } + // END load() + + // -------------------------------------------------------------------- + + /** + * Fetch a config file item + * + * The second parameter allows a slash to be added to the end of + * the item, in the case of a path. + * + * @access public + * @param string the config item name + * @param bool + * @return string + */ + function item($item, $slash = FALSE) + { + if ( ! isset($this->config[$item])) + { + return FALSE; + } + + $pref = $this->config[$item]; + + if ($pref == '') + { + return $pref; + } + + if ($slash !== FALSE AND ereg("/$", $pref) === FALSE) + { + $pref .= '/'; + } + + return $pref; + } + // END item() + + // -------------------------------------------------------------------- + + /** + * Site URL + * + * @access public + * @param string the URI string + * @return string + */ + function site_url($uri = '') + { + if (is_array($uri)) + { + $uri = implode('/', $uri); + } + + if ($uri == '') + { + return $this->item('base_url', 1).$this->item('index_page'); + } + else + { + $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix'); + return $this->item('base_url', 1).$this->item('index_page', 1).preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix; + } + } + // END site_url() + + // -------------------------------------------------------------------- + + /** + * System URL + * + * @access public + * @return string + */ + function system_url() + { + $x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH)); + return $this->item('base_url', 1).end($x).'/'; + } + // END system_url() + + // -------------------------------------------------------------------- + + /** + * Set a config file item + * + * @access public + * @param string the config item key + * @param string the config item value + * @return void + */ + function set_item($item, $value) + { + $this->config[$item] = $value; + } + // END set_item() + +} + +// END CI_Config class +?> \ No newline at end of file diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php new file mode 100644 index 000000000..ec21f8d66 --- /dev/null +++ b/system/libraries/Controller.php @@ -0,0 +1,445 @@ +_ci_assign_core(); + + // Load everything specified in the autoload.php file + $this->load->_ci_autoloader($this->_ci_autoload()); + + // This allows anything loaded using $this->load (viwes, files, etc.) + // to become accessible from within the Controller class functions. + foreach ($this->ci_is_loaded as $val) + { + $this->load->$val =& $this->$val; + } + + log_message('debug', "Controller Class Initialized"); + } + // END Controller() + + // -------------------------------------------------------------------- + + /** + * Initialization Handler + * + * Looks for the existence of a handler method and calls it + * + * @access private + * @param string the item that is being loaded + * @param mixed any additional parameters + * @return void + */ + function _ci_initialize($what, $params = FALSE) + { + $method = '_ci_init_'.strtolower(str_replace(EXT, '', $what)); + + if ( ! method_exists($this, $method)) + { + $method = substr($method, 4); + + if ( ! file_exists(APPPATH.'init/'.$method.EXT)) + { + if ( ! file_exists(BASEPATH.'init/'.$method.EXT)) + { + log_message('error', "Unable to load the requested class: ".$what); + show_error("Unable to load the class: ".$what); + } + + include(BASEPATH.'init/'.$method.EXT); + } + else + { + include(APPPATH.'init/'.$method.EXT); + } + } + else + { + if ($params === FALSE) + { + $this->$method(); + } + else + { + $this->$method($params); + } + } + } + // END _ci_initialize() + + // -------------------------------------------------------------------- + + /** + * Loads and instantiates the requested model class + * + * @access private + * @param string + * @return array + */ + function _ci_load_model($model, $name = '', $db_conn = FALSE) + { + if ($name == '') + { + $name = $model; + } + + if (isset($this->$name)) + { + show_error('The model name you are loading is the name of a resource that is already being used: '.$name); + } + + $model = strtolower($model); + + if ( ! file_exists(APPPATH.'models/'.$model.EXT)) + { + show_error('Unable to locate the model you have specified: '.$model); + } + + if ($db_conn !== FALSE) + { + if ($db_conn === TRUE) + $db_conn = ''; + + $this->_ci_init_database($db_conn, FALSE, TRUE); + } + + if ( ! class_exists('Model')) + { + require_once(BASEPATH.'libraries/Model'.EXT); + } + + require_once(APPPATH.'models/'.$model.EXT); + + $model = ucfirst($model); + $this->$name = new $model(); + $this->_ci_models[] = $name; + $this->_ci_assign_to_models(); + } + // END _ci_load_model() + + + // -------------------------------------------------------------------- + + /** + * Assign to Models + * + * Makes sure that anything loaded by the loader class (libraries, plugins, etc.) + * will be available to modles, if any exist. + * + * @access public + * @param object + * @return array + */ + function _ci_assign_to_models() + { + $obj =& get_instance(); + if (count($obj->_ci_models) == 0) + { + return; + } + foreach ($obj->_ci_models as $model) + { + $obj->$model->_assign_libraries(); + } + } + // END _ci_assign_to_models() + + + // -------------------------------------------------------------------- + + /** + * Auto-initialize Core Classes + * + * This initializes the core systems that are specified in the + * libraries/autoload.php file, as well as the systems specified in + * the $autoload class array above. + * + * It returns the "autoload" array so we can pass it to the Loader + * class since it needs to autoload plugins and helper files + * + * The config/autoload.php file contains an array that permits + * sub-systems to be loaded automatically. + * + * @access private + * @return array + */ + function _ci_autoload() + { + include_once(APPPATH.'config/autoload'.EXT); + + if ( ! isset($autoload)) + { + return FALSE; + } + + if (count($autoload['config']) > 0) + { + foreach ($autoload['config'] as $key => $val) + { + $this->config->load($val); + } + } + unset($autoload['config']); + + if ( ! is_array($autoload['core'])) + { + $autoload['core'] = array($autoload['core']); + } + + foreach ($autoload['core'] as $item) + { + $this->_ci_initialize($item); + } + + return $autoload; + } + // END _ci_autoload() + + // -------------------------------------------------------------------- + + /** + * Assign the core classes to the global $CI object + * + * By assigning all the classes instantiated by the front controller + * local class variables we enable everything to be accessible using + * $this->class->function() + * + * @access private + * @return void + */ + function _ci_assign_core() + { + foreach (array('Config', 'Input', 'Benchmark', 'URI', 'Output') as $val) + { + $class = strtolower($val); + $this->$class =& _load_class('CI_'.$val); + $this->ci_is_loaded[] = $class; + } + + $this->lang =& _load_class('CI_Language'); + $this->ci_is_loaded[] = 'lang'; + + // In PHP 4 the Controller class is a child of CI_Loader. + // In PHP 5 we run it as its own class. + if (floor(phpversion()) >= 5) + { + $this->load = new CI_Loader(); + } + + $this->ci_is_loaded[] = 'load'; + } + // END _ci_assign_core() + + // -------------------------------------------------------------------- + + /** + * Initialize Scaffolding + * + * This initializing function works a bit different than the + * others. It doesn't load the class. Instead, it simply + * sets a flag indicating that scaffolding is allowed to be + * used. The actual scaffolding function below is + * called by the front controller based on whether the + * second segment of the URL matches the "secret" scaffolding + * word stored in the application/config/routes.php + * + * @access private + * @param string the table to scaffold + * @return void + */ + function _ci_init_scaffolding($table = FALSE) + { + if ($table === FALSE) + { + show_error('You must include the name of the table you would like access when you initialize scaffolding'); + } + + $this->_ci_scaffolding = TRUE; + $this->_ci_scaff_table = $table; + } + // END _ci_init_scaffolding() + + // -------------------------------------------------------------------- + + /** + * Initialize Database + * + * @access private + * @param mixed database connection values + * @param bool whether to return the object for multiple connections + * @return void + */ + function _ci_init_database($params = '', $return = FALSE, $active_record = FALSE) + { + if ($this->_ci_is_loaded('db') == TRUE AND $return == FALSE AND $active_record == FALSE) + { + return; + } + + // Load the DB config file if needed + if (is_string($params) AND strpos($params, '://') === FALSE) + { + include(APPPATH.'config/database'.EXT); + + $group = ($params == '') ? $active_group : $params; + + if ( ! isset($db[$group])) + { + show_error('You have specified an invalid database connection group: '.$group); + } + + $params = $db[$group]; + } + + // No DB specified yet? Beat them senseless... + if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '') + { + show_error('You have not selected a database type to connect to.'); + } + + // Load the DB classes. Note: Since the active record class is optional + // 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 == TRUE) + { + $params['active_r'] = TRUE; + } + + require_once(BASEPATH.'drivers/DB_driver'.EXT); + + if ( ! isset($params['active_r']) OR $params['active_r'] == TRUE) + { + require_once(BASEPATH.'drivers/DB_active_record'.EXT); + + if ( ! class_exists('CI_DB')) + { + eval('class CI_DB extends CI_DB_active_record { }'); + } + } + else + { + if ( ! class_exists('CI_DB')) + { + eval('class CI_DB extends CI_DB_driver { }'); + } + } + + require_once(BASEPATH.'drivers/DB_'.$params['dbdriver'].EXT); + + // Instantiate the DB adapter + $driver = 'CI_DB_'. $params['dbdriver']; + $DB = new $driver($params); + + if ($return === TRUE) + { + return $DB; + } + + $obj =& get_instance(); + $obj->ci_is_loaded[] = 'db'; + $obj->db =& $DB; + } + // END _ci_init_database() + + // -------------------------------------------------------------------- + + /** + * Returns TRUE if a class is loaded, FALSE if not + * + * @access public + * @param string the class name + * @return bool + */ + function _ci_is_loaded($class) + { + return ( ! in_array($class, $this->ci_is_loaded)) ? FALSE : TRUE; + } + // END _ci_is_loaded() + + // -------------------------------------------------------------------- + + /** + * Scaffolding + * + * Initializes the scaffolding. + * + * @access private + * @return void + */ + function _ci_scaffolding() + { + if ($this->_ci_scaffolding === FALSE OR $this->_ci_scaff_table === FALSE) + { + show_404('Scaffolding unavailable'); + } + + if (class_exists('Scaffolding')) return; + + if ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'))) + { + $method = 'view'; + } + else + { + $method = $this->uri->segment(3); + } + + $this->_ci_init_database("", FALSE, TRUE); + + $this->_ci_initialize('pagination'); + require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); + $this->scaff = new Scaffolding($this->_ci_scaff_table); + $this->scaff->$method(); + } + // END _ci_scaffolding() + +} +// END _Controller class +?> \ No newline at end of file diff --git a/system/libraries/Email.php b/system/libraries/Email.php new file mode 100644 index 000000000..96dc0014d --- /dev/null +++ b/system/libraries/Email.php @@ -0,0 +1,1740 @@ + 0) + { + $this->initialize($config); + } + + log_message('debug', "Email Class Initialized"); + } + // END CI_Email() + + // -------------------------------------------------------------------- + + /** + * Initialize preferences + * + * @access public + * @param array + * @return void + */ + function initialize($config = array()) + { + $this->clear(); + foreach ($config as $key => $val) + { + if (isset($this->$key)) + { + $method = 'set_'.$key; + + if (method_exists($this, $method)) + { + $this->$method($val); + } + else + { + $this->$key = $val; + } + } + } + $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; + $this->_safe_mode = (@ini_get("safe_mode") == 0) ? FALSE : TRUE; + } + // END initialize() + + // -------------------------------------------------------------------- + + /** + * Initialize the Email Data + * + * @access public + * @return void + */ + function clear() + { + $this->_subject = ""; + $this->_body = ""; + $this->_finalbody = ""; + $this->_header_str = ""; + $this->_replyto_flag = FALSE; + $this->_recipients = array(); + $this->_headers = array(); + $this->_debug_msg = array(); + + $this->_set_header('User-Agent', $this->useragent); + $this->_set_header('Date', $this->_set_date()); + } + // END clear() + + // -------------------------------------------------------------------- + + /** + * Set FROM + * + * @access public + * @param string + * @param string + * @return void + */ + function from($from, $name = '') + { + if (preg_match( '/\<(.*)\>/', $from, $match)) + $from = $match['1']; + + if ($this->validate) + $this->validate_email($this->_str_to_array($from)); + + if ($name != '' && substr($name, 0, 1) != '"') + { + $name = '"'.$name.'"'; + } + + $this->_set_header('From', $name.' <'.$from.'>'); + $this->_set_header('Return-Path', '<'.$from.'>'); + } + // END from() + + // -------------------------------------------------------------------- + + /** + * Set Reply-to + * + * @access public + * @param string + * @param string + * @return void + */ + function reply_to($replyto, $name = '') + { + if (preg_match( '/\<(.*)\>/', $replyto, $match)) + $replyto = $match['1']; + + if ($this->validate) + $this->validate_email($this->_str_to_array($replyto)); + + if ($name == '') + { + $name = $replyto; + } + + if (substr($name, 0, 1) != '"') + { + $name = '"'.$name.'"'; + } + + $this->_set_header('Reply-To', $name.' <'.$replyto.'>'); + $this->_replyto_flag = TRUE; + } + // END reply_to() + + // -------------------------------------------------------------------- + + /** + * Set Recipients + * + * @access public + * @param string + * @return void + */ + function to($to) + { + $to = $this->_str_to_array($to); + $to = $this->clean_email($to); + + if ($this->validate) + $this->validate_email($to); + + if ($this->_get_protocol() != 'mail') + $this->_set_header('To', implode(", ", $to)); + + switch ($this->_get_protocol()) + { + case 'smtp' : $this->_recipients = $to; + break; + case 'sendmail' : $this->_recipients = implode(", ", $to); + break; + case 'mail' : $this->_recipients = implode(", ", $to); + break; + } + } + // END to() + + // -------------------------------------------------------------------- + + /** + * Set CC + * + * @access public + * @param string + * @return void + */ + function cc($cc) + { + $cc = $this->_str_to_array($cc); + $cc = $this->clean_email($cc); + + if ($this->validate) + $this->validate_email($cc); + + $this->_set_header('Cc', implode(", ", $cc)); + + if ($this->_get_protocol() == "smtp") + $this->_cc_array = $cc; + } + // END cc() + + // -------------------------------------------------------------------- + + /** + * Set BCC + * + * @access public + * @param string + * @param string + * @return void + */ + function bcc($bcc, $limit = '') + { + if ($limit != '' && ctype_digit($limit)) + { + $this->bcc_batch_mode = true; + $this->bcc_batch_size = $limit; + } + + $bcc = $this->_str_to_array($bcc); + $bcc = $this->clean_email($bcc); + + if ($this->validate) + $this->validate_email($bcc); + + if (($this->_get_protocol() == "smtp") OR ($this->bcc_batch_mode && count($bcc) > $this->bcc_batch_size)) + $this->_bcc_array = $bcc; + else + $this->_set_header('Bcc', implode(", ", $bcc)); + } + // END bcc() + + // -------------------------------------------------------------------- + + /** + * Set Email Subject + * + * @access public + * @param string + * @return void + */ + function subject($subject) + { + $subject = preg_replace("/(\r\n)|(\r)|(\n)/", "", $subject); + $subject = preg_replace("/(\t)/", " ", $subject); + + $this->_set_header('Subject', trim($subject)); + } + // END subject() + + // -------------------------------------------------------------------- + + /** + * Set Body + * + * @access public + * @param string + * @return void + */ + function message($body) + { + $body = rtrim(str_replace("\r", "", $body)); + + if ($this->wordwrap === TRUE AND $this->mailtype != 'html') + $this->_body = $this->word_wrap($body); + else + $this->_body = $body; + + $this->_body = stripslashes($this->_body); + } + // END message() + + // -------------------------------------------------------------------- + + /** + * Assign file attachments + * + * @access public + * @param string + * @return string + */ + function attach($filename, $disposition = 'attachment') + { + $this->_attach_name[] = $filename; + $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename)))); + $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters + } + // END attach() + + // -------------------------------------------------------------------- + + /** + * Add a Header Item + * + * @access public + * @param string + * @param string + * @return void + */ + function _set_header($header, $value) + { + $this->_headers[$header] = $value; + } + // END _set_header() + + // -------------------------------------------------------------------- + + /** + * Convert a String to an Array + * + * @access public + * @param string + * @return array + */ + function _str_to_array($email) + { + if ( ! is_array($email)) + { + if (ereg(',$', $email)) + $email = substr($email, 0, -1); + + if (ereg('^,', $email)) + $email = substr($email, 1); + + if (ereg(',', $email)) + { + $x = explode(',', $email); + $email = array(); + + for ($i = 0; $i < count($x); $i ++) + $email[] = trim($x[$i]); + } + else + { + $email = trim($email); + settype($email, "array"); + } + } + return $email; + } + // END _str_to_array() + + // -------------------------------------------------------------------- + + /** + * Set Multipart Value + * + * @access public + * @param string + * @return void + */ + function set_alt_message($str = '') + { + $this->alt_message = ($str == '') ? '' : $str; + } + // END set_alt_message() + + // -------------------------------------------------------------------- + + /** + * Set Mailtype + * + * @access public + * @param string + * @return void + */ + function set_mailtype($type = 'text') + { + $this->mailtype = ($type == 'html') ? 'html' : 'text'; + } + // END set_mailtype() + + // -------------------------------------------------------------------- + + /** + * Set Wordwrap + * + * @access public + * @param string + * @return void + */ + function set_wordwrap($wordwrap = TRUE) + { + $this->wordwrap = ($wordwrap === FALSE) ? FALSE : TRUE; + } + // END set_wordwrap() + + // -------------------------------------------------------------------- + + /** + * Set Protocal + * + * @access public + * @param string + * @return void + */ + function set_protocol($protocol = 'mail') + { + $this->protocol = ( ! in_array($protocol, $this->_protocols)) ? 'mail' : strtolower($protocol); + } + // END set_protocol() + + // -------------------------------------------------------------------- + + /** + * Set Priority + * + * @access public + * @param integer + * @return void + */ + function set_priority($n = 3) + { + if ( ! ctype_digit($n)) + { + $this->priority = 3; + return; + } + + if ($n < 1 OR $n > 5) + { + $this->priority = 3; + return; + } + + $this->priority = $n; + } + // END set_priority() + + // -------------------------------------------------------------------- + + /** + * Set Newline Character + * + * @access public + * @param string + * @return void + */ + function set_newline($newline = "\n") + { + if ($newline != "\n" OR $newline != "\r\n" OR $newline != "\r") + { + $this->newline = "\n"; + return; + } + + $this->newline = $newline; + } + // END set_newline() + + // -------------------------------------------------------------------- + + /** + * Set Message Boundry + * + * @access private + * @return void + */ + function _set_boundaries() + { + $this->_alt_boundary = "B_ALT_".uniqid(''); // mulipart/alternative + $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary + } + // END _set_boundaries() + + // -------------------------------------------------------------------- + + /** + * Get the Message ID + * + * @access private + * @return string + */ + function _get_message_id() + { + $from = $this->_headers['Return-Path']; + $from = str_replace(">", "", $from); + $from = str_replace("<", "", $from); + + return "<".uniqid('').strstr($from, '@').">"; + } + // END _get_message_id() + + // -------------------------------------------------------------------- + + /** + * Get Mail Protocol + * + * @access private + * @param bool + * @return string + */ + function _get_protocol($return = true) + { + $this->protocol = strtolower($this->protocol); + $this->protocol = ( ! in_array($this->protocol, $this->_protocols)) ? 'mail' : $this->protocol; + + if ($return == true) + return $this->protocol; + } + // END _get_protocol() + + // -------------------------------------------------------------------- + + /** + * Get Mail Encoding + * + * @access private + * @param bool + * @return string + */ + function _get_encoding($return = true) + { + $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '7bit' : $this->_encoding; + + if ( ! in_array($this->charset, $this->_base_charsets)) + $this->_encoding = "8bit"; + + if ($return == true) + return $this->_encoding; + } + // END _get_encoding() + + // -------------------------------------------------------------------- + + /** + * Get content type (text/html/attachment) + * + * @access private + * @return string + */ + function _get_content_type() + { + if ($this->mailtype == 'html' && count($this->_attach_name) == 0) + return 'html'; + + elseif ($this->mailtype == 'html' && count($this->_attach_name) > 0) + return 'html-attach'; + + elseif ($this->mailtype == 'text' && count($this->_attach_name) > 0) + return 'plain-attach'; + + else return 'plain'; + } + // END _get_content_type() + + // -------------------------------------------------------------------- + + /** + * Set RFC 822 Date + * + * @access public + * @return string + */ + function _set_date() + { + $timezone = date("Z"); + $operator = (substr($timezone, 0, 1) == '-') ? '-' : '+'; + $timezone = abs($timezone); + $timezone = ($timezone/3600) * 100 + ($timezone % 3600) /60; + + return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone); + } + // END _set_date() + + // -------------------------------------------------------------------- + + /** + * Mime message + * + * @access private + * @return string + */ + function _get_mime_message() + { + return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format."; + } + // END _get_mime_message() + + // -------------------------------------------------------------------- + + /** + * Validate Email Address + * + * @access public + * @param string + * @return bool + */ + function validate_email($email) + { + if ( ! is_array($email)) + { + $this->_set_error_message('email_must_be_array'); + return FALSE; + } + + foreach ($email as $val) + { + if ( ! $this->valid_email($val)) + { + $this->_set_error_message('email_invalid_address', $val); + return FALSE; + } + } + } + // END validate_email() + + // -------------------------------------------------------------------- + + /** + * Email Validation + * + * @access public + * @param string + * @return bool + */ + function valid_email($address) + { + if ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) + return FALSE; + else + return TRUE; + } + // END valid_email() + + // -------------------------------------------------------------------- + + /** + * Clean Extended Email Address: Joe Smith + * + * @access public + * @param string + * @return string + */ + function clean_email($email) + { + if ( ! is_array($email)) + { + if (preg_match('/\<(.*)\>/', $email, $match)) + return $match['1']; + else + return $email; + } + + $clean_email = array(); + + for ($i=0; $i < count($email); $i++) + { + if (preg_match( '/\<(.*)\>/', $email[$i], $match)) + $clean_email[] = $match['1']; + else + $clean_email[] = $email[$i]; + } + + return $clean_email; + } + // END clean_email() + + // -------------------------------------------------------------------- + + /** + * Build alternative plain text message + * + * This function provides the raw message for use + * in plain-text headers of HTML-formatted emails. + * If the user hasn't specified his own alternative message + * it creates one by stripping the HTML + * + * @access private + * @return string + */ + function _get_alt_message() + { + if (eregi( '\', $this->_body, $match)) + { + $body = $match['1']; + $body = substr($body, strpos($body, ">") + 1); + } + else + { + $body = $this->_body; + } + + $body = trim(strip_tags($body)); + $body = preg_replace( '# '.$message. ' '.$filepath.' '.$line, TRUE); + } + // END log_exception() + + // -------------------------------------------------------------------- + + /** + * 404 Page Not Found Handler + * + * @access private + * @param string + * @return string + */ + function show_404($page = '') + { + $heading = "404 Page Not Found"; + $message = "The page you requested was not found."; + + log_message('error', '404 Page Not Found --> '.$page); + echo $this->show_error($heading, $message, 'error_404'); + exit; + } + // END show_404() + + // -------------------------------------------------------------------- + + /** + * General Error Page + * + * This function takes an error message as input + * (either as a string or an array) and displayes + * it using the specified template. + * + * @access private + * @param string the heading + * @param string the message + * @param string the template name + * @return string + */ + function show_error($heading, $message, $template = 'error_general') + { + $message = '

'.implode('

', ( ! is_array($message)) ? array($message) : $message).'

'; + + ob_start(); + include_once(APPPATH.'errors/'.$template.EXT); + $buffer = ob_get_contents(); + ob_end_clean(); + return $buffer; + } + // END show_error() + + + // -------------------------------------------------------------------- + + /** + * Native PHP error handler + * + * @access private + * @param string the error severity + * @param string the error string + * @param string the error filepath + * @param string the error line number + * @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); + } + + ob_start(); + include_once(APPPATH.'errors/error_php'.EXT); + $buffer = ob_get_contents(); + ob_end_clean(); + echo $buffer; + } + // END show_php_error() + +// END Exceptions Class +} +?> \ No newline at end of file diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php new file mode 100644 index 000000000..389e7ac14 --- /dev/null +++ b/system/libraries/Hooks.php @@ -0,0 +1,237 @@ +item('enable_hooks') == FALSE) + { + return; + } + + // Grab the "hooks" definition file. + // If there are no hooks, we're done. + + @include(APPPATH.'config/hooks'.EXT); + + if ( ! isset($hook) OR ! is_array($hook)) + { + return; + } + + $this->hooks =& $hook; + $this->enabled = TRUE; + } + // END CI_Hooks() + + // -------------------------------------------------------------------- + + /** + * Does a given hook exist? + * + * Returns TRUE/FALSE based on whether a given hook exists + * + * @access private + * @param string + * @return bool + */ + function _hook_exists($which = '') + { + if ( ! $this->enabled) + { + return FALSE; + } + + if ( ! isset($this->hooks[$which])) + { + return FALSE; + } + + return TRUE; + } + // END hook_exists() + + + // -------------------------------------------------------------------- + + /** + * Call Hook + * + * Calls a particular hook + * + * @access private + * @param string the hook name + * @return mixed + */ + function _call_hook($which = '') + { + if (isset($this->hooks[$which][0]) AND is_array($this->hooks[$which][0])) + { + foreach ($this->hooks[$which] as $val) + { + $this->_run_hook($val); + } + } + else + { + $this->_run_hook($this->hooks[$which]); + } + } + // END hook_exists() + + // -------------------------------------------------------------------- + + /** + * Run Hook + * + * Runs a particular hook + * + * @access private + * @param array the hook details + * @return bool + */ + function _run_hook($data) + { + if ( ! is_array($data)) + { + return FALSE; + } + + // ----------------------------------- + // Safety - Prevents run-away loops + // ----------------------------------- + + // If the script being called happens to have the same + // extension call within it a loop can happen + + if ($this->in_progress == TRUE) + { + return; + } + + // ----------------------------------- + // Set file path + // ----------------------------------- + + if ( ! isset($data['filepath']) OR ! isset($data['filename'])) + { + return FALSE; + } + + $filepath = APPPATH.$data['filepath'].'/'.$data['filename']; + + if ( ! file_exists($filepath)) + { + return FALSE; + } + + // ----------------------------------- + // Set class/function name + // ----------------------------------- + + $class = FALSE; + $function = FALSE; + $params = ''; + + if (isset($data['class']) AND $data['class'] != '') + { + $class = $data['class']; + } + + if (isset($data['function'])) + { + $function = $data['function']; + } + + if (isset($data['params'])) + { + $params = $data['params']; + } + + if ($class === FALSE AND $function === FALSE) + { + return FALSE; + } + + // ----------------------------------- + // Set the in_progress flag + // ----------------------------------- + + $this->in_progress = TRUE; + + // ----------------------------------- + // Call the requested class and/or function + // ----------------------------------- + + if ($class !== FALSE) + { + if ( ! class_exists($class)) + { + require($filepath); + } + + $HOOK = new $class; + $HOOK->$function($params); + } + else + { + if ( ! function_exists($function)) + { + require($filepath); + } + + $function($params); + } + + $this->in_progress = FALSE; + return TRUE; + } + // END _run_hook() + + +} + +// END CI_Hooks class +?> \ No newline at end of file diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php new file mode 100644 index 000000000..854f0484b --- /dev/null +++ b/system/libraries/Image_lib.php @@ -0,0 +1,1550 @@ + 0) + { + $this->initialize($props); + } + + log_message('debug', "Image Lib Class Initialized"); + } + // END CI_Image_lib() + + // -------------------------------------------------------------------- + + /** + * Initialize image properties + * + * Resets values in case this class is used in a loop + * + * @access public + * @return void + */ + function clear() + { + $props = array('source_folder', 'dest_folder', 'source_image', 'full_src_path', 'full_dst_path', 'new_image', 'image_type', 'size_str', 'quality', 'orig_width', 'orig_height', 'rotation_angle', 'x_axis', 'y_axis', 'create_fnc', 'copy_fnc', 'wm_overlay_path', 'wm_use_truetype', 'dynamic_output', 'wm_font_size', 'wm_text', 'wm_vrt_alignment', 'wm_hor_alignment', 'wm_padding', 'wm_hor_offset', 'wm_vrt_offset', 'wm_font_color', 'wm_use_drop_shadow', 'wm_shadow_color', 'wm_shadow_distance', 'wm_opacity'); + + foreach ($props as $val) + { + $this->$val = ''; + } + } + // END clear() + + // -------------------------------------------------------------------- + + /** + * initialize image preferences + * + * @access public + * @param array + * @return void + */ + function initialize($props = array()) + { + /* + * Convert array elements into class variables + */ + if (count($props) > 0) + { + foreach ($props as $key => $val) + { + $this->$key = $val; + } + } + + /* + * Is there a source image? + * + * If not, there's no reason to continue + * + */ + if ($this->source_image == '') + { + $this->set_error('imglib_source_image_required'); + return FALSE; + } + /* + * Is getimagesize() Available? + * + * We use it to determine the image properties (width/height). + * Note: We need to figure out how to determine image + * properties using ImageMagick and NetPBM + * + */ + if ( ! function_exists('getimagesize')) + { + $this->set_error('imglib_gd_required_for_props'); + return FALSE; + } + + $this->image_library = strtolower($this->image_library); + + /* + * Set the full server path + * + * The source image may or may not contain a path. + * Either way, we'll try use realpath to generate the + * full server path in order to more reliably read it. + * + */ + if (function_exists('realpath') AND @realpath($this->source_image) !== FALSE) + { + $full_source_path = str_replace("\\", "/", realpath($this->source_image)); + } + else + { + $full_source_path = $this->source_image; + } + + $x = explode('/', $full_source_path); + $this->source_image = end($x); + $this->source_folder = str_replace($this->source_image, '', $full_source_path); + + // Set the Image Propterties + if ( ! $this->get_image_properties($this->source_folder.$this->source_image)) + { + return FALSE; + } + + /* + * Assign the "new" image name/path + * + * If the user has set a "new_image" name it means + * we are making a copy of the source image. If not + * it means we are altering the original. We'll + * set the destination filename and path accordingly. + * + */ + if ($this->new_image == '') + { + $this->dest_image = $this->source_image; + $this->dest_folder = $this->source_folder; + } + else + { + if (strpos($this->new_image, '/') === FALSE) + { + $this->dest_folder = $this->source_folder; + $this->dest_image = $this->new_image; + } + else + { + if (function_exists('realpath') AND @realpath($this->new_image) !== FALSE) + { + $full_dest_path = str_replace("\\", "/", realpath($this->new_image)); + } + else + { + $full_dest_path = $this->new_image; + } + + // Is there a file name? + if ( ! preg_match("#[\.jpg|\.jpeg|\.gif|\.png]$#i", $full_dest_path)) + { + $this->dest_folder = $full_dest_path.'/'; + $this->dest_image = $this->source_image; + } + else + { + $x = explode('/', $full_dest_path); + $this->dest_image = end($x); + $this->dest_folder = str_replace($this->dest_image, '', $full_dest_path); + } + } + } + + /* + * Compile the finalized filenames/paths + * + * We'll create two master strings containing the + * full server path to the source image and the + * full server path to the destination image. + * We'll also split the destination image name + * so we can insert the thumbnail marker if needed. + * + */ + if ($this->create_thumb === FALSE OR $this->thumb_marker == '') + { + $this->thumb_marker = ''; + } + + $xp = $this->explode_name($this->dest_image); + + $filename = $xp['name']; + $file_ext = $xp['ext']; + + $this->full_src_path = $this->source_folder.$this->source_image; + $this->full_dst_path = $this->dest_folder.$filename.$this->thumb_marker.$file_ext; + + /* + * Should we maintain image proportions? + * + * When creating thumbs or copies, the target width/height + * might not be in correct proportion with the source + * image's width/height. We'll recalculate it here. + * + */ + if ($this->maintain_ratio === TRUE && ($this->width != '' AND $this->height != '')) + { + $this->image_reproportion(); + } + + /* + * Was a width and height specified? + * + * If the destination width/height was + * not submitted we will use the values + * from the actual file + * + */ + if ($this->width == '') + $this->width = $this->orig_width; + + if ($this->height == '') + $this->height = $this->orig_height; + + // Set the quality + $this->quality = trim(str_replace("%", "", $this->quality)); + + if ($this->quality == '' OR $this->quality == 0 OR ! ctype_digit($this->quality)) + $this->quality = 90; + + // Set the x/y coordinates + $this->x_axis = ($this->x_axis == '' OR ! is_numeric($this->x_axis)) ? 0 : $this->x_axis; + $this->y_axis = ($this->y_axis == '' OR ! is_numeric($this->y_axis)) ? 0 : $this->y_axis; + + // Watermark-related Stuff... + if ($this->wm_font_color != '') + { + if (strlen($this->wm_font_color) == 6) + { + $this->wm_font_color = '#'.$this->wm_font_color; + } + } + + if ($this->wm_shadow_color != '') + { + if (strlen($this->wm_shadow_color) == 6) + { + $this->wm_shadow_color = '#'.$this->wm_shadow_color; + } + } + + if ($this->wm_overlay_path != '') + { + $this->wm_overlay_path = str_replace("\\", "/", realpath($this->wm_overlay_path)); + } + + if ($this->wm_shadow_color != '') + { + $this->wm_use_drop_shadow = TRUE; + } + + if ($this->wm_font_path != '') + { + $this->wm_use_truetype = TRUE; + } + + return TRUE; + } + // END initialize() + + // -------------------------------------------------------------------- + + /** + * Image Resize + * + * This is a wrapper function that chooses the proper + * resize function based on the protocol specified + * + * @access public + * @return bool + */ + function resize() + { + $protocol = 'image_process_'.$this->image_library; + + if (eregi("gd2$", $protocol)) + { + $protocol = 'image_process_gd'; + } + + return $this->$protocol('resize'); + } + // END resize() + + // -------------------------------------------------------------------- + + /** + * Image Crop + * + * This is a wrapper function that chooses the proper + * cropping function based on the protocol specified + * + * @access public + * @return bool + */ + function crop() + { + $protocol = 'image_process_'.$this->image_library; + + if (eregi("gd2$", $protocol)) + { + $protocol = 'image_process_gd'; + } + + return $this->$protocol('crop'); + } + // END crop() + + // -------------------------------------------------------------------- + + /** + * Image Rotate + * + * This is a wrapper function that chooses the proper + * rotation function based on the protocol specified + * + * @access public + * @return bool + */ + function rotate() + { + // Allowed rotation values + $degs = array(90, 180, 270, 'vrt', 'hor'); + + if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs)) + { + $this->set_error('imglib_rotation_angle_required'); + return FALSE; + } + + // Reassign the width and height + if ($this->rotation_angle == 90 OR $this->rotation_angle == 270) + { + $this->width = $this->orig_height; + $this->height = $this->orig_width; + } + else + { + $this->width = $this->orig_width; + $this->height = $this->orig_height; + } + + + // Choose resizing function + if ($this->image_library == 'imagemagick' OR $this->image_library == 'netpbm') + { + $protocol = 'image_process_'.$this->image_library; + + return $this->$protocol('rotate'); + } + + if ($this->rotation_angle == 'hor' OR $this->rotation_angle == 'vrt') + { + return $this->image_mirror_gd(); + } + else + { + return $this->image_rotate_gd(); + } + } + // END rotate() + + // -------------------------------------------------------------------- + + /** + * Image Process Using GD/GD2 + * + * This function will resize or crop + * + * @access public + * @param string + * @return bool + */ + function image_process_gd($action = 'resize') + { + $v2_override = FALSE; + + if ($action == 'crop') + { + // If the target width/height match the source then it's pointless to crop, right? + if ($this->width >= $this->orig_width AND $this->height >= $this->orig_width) + { + // We'll return true so the user thinks the process succeeded. + // It'll be our little secret... + + return TRUE; + } + + // Reassign the source width/height if cropping + $this->orig_width = $this->width; + $this->orig_height = $this->height; + + // GD 2.0 has a cropping bug so we'll test for it + if ($this->gd_version() !== FALSE) + { + $gd_version = str_replace('0', '', $this->gd_version()); + $v2_override = ($gd_version == 2) ? TRUE : FALSE; + } + } + else + { + // If the target width/height match the source, AND if + // the new file name is not equal to the old file name + // we'll simply make a copy of the original with the new name + if (($this->orig_width == $this->width AND $this->orig_height == $this->height) AND ($this->source_image != $this->dest_image)) + { + if ( ! @copy($this->full_src_path, $this->full_dst_path)) + { + $this->set_error('imglib_copy_failed'); + return FALSE; + } + + @chmod($this->full_dst_path, 0777); + return TRUE; + } + + // If resizing the x/y axis must be zero + $this->x_axis = 0; + $this->y_axis = 0; + } + + // Create the image handle + if ( ! ($src_img = $this->image_create_gd())) + { + return FALSE; + } + + // Create The Image + if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE) + { + $create = 'imagecreatetruecolor'; + $copy = 'imagecopyresampled'; + } + else + { + $create = 'imagecreate'; + $copy = 'imagecopyresized'; + } + + $dst_img = $create($this->width, $this->height); + $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 + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($dst_img); + } + else + { + // Or save it + if ( ! $this->image_save_gd($dst_img)) + { + return FALSE; + } + } + + // Kill the file handles + imagedestroy($dst_img); + imagedestroy($src_img); + + // Set the file to 777 + @chmod($this->full_dst_path, 0777); + + return TRUE; + } + // END image_process_gd() + + // -------------------------------------------------------------------- + + /** + * Image Process Using ImageMagick + * + * This function will resize, crop or rotate + * + * @access public + * @param string + * @return bool + */ + function image_process_imagemagick($action = 'resize') + { + // Do we have a vaild library path? + if ($this->library_path == '') + { + $this->set_error('imglib_libpath_invalid'); + return FALSE; + } + + if ( ! eregi("convert$", $this->library_path)) + { + if ( ! eregi("/$", $this->library_path)) $this->library_path .= "/"; + + $this->library_path .= 'convert'; + } + + // Execute the command + $cmd = $this->library_path." -quality ".$this->quality; + + if ($action == 'crop') + { + $cmd .= " -crop ".$this->width."x".$this->height."+".$this->x_axis."+".$this->y_axis." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; + } + elseif ($action == 'rotate') + { + switch ($this->rotation_angle) + { + case 'hor' : $angle = '-flop'; + break; + case 'vrt' : $angle = '-flip'; + break; + default : $angle = '-rotate '.$this->rotation_angle; + break; + } + + $cmd .= " ".$angle." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; + } + else // Resize + { + $cmd .= " -resize ".$this->width."x".$this->height." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; + } + + $retval = 1; + + @exec($cmd, $output, $retval); + + // Did it work? + if ($retval > 0) + { + $this->set_error('imglib_image_process_failed'); + return FALSE; + } + + // Set the file to 777 + @chmod($this->full_dst_path, 0777); + + return TRUE; + } + // END image_process_imagemagick() + + // -------------------------------------------------------------------- + + /** + * Image Process Using NetPBM + * + * This function will resize, crop or rotate + * + * @access public + * @param string + * @return bool + */ + function image_process_netpbm($action = 'resize') + { + if ($this->library_path == '') + { + $this->set_error('imglib_libpath_invalid'); + return FALSE; + } + + // Build the resizing command + switch ($this->image_type) + { + case 1 : + $cmd_in = 'giftopnm'; + $cmd_out = 'ppmtogif'; + break; + case 2 : + $cmd_in = 'jpegtopnm'; + $cmd_out = 'ppmtojpeg'; + break; + case 3 : + $cmd_in = 'pngtopnm'; + $cmd_out = 'ppmtopng'; + break; + } + + if ($action == 'crop') + { + $cmd_inner = 'pnmcut -left '.$this->x_axis.' -top '.$this->y_axis.' -width '.$this->width.' -height '.$this->height; + } + elseif ($action == 'rotate') + { + switch ($this->rotation_angle) + { + case 90 : $angle = 'r270'; + break; + case 180 : $angle = 'r180'; + break; + case 270 : $angle = 'r90'; + break; + case 'vrt' : $angle = 'tb'; + break; + case 'hor' : $angle = 'lr'; + break; + } + + $cmd_inner = 'pnmflip -'.$angle.' '; + } + else // Resize + { + $cmd_inner = 'pnmscale -xysize '.$this->width.' '.$this->height; + } + + $cmd = $this->library_path.$cmd_in.' '.$this->full_src_path.' | '.$cmd_inner.' | '.$cmd_out.' > '.$this->dest_folder.'netpbm.tmp'; + + $retval = 1; + + @exec($cmd, $output, $retval); + + // Did it work? + if ($retval > 0) + { + $this->set_error('imglib_image_process_failed'); + return FALSE; + } + + // With NetPBM we have to create a temporary image. + // If you try manipulating the original it fails so + // we have to rename the temp file. + copy ($this->dest_folder.'netpbm.tmp', $this->full_dst_path); + unlink ($this->dest_folder.'netpbm.tmp'); + @chmod($dst_image, 0777); + + return TRUE; + } + // END image_process_netpbm() + + // -------------------------------------------------------------------- + + /** + * Image Rotate Using GD + * + * @access public + * @return bool + */ + function image_rotate_gd() + { + // Is Image Rotation Supported? + // this function is only supported as of PHP 4.3 + if ( ! function_exists('imagerotate')) + { + $this->set_error('imglib_rotate_unsupported'); + return FALSE; + } + + // Create the image handle + if ( ! ($src_img = $this->image_create_gd())) + { + return FALSE; + } + + // Set the background color + // This won't work with transparent PNG files so we are + // going to have to figure out how to determine the color + // of the alpha channel in a future release. + + $white = imagecolorallocate($src_img, 255, 255, 255); + + // Rotate it! + $dst_img = imagerotate($src_img, $this->rotation_angle, $white); + + // Save the Image + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($dst_img); + } + else + { + // Or save it + if ( ! $this->image_save_gd($dst_img)) + { + return FALSE; + } + } + + // Kill the file handles + imagedestroy($dst_img); + imagedestroy($src_img); + + // Set the file to 777 + + @chmod($this->full_dst_path, 0777); + + return true; + } + // END image_rotate_gd() + + // -------------------------------------------------------------------- + + /** + * Create Mirror Image using GD + * + * This function will flip horizontal or vertical + * + * @access public + * @return bool + */ + function image_mirror_gd() + { + if ( ! $src_img = $this->image_create_gd()) + { + return FALSE; + } + + $width = $this->orig_width; + $height = $this->orig_height; + + if ($this->rotation_angle == 'hor') + { + for ($i = 0; $i < $height; $i++) + { + $left = 0; + $right = $width-1; + + while ($left < $right) + { + $cl = imagecolorat($src_img, $left, $i); + $cr = imagecolorat($src_img, $right, $i); + + imagesetpixel($src_img, $left, $i, $cr); + imagesetpixel($src_img, $right, $i, $cl); + + $left++; + $right--; + } + } + } + else + { + for ($i = 0; $i < $width; $i++) + { + $top = 0; + $bot = $height-1; + + while ($top < $bot) + { + $ct = imagecolorat($src_img, $i, $top); + $cb = imagecolorat($src_img, $i, $bot); + + imagesetpixel($src_img, $i, $top, $cb); + imagesetpixel($src_img, $i, $bot, $ct); + + $top++; + $bot--; + } + } + } + + // Show the image + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($src_img); + } + else + { + // Or save it + if ( ! $this->image_save_gd($src_img)) + { + return FALSE; + } + } + + // Kill the file handles + imagedestroy($src_img); + + // Set the file to 777 + @chmod($this->full_dst_path, 0777); + + return TRUE; + } + // END image_mirror_gd() + + // -------------------------------------------------------------------- + + /** + * Image Watermark + * + * This is a wrapper function that chooses the type + * of watermarking based on the specified preference. + * + * @access public + * @param string + * @return bool + */ + function watermark() + { + if ($this->wm_type == 'overlay') + { + return $this->overlay_watermark(); + } + else + { + return $this->text_watermark(); + } + } + // END image_mirror_gd() + + // -------------------------------------------------------------------- + + /** + * Watermark - Graphic Version + * + * @access public + * @return bool + */ + function overlay_watermark() + { + if ( ! function_exists('imagecolortransparent')) + { + $this->set_error('imglib_gd_required'); + return FALSE; + } + + // Fetch source image properties + $this->get_image_properties(); + + // Fetch watermark image properties + $props = $this->get_image_properties($this->wm_overlay_path, TRUE); + $wm_img_type = $props['image_type']; + $wm_width = $props['width']; + $wm_height = $props['height']; + + // Create two image resources + $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type); + $src_img = $this->image_create_gd($this->full_src_path); + + // Reverse the offset if necessary + // When the image is positioned at the bottom + // we don't want the vertical offset to push it + // further down. We want the reverse, so we'll + // invert the offset. Same with the horizontal + // offset when the image is at the right + + $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); + $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); + + if ($this->wm_vrt_alignment == 'B') + $this->wm_vrt_offset = $this->wm_vrt_offset * -1; + + if ($this->wm_hor_alignment == 'R') + $this->wm_hor_offset = $this->wm_hor_offset * -1; + + // Set the base x and y axis values + $x_axis = $this->wm_hor_offset + $this->wm_padding; + $y_axis = $this->wm_vrt_offset + $this->wm_padding; + + // Set the vertical position + switch ($this->wm_vrt_alignment) + { + case 'T': + break; + case 'M': $y_axis += ($this->orig_height / 2) - ($wm_height / 2); + break; + case 'B': $y_axis += $this->orig_height - $wm_height; + break; + } + + // Set the horizontal position + switch ($this->wm_hor_alignment) + { + case 'L': + break; + case 'C': $x_axis += ($this->orig_width / 2) - ($wm_width / 2); + break; + case 'R': $x_axis += $this->orig_width - $wm_width; + break; + } + + // Build the finalized image + if ($wm_img_type == 3 AND function_exists('imagealphablending')) + { + @imagealphablending($src_img, TRUE); + } + + // Set RGB values for text and shadow + imagecolortransparent($wm_img, imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp)); + imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity); + + // Output the image + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($src_img); + } + else + { + if ( ! $this->image_save_gd($src_img)) + { + return FALSE; + } + } + + imagedestroy($src_img); + imagedestroy($wm_img); + + return TRUE; + } + // END overlay_watermark() + + // -------------------------------------------------------------------- + + /** + * Watermark - Text Version + * + * @access public + * @return bool + */ + function text_watermark() + { + if ( ! ($src_img = $this->image_create_gd())) + { + return FALSE; + } + + if ($this->wm_use_truetype == TRUE AND ! file_exists($this->wm_font_path)) + { + $this->set_error('imglib_missing_font'); + return FALSE; + } + + // Fetch source image properties + $this->get_image_properties(); + + // Set RGB values for text and shadow + $this->wm_font_color = str_replace('#', '', $this->wm_font_color); + $this->wm_shadow_color = str_replace('#', '', $this->wm_shadow_color); + + $R1 = hexdec(substr($this->wm_font_color, 0, 2)); + $G1 = hexdec(substr($this->wm_font_color, 2, 2)); + $B1 = hexdec(substr($this->wm_font_color, 4, 2)); + + $R2 = hexdec(substr($this->wm_shadow_color, 0, 2)); + $G2 = hexdec(substr($this->wm_shadow_color, 2, 2)); + $B2 = hexdec(substr($this->wm_shadow_color, 4, 2)); + + $txt_color = imagecolorclosest($src_img, $R1, $G1, $B1); + $drp_color = imagecolorclosest($src_img, $R2, $G2, $B2); + + // Reverse the vertical offset + // When the image is positioned at the bottom + // we don't want the vertical offset to push it + // further down. We want the reverse, so we'll + // invert the offset. Note: The horizontal + // offset flips itself automatically + + if ($this->wm_vrt_alignment == 'B') + $this->wm_vrt_offset = $this->wm_vrt_offset * -1; + + if ($this->wm_hor_alignment == 'R') + $this->wm_hor_offset = $this->wm_hor_offset * -1; + + // Set font width and height + // These are calculated differently depending on + // whether we are using the true type font or not + if ($this->wm_use_truetype == TRUE) + { + if ($this->wm_font_size == '') + $this->wm_font_size = '17'; + + $fontwidth = $this->wm_font_size-($this->wm_font_size/4); + $fontheight = $this->wm_font_size; + $this->wm_vrt_offset += $this->wm_font_size; + } + else + { + $fontwidth = imagefontwidth($this->wm_font_size); + $fontheight = imagefontheight($this->wm_font_size); + } + + // Set base X and Y axis values + $x_axis = $this->wm_hor_offset + $this->wm_padding; + $y_axis = $this->wm_vrt_offset + $this->wm_padding; + + // Set verticle alignment + if ($this->wm_use_drop_shadow == FALSE) + $this->wm_shadow_distance = 0; + + $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); + $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); + + switch ($this->wm_vrt_alignment) + { + case "T" : + break; + case "M": $y_axis += ($this->orig_height/2)+($fontheight/2); + break; + case "B": $y_axis += ($this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight/2)); + break; + } + + $x_shad = $x_axis + $this->wm_shadow_distance; + $y_shad = $y_axis + $this->wm_shadow_distance; + + // Set horizontal alignment + switch ($this->wm_hor_alignment) + { + case "L": + break; + case "R": + if ($this->wm_use_drop_shadow) + $x_shad += ($this->orig_width - $fontwidth*strlen($this->wm_text)); + $x_axis += ($this->orig_width - $fontwidth*strlen($this->wm_text)); + break; + case "C": + if ($this->wm_use_drop_shadow) + $x_shad += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2); + $x_axis += floor(($this->orig_width -$fontwidth*strlen($this->wm_text))/2); + break; + } + + // Add the text to the source image + if ($this->wm_use_truetype) + { + if ($this->wm_use_drop_shadow) + imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text); + imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text); + } + else + { + if ($this->wm_use_drop_shadow) + imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color); + imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); + } + + // Output the final image + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($src_img); + } + else + { + $this->image_save_gd($src_img); + } + + imagedestroy($src_img); + + return TRUE; + } + // END text_watermark() + + // -------------------------------------------------------------------- + + /** + * Create Image - GD + * + * This simply creates an image resource handle + * based on the type of image being processed + * + * @access public + * @param string + * @return resource + */ + function image_create_gd($path = '', $image_type = '') + { + if ($path == '') + $path = $this->full_src_path; + + if ($image_type == '') + $image_type = $this->image_type; + + + switch ($image_type) + { + case 1 : + if ( ! function_exists('imagecreatefromgif')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); + return FALSE; + } + + return imagecreatefromgif($path); + break; + case 2 : + if ( ! function_exists('imagecreatefromjpeg')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); + return FALSE; + } + + return imagecreatefromjpeg($path); + break; + case 3 : + if ( ! function_exists('imagecreatefrompng')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); + return FALSE; + } + + return imagecreatefrompng($path); + break; + + } + + $this->set_error(array('imglib_unsupported_imagecreate')); + return FALSE; + } + // END image_create_gd() + + // -------------------------------------------------------------------- + + /** + * Write imge file to disk - GD + * + * Takes an image resource as input and writes the file + * to the specified destination + * + * @access public + * @param resource + * @return bool + */ + function image_save_gd($resource) + { + switch ($this->image_type) + { + case 1 : + if ( ! function_exists('imagegif')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); + return FALSE; + } + + @imagegif($resource, $this->full_dst_path); + break; + case 2 : + if ( ! function_exists('imagejpeg')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); + return FALSE; + } + + if (phpversion() == '4.4.1') + { + @touch($this->full_dst_path); // PHP 4.4.1 bug #35060 - workaround + } + + @imagejpeg($resource, $this->full_dst_path, $this->quality); + break; + case 3 : + if ( ! function_exists('imagepng')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); + return FALSE; + } + + @imagepng($resource, $this->full_dst_path); + break; + default : + $this->set_error(array('imglib_unsupported_imagecreate')); + return FALSE; + break; + } + + return TRUE; + } + // END image_save_gd() + + // -------------------------------------------------------------------- + + /** + * Dynamically ouputs an image + * + * @access public + * @param resource + * @return void + */ + function image_display_gd($resource) + { + header("Content-Disposition: filename={$this->source_image};"); + header("Content-Type: {$this->mime_type}"); + header('Content-Transfer-Encoding: binary'); + header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT'); + + switch ($this->image_type) + { + case 1 : imagegif($resource); + break; + case 2 : imagejpeg($resource, '', $this->quality); + break; + case 3 : imagepng($resource); + break; + default : echo 'Unable to display the image'; + break; + } + } + // END image_display_gd() + + // -------------------------------------------------------------------- + + /** + * Reproportion Image Width/Height + * + * When creating thumbs, the desired width/height + * can end up warping the image due to an incorrect + * ratio between the full-sized image and the thumb. + * + * This function lets us reproportion the width/height + * if users choose to maintain the aspect ratio when resizing. + * + * @access public + * @return void + */ + function image_reproportion() + { + if ( ! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0) + return; + + if ( ! is_numeric($this->orig_width) OR ! is_numeric($this->orig_height) OR $this->orig_width == 0 OR $this->orig_height == 0) + return; + + $new_width = ceil($this->orig_width*$this->height/$this->orig_height); + $new_height = ceil($this->width*$this->orig_height/$this->orig_width); + + $ratio = (($this->orig_height/$this->orig_width) - ($this->height/$this->width)); + + if ($this->master_dim != 'width' AND $this->master_dim != 'height') + { + $this->master_dim = ($ratio < 0) ? 'width' : 'height'; + } + + if (($this->width != $new_width) AND ($this->height != $new_height)) + { + if ($this->master_dim == 'height') + { + $this->width = $new_width; + } + else + { + $this->height = $new_height; + } + } + } + // END image_reproportion() + + // -------------------------------------------------------------------- + + /** + * Get image properties + * + * A helper function that gets info about the file + * + * @access public + * @param string + * @return mixed + */ + function get_image_properties($path = '', $return = FALSE) + { + // For now we require GD but we should + // find a way to determine this using IM or NetPBM + + if ($path == '') + $path = $this->full_src_path; + + if ( ! file_exists($path)) + { + $this->set_error('imglib_invalid_path'); + return FALSE; + } + + $vals = @getimagesize($path); + + $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); + + $mime = (isset($types[$vals['2']])) ? 'image/'.$types[$vals['2']] : 'image/jpg'; + + if ($return == TRUE) + { + $v['width'] = $vals['0']; + $v['height'] = $vals['1']; + $v['image_type'] = $vals['2']; + $v['size_str'] = $vals['3']; + $v['mime_type'] = $mime; + + return $v; + } + + $this->orig_width = $vals['0']; + $this->orig_height = $vals['1']; + $this->image_type = $vals['2']; + $this->size_str = $vals['3']; + $this->mime_type = $mime; + + return TRUE; + } + // END get_image_properties() + + // -------------------------------------------------------------------- + + /** + * Size calculator + * + * This function takes a known width x height and + * recalculates it to a new size. Only one + * new variable needs to be known + * + * $props = array( + * 'width' => $width, + * 'height' => $height, + * 'new_width' => 40, + * 'new_height' => '' + * ); + * + * @access public + * @param array + * @return array + */ + function size_calculator($vals) + { + if ( ! is_array($vals)) + return; + + $allowed = array('new_width', 'new_height', 'width', 'height'); + + foreach ($allowed as $item) + { + if ( ! isset($vals[$item]) OR $vals[$item] == '') + $vals[$item] = 0; + } + + if ($vals['width'] == 0 OR $vals['height'] == 0) + { + return $vals; + } + + if ($vals['new_width'] == 0) + { + $vals['new_width'] = ceil($vals['width']*$vals['new_height']/$vals['height']); + } + elseif ($vals['new_height'] == 0) + { + $vals['new_height'] = ceil($vals['new_width']*$vals['height']/$vals['width']); + } + + return $vals; + } + // END size_calculator() + + // -------------------------------------------------------------------- + + /** + * Explode source_image + * + * This is a helper function that extracts the extension + * from the source_image. This function lets us deal with + * source_images with multiple periods, like: my.cool.jpg + * It returns an associative array with two elements: + * $array['ext'] = '.jpg'; + * $array['name'] = 'my.cool'; + * + * @access public + * @param array + * @return array + */ + function explode_name($source_image) + { + $x = explode('.', $source_image); + $ret['ext'] = '.'.end($x); + + $name = ''; + + $ct = count($x)-1; + + for ($i = 0; $i < $ct; $i++) + { + $name .= $x[$i]; + + if ($i < ($ct - 1)) + { + $name .= '.'; + } + } + + $ret['name'] = $name; + + return $ret; + } + // END explode_name() + + // -------------------------------------------------------------------- + + /** + * Is GD Installed? + * + * @access public + * @return bool + */ + function gd_loaded() + { + if ( ! extension_loaded('gd')) + { + if ( ! dl('gd.so')) + { + return FALSE; + } + } + + return TRUE; + } + // END gd_loaded() + + // -------------------------------------------------------------------- + + /** + * Get GD version + * + * @access public + * @return mixed + */ + function gd_version() + { + if (function_exists('gd_info')) + { + $gd_version = @gd_info(); + $gd_version = preg_replace("/\D/", "", $gd_version['GD Version']); + + return $gd_version; + } + + return FALSE; + } + // END gd_version() + + // -------------------------------------------------------------------- + + /** + * Set error message + * + * @access public + * @param string + * @return void + */ + function set_error($msg) + { + $obj =& get_instance(); + $obj->lang->load('imglib'); + + if (is_array($msg)) + { + foreach ($msg as $val) + { + + $msg = ($obj->lang->line($val) == FALSE) ? $val : $obj->lang->line($val); + $this->error_msg[] = $msg; + log_message('error', $msg); + } + } + else + { + $msg = ($obj->lang->line($msg) == FALSE) ? $msg : $obj->lang->line($msg); + $this->error_msg[] = $msg; + log_message('error', $msg); + } + } + // END set_error() + + // -------------------------------------------------------------------- + + /** + * Show error messages + * + * @access public + * @param string + * @return string + */ + function display_errors($open = '

', $close = '

') + { + $str = ''; + foreach ($this->error_msg as $val) + { + $str .= $open.$val.$close; + } + + return $str; + } + // END display_errors() +} +// END Image_lib Class +?> \ No newline at end of file diff --git a/system/libraries/Input.php b/system/libraries/Input.php new file mode 100644 index 000000000..6aba5dd43 --- /dev/null +++ b/system/libraries/Input.php @@ -0,0 +1,585 @@ +use_xss_clean = ($CFG->item('global_xss_filtering') === TRUE) ? TRUE : FALSE; + $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; + + log_message('debug', "Input Class Initialized"); + $this->_sanitize_globals(); + } + // END CI_Input() + + // -------------------------------------------------------------------- + + /** + * Sanitize Globals + * + * This function does the folowing: + * + * Unsets $_GET data (if query strings are not enabled) + * + * Unsets all globals if register_globals is enabled + * + * Standardizes newline characters to \n + * + * @access private + * @return void + */ + function _sanitize_globals() + { + // Unset globals. This is effectively the same as register_globals = off + foreach (array($_GET, $_POST, $_COOKIE) as $global) + { + if ( ! is_array($global)) + { + unset($$global); + } + else + { + foreach ($global as $key => $val) + { + unset($$key); + } + } + } + + // Is $_GET data allowed? + if ($this->allow_get_array == FALSE) + { + $_GET = array(); + } + + // Clean $_POST Data + if (is_array($_POST) AND count($_POST) > 0) + { + foreach($_POST as $key => $val) + { + if (is_array($val)) + { + foreach($val as $k => $v) + { + $_POST[$this->_clean_input_keys($key)][$this->_clean_input_keys($k)] = $this->_clean_input_data($v); + } + } + else + { + $_POST[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); + } + } + } + + // Clean $_COOKIE Data + if (is_array($_COOKIE) AND count($_COOKIE) > 0) + { + foreach($_COOKIE as $key => $val) + { + $_COOKIE[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); + } + } + + log_message('debug', "Global POST and COOKIE data sanitized"); + } + // END _sanitize_globals() + + // -------------------------------------------------------------------- + + /** + * Clean Intput Data + * + * This is a helper function. It escapes data and + * standardizes newline characters to \n + * + * @access private + * @param string + * @return string + */ + function _clean_input_data($str) + { + if (is_array($str)) + { + $new_array = array(); + foreach ($str as $key => $val) + { + $new_array[$key] = $this->_clean_input_data($val); + } + return $new_array; + } + + if ($this->use_xss_clean === TRUE) + { + $str = $this->xss_clean($str); + } + + return preg_replace("/\015\012|\015|\012/", "\n", $str); + } + // END _clean_input_data() + + // -------------------------------------------------------------------- + + /** + * Clean Keys + * + * This is a helper function. To prevent malicious users + * from trying to exploit keys we make sure that keys are + * only named with alpha-numeric text and a few other items. + * + * @access private + * @param string + * @return string + */ + function _clean_input_keys($str) + { + if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str)) + { + exit('Disallowed Key Characters: '.$str); + } + + if ( ! get_magic_quotes_gpc()) + { + return addslashes($str); + } + + return $str; + } + // END _clean_input_keys() + + // -------------------------------------------------------------------- + + /** + * Fetch an item from the POST array + * + * @access public + * @param string + * @return string + */ + function post($index = '', $xss_clean = FALSE) + { + if ( ! isset($_POST[$index])) + { + return FALSE; + } + else + { + if ($xss_clean === TRUE) + { + return $this->xss_clean($_POST[$index]); + } + else + { + return $_POST[$index]; + } + } + } + // END post() + + // -------------------------------------------------------------------- + + /** + * Fetch an item from the COOKIE array + * + * @access public + * @param string + * @return string + */ + function cookie($index = '', $xss_clean = FALSE) + { + if ( ! isset($_COOKIE[$index])) + { + return FALSE; + } + else + { + if ($xss_clean === TRUE) + { + return $this->xss_clean($_COOKIE[$index]); + } + else + { + return $_COOKIE[$index]; + } + } + } + // END cookie() + + // -------------------------------------------------------------------- + + /** + * Fetch the IP Address + * + * @access public + * @return string + */ + function ip_address() + { + if ($this->ip_address !== FALSE) + { + return $this->ip_address; + } + + $cip = (isset($_SERVER['HTTP_CLIENT_IP']) AND $_SERVER['HTTP_CLIENT_IP'] != "") ? $_SERVER['HTTP_CLIENT_IP'] : FALSE; + $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_address = $cip; + elseif ($rip) $this->ip_address = $rip; + elseif ($cip) $this->ip_address = $cip; + elseif ($fip) $this->ip_address = $fip; + + if (strstr($this->ip_address, ',')) + { + $x = explode(',', $this->ip_address); + $this->ip_address = end($x); + } + + if ( ! $this->valid_ip($this->ip_address)) + { + $this->ip_address = '0.0.0.0'; + } + + unset($cip); + unset($rip); + unset($fip); + + return $this->ip_address; + } + // END ip_address() + + // -------------------------------------------------------------------- + + /** + * Validate IP Address + * + * @access public + * @param string + * @return string + */ + function valid_ip($ip) + { + return ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) ? FALSE : TRUE; + } + // END valid_ip() + + // -------------------------------------------------------------------- + + /** + * User Agent + * + * @access public + * @return string + */ + function user_agent() + { + if ($this->user_agent !== FALSE) + { + return $this->user_agent; + } + + $this->user_agent = ( ! isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT']; + + return $this->user_agent; + } + // END user_agent() + + // -------------------------------------------------------------------- + + /** + * XSS Clean + * + * Sanitizes data so that Cross Site Scripting Hacks can be + * prevented.Ê This function does a fair amount of work but + * it is extremely thorough, designed to prevent even the + * most obscure XSS attempts.Ê Nothing is ever 100% foolproof, + * of course, but I haven't been able to get anything passed + * the filter. + * + * Note: This function should only be used to deal with data + * upon submission.Ê It's not something that should + * be used for general runtime processing. + * + * This function was based in part on some code and ideas I + * got from Bitflux: http://blog.bitflux.ch/wiki/XSS_Prevention + * + * To help develop this script I used this great list of + * vulnerabilities along with a few other hacks I've + * harvested from examining vulnerabilities in other programs: + * http://ha.ckers.org/xss.html + * + * @access public + * @param string + * @return string + */ + function xss_clean($str, $charset = 'ISO-8859-1') + { + /* + * Remove Null Characters + * + * This prevents sandwiching null characters + * between ascii characters, like Java\0script. + * + */ + $str = preg_replace('/\0+/', '', $str); + $str = preg_replace('/(\\\\0)+/', '', $str); + + /* + * Validate standard character entites + * + * Add a semicolon if missing. We do this to enable + * the conversion of entities to ASCII later. + * + */ + $str = preg_replace('#(&\#*\w+)[\x00-\x20]+;#u',"\\1;",$str); + + /* + * Validate UTF16 two byte encodeing (x00) + * + * Just as above, adds a semicolon if missing. + * + */ + $str = preg_replace('#(&\#x*)([0-9A-F]+);*#iu',"\\1\\2;",$str); + + /* + * URL Decode + * + * Just in case stuff like this is submitted: + * + * Google + * + * Note: Normally urldecode() would be easier but it removes plus signs + * + */ + $str = preg_replace("/%u0([a-z0-9]{3})/i", "&#x\\1;", $str); + $str = preg_replace("/%([a-z0-9]{2})/i", "&#x\\1;", $str); + + /* + * Convert character entities to ASCII + * + * This permits our tests below to work reliably. + * We only convert entities that are within tags since + * these are the ones that will pose security problems. + * + */ + + if (preg_match_all("/<(.+?)>/si", $str, $matches)) + { + for ($i = 0; $i < count($matches['0']); $i++) + { + $str = str_replace($matches['1'][$i], + $this->_html_entity_decode($matches['1'][$i], $charset), + $str); + } + } + + /* + * Convert all tabs to spaces + * + * This prevents strings like this: ja vascript + * Note: we deal with spaces between characters later. + * + */ + $str = preg_replace("#\t+#", " ", $str); + + /* + * Makes PHP tags safe + * + * Note: XML tags are inadvertently replaced too: + * + * '), array('<?php', '<?PHP', '<?', '?>'), $str); // .*?#si", "", $str); + $str = preg_replace("##si", "", $str); + $str = preg_replace("#<(script|xss).*?\>#si", "", $str); + + /* + * Remove JavaScript Event Handlers + * + * Note: This code is a little blunt. It removes + * the event handler and anything up to the closing >, + * but it's unlkely to be a problem. + * + */ + $str = preg_replace('#(<[^>]+.*?)(onblur|onchange|onclick|onfocus|onload|onmouseover|onmouseup|onmousedown|onselect|onsubmit|onunload|onkeypress|onkeydown|onkeyup|onresize)[^>]*>#iU',"\\1>",$str); + + /* + * Sanitize naughty HTML elements + * + * If a tag containing any of the words in the list + * below is found, the tag gets converted to entities. + * + * So this: + * Becomes: <blink> + * + */ + $str = preg_replace('#<(/*\s*)(alert|applet|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|layer|link|meta|object|plaintext|style|script|textarea|title|xml|xss)([^>]*)>#is', "<\\1\\2\\3>", $str); + + /* + * Sanitize naughty scripting elements + * + * Similar to above, only instead of looking for + * tags it looks for PHP and JavaScript commands + * that are disallowed. Rather than removing the + * code, it simply converts the parenthesis to entities + * rendering the code unexecutable. + * + * For example: eval('some code') + * Becomes: eval('some code') + * + */ + $str = preg_replace('#(alert|cmd|passthru|eval|exec|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)\((.*?)\)#si', "\\1\\2(\\3)", $str); + + /* + * Final clean up + * + * This adds a bit of extra precaution in case + * something got through the above filters + * + */ + $bad = array( + 'document.cookie' => '', + 'document.write' => '', + 'window.location' => '', + "javascript\s*:" => '', + "Redirect\s+302" => '', + '' => '-->' + ); + + foreach ($bad as $key => $val) + { + $str = preg_replace("#".$key."#i", $val, $str); + } + + + log_message('debug', "XSS Filtering completed"); + return $str; + } + // END xss_clean() + + + /** + * HTML Entities Decode + * + * This function is a replacement for html_entity_decode() + * + * In some versions of PHP the native function does not work + * when UTF-8 is the specified character set, so this gives us + * a work-around. More info here: + * http://bugs.php.net/bug.php?id=25670 + * + * @access private + * @param string + * @param string + * @return string + */ + /* ------------------------------------------------- + /* Replacement for html_entity_decode() + /* -------------------------------------------------*/ + + /* + NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the + character set, and the PHP developers said they were not back porting the + fix to versions other than PHP 5.x. + */ + function _html_entity_decode($str, $charset='ISO-8859-1') + { + 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 version_compare(phpversion(), '5.0.0', '>='))) + { + $str = html_entity_decode($str, ENT_COMPAT, $charset); + $str = preg_replace('~&#x([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-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; + } + +} +// END Input class +?> \ No newline at end of file diff --git a/system/libraries/Language.php b/system/libraries/Language.php new file mode 100644 index 000000000..b668aa060 --- /dev/null +++ b/system/libraries/Language.php @@ -0,0 +1,113 @@ +is_loaded)) + { + return; + } + + if ($idiom == '') + { + $obj =& get_instance(); + $deft_lang = $obj->config->item('language'); + $idiom = ($deft_lang == '') ? 'english' : $deft_lang; + } + + if ( ! file_exists(BASEPATH.'language/'.$idiom.'/'.$langfile)) + { + show_error('Unable to load the requested language file: language/'.$langfile.EXT); + } + + include_once(BASEPATH.'language/'.$idiom.'/'.$langfile); + + if ( ! isset($lang)) + { + log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile); + return; + } + + if ($return == TRUE) + { + return $lang; + } + + $this->is_loaded[] = $langfile; + $this->language = array_merge($this->language, $lang); + unset($lang); + + log_message('debug', 'Language file loaded: language/'.$idiom.'/'.$langfile); + return TRUE; + } + // END load() + + // -------------------------------------------------------------------- + + /** + * Fetch a single line of text from the language array + * + * @access public + * @param string the language line + * @return string + */ + function line($line = '') + { + return ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line]; + } + // END line() + +} +// END Language Class +?> \ No newline at end of file diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php new file mode 100644 index 000000000..e2467fa64 --- /dev/null +++ b/system/libraries/Loader.php @@ -0,0 +1,611 @@ +view_path = APPPATH.'views/'; + $this->ob_level = ob_get_level(); + + log_message('debug', "Loader Class Initialized"); + } + // END CI_Loader() + + // -------------------------------------------------------------------- + + /** + * Class Loader + * + * This function lets users load and instantiate classes. + * It is designed to be called from a user's app controllers. + * + * @access public + * @param string the name of the class + * @param mixed any initialization parameters + * @return void + */ + function library($class, $param = FALSE) + { + if ($class == '') + return; + + $obj =& get_instance(); + $obj->_ci_initialize($class, $param); + $obj->_ci_assign_to_models(); + } + // END library() + + // -------------------------------------------------------------------- + + /** + * Model Loader + * + * This function lets users load and instantiate models. + * + * @access public + * @param string the name of the class + * @param mixed any initialization parameters + * @return void + */ + function model($model, $name = '', $db_conn = FALSE) + { + if ($model == '') + return; + + $obj =& get_instance(); + $obj->_ci_load_model($model, $name, $db_conn); + } + // END library() + + // -------------------------------------------------------------------- + + /** + * Database Loader + * + * @access public + * @param string the DB credentials + * @param bool whether to return the DB object + * @param bool whether to enable active record (this allows us to override the config setting) + * @return mixed + */ + function database($db = '', $return = FALSE, $active_record = FALSE) + { + $obj =& get_instance(); + + if ($return === TRUE) + { + return $obj->_ci_init_database($db, TRUE, $active_record); + } + else + { + $obj->_ci_init_database($db, FALSE, $active_record); + $obj->_ci_assign_to_models(); + } + } + // END database() + + // -------------------------------------------------------------------- + + /** + * Scaffolding Loader + * + * @access public + * @param string + * @return void + */ + function scaffolding($table = '') + { + if ($table == FALSE) + { + show_error('You must include the name of the table you would like access when you initialize scaffolding'); + } + + $obj =& get_instance(); + $obj->_ci_init_scaffolding($table); + } + // END scaffolding() + + // -------------------------------------------------------------------- + + /** + * Load View + * + * This function is used to load a "view" file. It has three parameters: + * + * 1. The name of the "view" file to be included. + * 2. An associative array of data to be extracted for use in the view. + * 3. TRUE/FALSE - whether to return the data or load it. In + * some cases it's advantageous to be able to retun data so that + * a developer can process it in some way. + * + * @access public + * @param string + * @param array + * @param bool + * @return void + */ + function view($view, $vars = array(), $return = FALSE) + { + return $this->_ci_load(array('view' => $view, 'vars' => $this->_ci_object_to_array($vars), 'return' => $return)); + } + // END view() + + // -------------------------------------------------------------------- + + /** + * Load File + * + * This is a generic file loader + * + * @access public + * @param string + * @param bool + * @return string + */ + function file($path, $return = FALSE) + { + return $this->_ci_load(array('path' => $path, 'return' => $return)); + } + // END file() + + // -------------------------------------------------------------------- + + /** + * Set Variables + * + * Once variables are set they become availabe within + * the controller class and its "view" files. + * + * @access public + * @param array + * @return void + */ + function vars($vars = array()) + { + $vars = $this->_ci_object_to_array($vars); + + if (is_array($vars) AND count($vars) > 0) + { + foreach ($vars as $key => $val) + { + $this->cached_vars[$key] = $val; + } + } + } + // END vars() + + // -------------------------------------------------------------------- + + /** + * Load Helper + * + * This function loads the specified helper file. + * + * @access public + * @param mixed + * @return void + */ + function helper($helpers = array()) + { + if ( ! is_array($helpers)) + { + $helpers = array($helpers); + } + + foreach ($helpers as $helper) + { + if (isset($this->helpers[$helper])) + { + continue; + } + + $helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper'); + + if ( ! file_exists(BASEPATH.'helpers/'.$helper.EXT)) + { + show_error('Unable to load the requested file: helpers/'.$helper.EXT); + } + + include_once(BASEPATH.'helpers/'.$helper.EXT); + + $this->helpers[$helper] = TRUE; + } + + log_message('debug', 'Helpers loaded: '.implode(', ', $helpers)); + } + // END helper() + + // -------------------------------------------------------------------- + + /** + * Load Helpers + * + * This is simply an alias to the above function in case the + * user has written the plural form of this function. + * + * @access public + * @param array + * @return void + */ + function helpers($helpers = array()) + { + $this->helper($helpers); + } + // END helpers() + + // -------------------------------------------------------------------- + + /** + * Load Plugin + * + * This function loads the specified plugin. + * + * @access public + * @param array + * @return void + */ + function plugin($plugins = array()) + { + if ( ! is_array($plugins)) + { + $plugins = array($plugins); + } + + foreach ($plugins as $plugin) + { + if (isset($this->plugins[$plugin])) + { + continue; + } + + $plugin = strtolower(str_replace(EXT, '', str_replace('_plugin.', '', $plugin)).'_pi'); + + if ( ! file_exists(BASEPATH.'plugins/'.$plugin.EXT)) + { + show_error('Unable to load the requested file: plugins/'.$plugin.EXT); + } + + include_once(BASEPATH.'plugins/'.$plugin.EXT); + + $this->plugins[$plugin] = TRUE; + } + + log_message('debug', 'Plugins loaded: '.implode(', ', $plugins)); + } + // END plugin() + + // -------------------------------------------------------------------- + + /** + * Load Script + * + * This function loads the specified include file from the + * application/scripts/ folder + * + * @access public + * @param array + * @return void + */ + function script($scripts = array()) + { + if ( ! is_array($scripts)) + { + $scripts = array($scripts); + } + + foreach ($scripts as $script) + { + if (isset($this->scripts[$script])) + { + continue; + } + + $script = strtolower(str_replace(EXT, '', $script)); + + if ( ! file_exists(APPPATH.'scripts/'.$script.EXT)) + { + show_error('Unable to load the requested script: scripts/'.$script.EXT); + } + + include_once(APPPATH.'scripts/'.$script.EXT); + + $this->scripts[$script] = TRUE; + } + + log_message('debug', 'Scripts loaded: '.implode(', ', $scripts)); + } + // END script() + + // -------------------------------------------------------------------- + + /** + * Load Plugins + * + * This is simply an alias to the above function in case the + * user has written the plural form of this function. + * + * @access public + * @param array + * @return void + */ + function plugins($plugins = array()) + { + $this->plugin($plugins); + } + // END plugins() + + // -------------------------------------------------------------------- + + /** + * Loads a language file + * + * @access public + * @param string + * @return void + */ + function language($file = '', $lang = '', $return = FALSE) + { + $obj =& get_instance(); + return $obj->lang->load($file, $lang, $return); + } + // END language() + + // -------------------------------------------------------------------- + + /** + * Loads a config file + * + * @access public + * @param string + * @return void + */ + function config($file = '') + { + $obj =& get_instance(); + $obj->config->load($file); + } + // END config() + + // -------------------------------------------------------------------- + + /** + * Set the Path to the "views" folder + * + * @access private + * @param string + * @return void + */ + function _ci_set_view_path($path) + { + $this->view_path = $path; + } + // END _ci_set_view_path() + + // -------------------------------------------------------------------- + + /** + * Loader + * + * This function isn't called directly. It's called from + * the two functions above. It's used to load views and files + * + * @access private + * @param array + * @return void + */ + function _ci_load($data) + { + $OUT =& _load_class('CI_Output'); + + // This allows anything loaded using $this->load (viwes, files, etc.) + // to become accessible from within the Controller and Model functions. + $obj =& get_instance(); + foreach ($obj->ci_is_loaded as $val) + { + if ( ! isset($this->$val)) + { + $this->$val =& $obj->$val; + } + } + + // Set the default data variables + foreach (array('view', 'vars', 'path', 'return') as $val) + { + $$val = ( ! isset($data[$val])) ? FALSE : $data[$val]; + } + + /* + * Extract and cached variables + * + * You can either set variables using the dedicated + * $this->load_vars() 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($vars)) + { + $this->cached_vars = array_merge($this->cached_vars, $vars); + } + extract($this->cached_vars); + + // Set the path to the requested file + if ($path == '') + { + $ext = pathinfo($view, PATHINFO_EXTENSION); + $file = ($ext == '') ? $view.EXT : $view; + $path = $this->view_path.$file; + } + else + { + $x = explode('/', $path); + $file = end($x); + } + + /* + * Buffer the output + * + * We buffer the output for two reasons: + * 1. Speed. You get a significant speed boost. + * 2. So that the final rendered template can be + * post-processed by the output class. Why do we + * need post processing? For one thing, in order to + * show the elapsed page load time. Unless we + * can intercept the content right before it's sent to + * the browser and then stop the timer, it won't be acurate. + * + */ + + if ( ! file_exists($path)) + { + show_error('Unable to load the requested file: '.$file); + } + + ob_start(); + + include($path); + log_message('debug', 'File loaded: '.$path); + + // Return the file data if requested to + if ($return === TRUE) + { + $buffer = ob_get_contents(); + ob_end_clean(); + + return $buffer; + } + + /* + * Flush the buffer... or buff the flusher? + * + * In order to permit templates (views) to be nested within + * other views, we need to flush the content back out whenever + * we are beyond the first level of output buffering so that + * it can be seen and included properly by the first included + * template and any subsequent ones. Oy! + * + */ + if (ob_get_level() > $this->ob_level + 1) + { + ob_end_flush(); + } + else + { + $OUT->set_output(ob_get_contents()); + ob_end_clean(); + } + } + // END _load() + + // -------------------------------------------------------------------- + + /** + * Autoloader + * + * The config/autoload.php file contains an array that permits sub-systems, + * plugins, and helpers to be loaded automatically. + * + * @access private + * @param array + * @return void + */ + function _ci_autoloader($autoload) + { + if ($autoload === FALSE) + { + return; + } + + foreach (array('helper', 'plugin', 'script') as $type) + { + if (isset($autoload[$type])) + { + if ( ! is_array($autoload[$type])) + { + $autoload[$type] = array($autoload[$type]); + } + + foreach ($autoload[$type] as $item) + { + $this->$type($item); + } + } + } + } + // END _ci_autoloader() + + // -------------------------------------------------------------------- + + /** + * Object to Array + * + * Takes an object as input and convers the class variables to array key/vals + * + * @access public + * @param object + * @return array + */ + function _ci_object_to_array($object) + { + if ( ! is_object($object)) + { + return $object; + } + + $array = array(); + foreach (get_object_vars($object) as $key => $val) + { + $array[$key] = $val; + } + + return $array; + } + +} +// END Loader Class +?> \ No newline at end of file diff --git a/system/libraries/Log.php b/system/libraries/Log.php new file mode 100644 index 000000000..35e30b64c --- /dev/null +++ b/system/libraries/Log.php @@ -0,0 +1,117 @@ + '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4'); + + /** + * Constructor + * + * @access public + * @param string the log file path + * @param string the error threshold + * @param string the date formatting codes + */ + function CI_Log($path = '', $threshold = '', $date_fmt = '') + { + $this->log_path = ($path != '') ? $path : BASEPATH.'logs/'; + + if ( ! is_dir($this->log_path) OR ! is_writable($this->log_path)) + { + $this->_enabled = FALSE; + } + + if (ctype_digit($threshold)) + { + $this->_threshold = $threshold; + } + + if ($date_fmt != '') + { + $this->_date_fmt = $date_fmt; + } + } + // END CI_Log() + + // -------------------------------------------------------------------- + + /** + * Write Log File + * + * Generally this function will be called using the global log_message() function + * + * @access public + * @param string the error level + * @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').'.php'; + $message = ''; + + if ( ! file_exists($filepath)) + { + $message .= "<"."?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; + } + + if ( ! $fp = @fopen($filepath, "a")) + { + return FALSE; + } + + $message .= $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --> '.$msg."\n"; + + flock($fp, LOCK_EX); + fwrite($fp, $message); + flock($fp, LOCK_UN); + fclose($fp); + + @chmod($filepath, 0666); + return TRUE; + } + // END write_log() +} +// END Log Class +?> \ No newline at end of file diff --git a/system/libraries/Model.php b/system/libraries/Model.php new file mode 100644 index 000000000..9834f8278 --- /dev/null +++ b/system/libraries/Model.php @@ -0,0 +1,72 @@ +_assign_libraries(FALSE); + log_message('debug', "Model Class Initialized"); + } + // END Model() + + /** + * Assign Libraries + * + * 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. + * + * @access private + */ + function _assign_libraries($use_reference = TRUE) + { + $obj =& get_instance(); + foreach ($obj->ci_is_loaded as $val) + { + if ( ! isset($this->$val)) + { + if ($use_reference === TRUE) + { + $this->$val =& $obj->$val; + } + else + { + $this->$val = $obj->$val; + } + } + } + } + // END _assign_libraries() + +} +// END Model Class +?> \ No newline at end of file diff --git a/system/libraries/Output.php b/system/libraries/Output.php new file mode 100644 index 000000000..f5db3e0d0 --- /dev/null +++ b/system/libraries/Output.php @@ -0,0 +1,241 @@ +final_output; + } + + // -------------------------------------------------------------------- + + /** + * Set Output + * + * Sets the output string + * + * @access public + * @param string + * @return void + */ + function set_output($output) + { + $this->final_output = $output; + } + + // -------------------------------------------------------------------- + + /** + * Set Cache + * + * @access public + * @param integer + * @return void + */ + function cache($time) + { + $this->cache_expiration = ( ! ctype_digit($time)) ? 0 : $time; + } + + // -------------------------------------------------------------------- + + /** + * Display Output + * + * All "view" data is automatically put into this variable + * by the controller class: + * + * $this->final_output + * + * This function simply echos the variable out. It also does the following: + * + * Stops the benchmark timer so the page rendering speed can be shown. + * + * Determines if the "memory_get_usage' function is available so that + * the memory usage can be shown. + * + * @access public + * @return void + */ + function _display($output = '') + { + $BM =& _load_class('CI_Benchmark'); + + if ($output == '') + { + $output =& $this->final_output; + } + + if ($this->cache_expiration > 0) + { + $this->_write_cache($output); + } + + $elapsed = $BM->elapsed_time('code_igniter_start', 'code_igniter_end'); + $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; + + $output = str_replace('{memory_usage}', $memory, $output); + $output = str_replace('{elapsed_time}', $elapsed, $output); + + echo $output; + + log_message('debug', "Final output sent to browser"); + log_message('debug', "Total execution time: ".$elapsed); + } + + // -------------------------------------------------------------------- + + /** + * Write a Cache File + * + * @access public + * @return void + */ + function _write_cache($output) + { + $obj =& get_instance(); + $path = $obj->config->item('cache_path'); + + $cache_path = ($path == '') ? BASEPATH.'cache/' : $path; + + if ( ! is_dir($cache_path) OR ! is_writable($cache_path)) + { + return; + } + + $uri = $obj->config->item('base_url', 1). + $obj->config->item('index_page'). + $obj->uri->uri_string(); + + $cache_path .= md5($uri); + + if ( ! $fp = @fopen($cache_path, 'wb')) + { + log_message('error', "Unable to write ache file: ".$cache_path); + return; + } + + $expire = time() + ($this->cache_expiration * 60); + + flock($fp, LOCK_EX); + fwrite($fp, $expire.'TS--->'.$output); + flock($fp, LOCK_UN); + fclose($fp); + @chmod($cache_path, 0777); + + log_message('debug', "Cache file written: ".$cache_path); + } + + // -------------------------------------------------------------------- + + /** + * Update/serve a cached file + * + * @access public + * @return void + */ + function _display_cache() + { + $CFG =& _load_class('CI_Config'); + $RTR =& _load_class('CI_Router'); + + $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); + + if ( ! is_dir($cache_path) OR ! is_writable($cache_path)) + { + return FALSE; + } + + // Build the file path. The file name is an MD5 hash of the full URI + $uri = $CFG->item('base_url', 1).$CFG->item('index_page').$RTR->uri_string; + + $filepath = $cache_path.md5($uri); + + if ( ! @file_exists($filepath)) + { + return FALSE; + } + + if ( ! $fp = @fopen($filepath, 'rb')) + { + 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 + 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']))) + { + @unlink($filepath); + log_message('debug', "Cache file has expired. File deleted"); + return FALSE; + } + + // Display the cache + $this->_display(str_replace($match['0'], '', $cache)); + log_message('debug', "Cache file is current. Sending it to browser."); + return TRUE; + } + +} +// END Output Class +?> \ No newline at end of file diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php new file mode 100644 index 000000000..0bbb577a3 --- /dev/null +++ b/system/libraries/Pagination.php @@ -0,0 +1,207 @@ +'; + var $cur_tag_close = ''; + var $next_tag_open = ' '; + var $next_tag_close = ' '; + var $prev_tag_open = ' '; + var $prev_tag_close = ''; + var $num_tag_open = ' '; + var $num_tag_close = ''; + + /** + * Constructor + * + * @access public + * @param array initialization parameters + */ + function CI_Pagination($params = array()) + { + if (count($params) > 0) + { + $this->initialize($params); + } + + log_message('debug', "Pagination Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Initialize Preferences + * + * @access public + * @param array initialization parameters + * @return void + */ + function initialize($params = array()) + { + if (count($params) > 0) + { + foreach ($params as $key => $val) + { + if (isset($this->$key)) + { + $this->$key = $val; + } + } + } + } + + // -------------------------------------------------------------------- + + /** + * Generate the pagination links + * + * @access public + * @return string + */ + function create_links() + { + // If our item count or per-page total is zero there is no need to continue. + if ($this->total_rows == 0 OR $this->per_page == 0) + { + return ''; + } + + // Calculate the total number of pages + $num_pages = intval($this->total_rows / $this->per_page); + + // Use modulus to see if our division has a remainder.If so, add one to our page number. + if ($this->total_rows % $this->per_page) + { + $num_pages++; + } + + // Is there only one page? Hm... nothing more to do here then. + if ($num_pages == 1) + { + return ''; + } + + // Determine the current page number. + $obj =& get_instance(); + if ($obj->uri->segment($this->uri_segment) != 0) + { + $this->cur_page = $obj->uri->segment($this->uri_segment); + } + + if ( ! ctype_digit($this->cur_page)) + { + $this->cur_page = 0; + } + + $uri_page_number = $this->cur_page; + $this->cur_page = floor(($this->cur_page/$this->per_page) + 1); + + // Calculate the start and end numbers. These determine + // which number to start and end the digit links with + $start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1; + $end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages; + + // Add a trailing slash to the base URL if needed + $this->base_url = preg_replace("/(.+?)\/*$/", "\\1/", $this->base_url); + + // And here we go... + $output = ''; + + // Render the "First" link + if ($this->cur_page > $this->num_links) + { + $output .= $this->first_tag_open.''.$this->first_link.''.$this->first_tag_close; + } + + // Render the "previous" link + if (($this->cur_page - $this->num_links) >= 0) + { + $i = $uri_page_number - $this->per_page; + if ($i == 0) $i = ''; + $output .= $this->prev_tag_open.''.$this->prev_link.''.$this->prev_tag_close; + } + + // Write the digit links + for ($loop = $start -1; $loop <= $end; $loop++) + { + $i = ($loop * $this->per_page) - $this->per_page; + + if ($i >= 0) + { + if ($this->cur_page == $loop) + { + $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page + } + else + { + $n = ($i == 0) ? '' : $i; + $output .= $this->num_tag_open.''.$loop.''.$this->num_tag_close; + } + } + } + + // Render the "next" link + if ($this->cur_page < $num_pages) + { + $output .= $this->next_tag_open.''.$this->next_link.''.$this->next_tag_close; + } + + // Render the "Last" link + if (($this->cur_page + $this->num_links) < $num_pages) + { + $i = (($num_pages * $this->per_page) - $this->per_page); + $output .= $this->last_tag_open.''.$this->last_link.''.$this->last_tag_close; + } + + // Kill double slashes. Note: Sometimes we can end up with a double slash + // in the penultimate link so we'll kill all double shashes. + $output = preg_replace("#([^:])//+#", "\\1/", $output); + + // Add the wrapper HTML if exists + $output = $this->full_tag_open.$output.$this->full_tag_close; + + return $output; + } +} +// END Pagination Class +?> \ No newline at end of file diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php new file mode 100644 index 000000000..9f6a814ae --- /dev/null +++ b/system/libraries/Parser.php @@ -0,0 +1,178 @@ +load->view($template, '', TRUE); + + if ($template == '') + { + return FALSE; + } + + foreach ($data as $key => $val) + { + if ( ! is_array($val)) + { + $template = $this->_parse_single($key, $val, $template); + } + else + { + $template = $this->_parse_pair($key, $val, $template); + } + } + + if ($return == FALSE) + { + $OUT->final_output = $template; + } + + return $template; + } + // END set_method() + + // -------------------------------------------------------------------- + + /** + * Set the left/right variable delimiters + * + * @access public + * @param string + * @param string + * @return void + */ + function set_delimiters($l = '{', $r = '}') + { + $this->l_delim = $l; + $this->r_delim = $r; + } + // END set_method() + + // -------------------------------------------------------------------- + + /** + * Parse a single key/value + * + * @access private + * @param string + * @param string + * @param string + * @return string + */ + function _parse_single($key, $val, $string) + { + return str_replace($this->l_delim.$key.$this->r_delim, $val, $string); + } + // END set_method() + + // -------------------------------------------------------------------- + + /** + * Parse a tag pair + * + * Parses tag pairs: {some_tag} string... {/some_tag} + * + * @access private + * @param string + * @param array + * @param string + * @return string + */ + function _parse_pair($variable, $data, $string) + { + if (FALSE === ($match = $this->_match_pair($string, $variable))) + { + return $string; + } + + $str = ''; + foreach ($data as $row) + { + $temp = $match['1']; + foreach ($row as $key => $val) + { + if ( ! is_array($val)) + { + $temp = $this->_parse_single($key, $val, $temp); + } + else + { + $temp = $this->_parse_pair($key, $val, $temp); + } + } + + $str .= $temp; + } + + return str_replace($match['0'], $str, $string); + } + // END set_method() + + // -------------------------------------------------------------------- + + /** + * Matches a variable pair + * + * @access private + * @param string + * @param string + * @return mixed + */ + function _match_pair($string, $variable) + { + if ( ! preg_match("|".$this->l_delim . $variable . $this->r_delim."(.+)".$this->l_delim . '/' . $variable . $this->r_delim."|s", $string, $match)) + { + return FALSE; + } + + return $match; + } + // END _match_pair() + +} +// END Parser Class +?> \ No newline at end of file diff --git a/system/libraries/Router.php b/system/libraries/Router.php new file mode 100644 index 000000000..abc253eff --- /dev/null +++ b/system/libraries/Router.php @@ -0,0 +1,318 @@ +config =& _load_class('CI_Config'); + $this->_set_route_mapping(); + log_message('debug', "Router Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Set the route mapping + * + * This function determies what should be served based on the URI request, + * as well as any "routes" that have been set in the routing config file. + * + * @access private + * @return void + */ + function _set_route_mapping() + { + // Are query strings enabled? If so we're done... + if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) + { + $this->set_class($_GET[$this->config->item('controller_trigger')]); + + if (isset($_GET[$this->config->item('function_trigger')])) + { + $this->set_method($_GET[$this->config->item('function_trigger')]); + } + + return; + } + + // Load the routes.php file + include_once(APPPATH.'config/routes'.EXT); + $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route; + unset($route); + + // Set the default controller + $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); + + // Fetch the URI string Depending on the server, + // the URI will be available in one of two globals + switch ($this->config->item('uri_protocol')) + { + case 'path_info' : $this->uri_string = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); + break; + case 'query_string' : $this->uri_string = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); + break; + default : + $path_info = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); + + if ($path_info != '' AND $path_info != "/".SELF) + { + $this->uri_string = $path_info; + } + else + { + $this->uri_string = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); + } + break; + } + + // Is there a URI string? If not, the default controller specified + // by the admin in the "routes" file will be shown. + if ($this->uri_string == '') + { + if ($this->default_controller === FALSE) + { + show_error("Unable to determine what should be displayed. A default route has not been specified in the routing file."); + } + + $this->set_class($this->default_controller); + $this->set_method('index'); + + log_message('debug', "No URI present. Default controller set."); + return; + } + + // Do we need to remove the suffix specified in the config file? + if ($this->config->item('url_suffix') != "") + { + $this->uri_string = preg_replace("|".preg_quote($this->config->item('url_suffix'))."$|", "", $this->uri_string); + } + + // Explode the URI Segments. The individual segments will + // be stored in the $this->segments array. + $this->_compile_segments(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string))); + + + // Remap the class/method if a route exists + unset($this->routes['default_controller']); + + if (count($this->routes) > 0) + { + $this->_parse_routes(); + } + } + // END _set_route_mapping() + + // -------------------------------------------------------------------- + + /** + * Compile Segments + * + * This function takes an array of URI segments as + * input, and puts it into the $this->segments array. + * It also sets the current class/method + * + * @access private + * @param array + * @param bool + * @return void + */ + function _compile_segments($segs, $route = FALSE) + { + $segments = array(); + + $i = 1; + foreach($segs as $val) + { + $val = trim($this->_filter_uri($val)); + + if ($val != '') + $segments[$i++] = $val; + } + + $this->set_class($segments['1']); + + if (isset($segments['2'])) + { + // A scaffolding request. No funny business with the URL + if ($this->routes['scaffolding_trigger'] == $segments['2'] AND $segments['2'] != '_ci_scaffolding') + { + $this->scaffolding_request = TRUE; + unset($this->routes['scaffolding_trigger']); + } + else + { + // A standard method request + $this->set_method($segments['2']); + } + } + + if ($route == FALSE) + { + $this->segments = $segments; + } + + unset($segments); + } + // END _compile_segments() + + // -------------------------------------------------------------------- + + /** + * Filter segments for malicious characters + * + * @access private + * @param string + * @return string + */ + function _filter_uri($str) + { + if ( ! preg_match("/^[a-z0-9~\s\%\.:_-]+$/i", $str)) + { + exit('The URI you submitted has disallowed characters: '.$str); + } + + return $str; + } + // END _filter_uri() + + // -------------------------------------------------------------------- + + /** + * Set the class name + * + * @access public + * @param string + * @return void + */ + function set_class($class) + { + $this->class = $class; + } + // END _filter_uri() + + // -------------------------------------------------------------------- + + /** + * Fetch the current class + * + * @access public + * @return string + */ + function fetch_class() + { + return $this->class; + } + // END _filter_uri() + + // -------------------------------------------------------------------- + + /** + * Set the method name + * + * @access public + * @param string + * @return void + */ + function set_method($method) + { + $this->method = $method; + } + // END set_method() + + // -------------------------------------------------------------------- + + /** + * Fetch the current method + * + * @access public + * @return string + */ + function fetch_method() + { + return $this->method; + } + // END set_method() + + // -------------------------------------------------------------------- + + /** + * Parse Routes + * + * This function matches any routes that may exist in + * the config/routes.php file against the URI to + * determine if the class/method need to be remapped. + * + * @access private + * @return void + */ + function _parse_routes() + { + // Turn the segment array into a URI string + $uri = implode('/', $this->segments); + $num = count($this->segments); + + // Is there a literal match? If so we're done + if (isset($this->routes[$uri])) + { + $this->_compile_segments(explode('/', $this->routes[$uri]), TRUE); + return; + } + + // Loop through the route array looking for wildcards + foreach ($this->routes as $key => $val) + { + if (count(explode('/', $key)) != $num) + continue; + + if (preg_match("|".str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key))."$|", $uri)) + { + $this->_compile_segments(explode('/', $val), TRUE); + break; + } + } + } + // END set_method() +} +// END Router Class +?> \ No newline at end of file diff --git a/system/libraries/Session.php b/system/libraries/Session.php new file mode 100644 index 000000000..4f08cf692 --- /dev/null +++ b/system/libraries/Session.php @@ -0,0 +1,499 @@ +object =& get_instance(); + + log_message('debug', "Session Class Initialized"); + $this->sess_run(); + } + // END display_errors() + + // -------------------------------------------------------------------- + + /** + * Run the session routines + * + * @access public + * @return void + */ + function sess_run() + { + /* + * Set the "now" time + * + * It can either set to GMT or time(). The pref + * is set in the config file. If the developer + * is doing any sort of time localization they + * might want to set the session time to GMT so + * they can offset the "last_activity" and + * "last_visit" times based on each user's locale. + * + */ + if (strtolower($this->object->config->item('time_reference')) == 'gmt') + { + $now = time(); + $this->now = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); + + if (strlen($this->now) < 10) + { + $this->now = time(); + log_message('error', 'The session class could not set a proper GMT timestamp so the local time() value was used.'); + } + } + else + { + $this->now = time(); + } + + /* + * Set the session length + * + * If the session expiration is set to zero in + * the config file we'll set the expiration + * two years from now. + * + */ + $expiration = $this->object->config->item('sess_expiration'); + + if (ctype_digit($expiration)) + { + if ($expiration > 0) + { + $this->sess_length = $this->object->config->item('sess_expiration'); + } + else + { + $this->sess_length = (60*60*24*365*2); + } + } + + // Do we need encryption? + $this->encryption = $this->object->config->item('sess_encrypt_cookie'); + + if ($this->encryption == TRUE) + { + $this->object->load->library('encrypt'); + } + + // Are we using a database? + if ($this->object->config->item('sess_use_database') === TRUE AND $this->object->config->item('sess_table_name') != '') + { + $this->use_database = TRUE; + $this->session_table = $this->object->config->item('sess_table_name'); + $this->object->load->database(); + } + + // Set the cookie name + if ($this->object->config->item('sess_cookie_name') != FALSE) + { + $this->sess_cookie = $this->object->config->item('cookie_prefix').$this->object->config->item('sess_cookie_name'); + } + + /* + * Fetch the current session + * + * If a session doesn't exist we'll create + * a new one. If it does, we'll update it. + * + */ + if ( ! $this->sess_read()) + { + $this->sess_create(); + } + else + { + // We only update the session every five minutes + if (($this->userdata['last_activity'] + 300) < $this->now) + { + $this->sess_update(); + } + } + + // Delete expired sessions if necessary + if ($this->use_database === TRUE) + { + $this->sess_gc(); + } + } + // END sess_run() + + // -------------------------------------------------------------------- + + /** + * Fetch the current session data if it exists + * + * @access public + * @return void + */ + function sess_read() + { + // Fetch the cookie + $session = $this->object->input->cookie($this->sess_cookie); + + if ($session === FALSE) + { + log_message('debug', 'A session cookie was not found.'); + return FALSE; + } + + // Decrypt and unserialize the data + if ($this->encryption == TRUE) + { + $session = $this->object->encrypt->decode($session); + } + + $session = @unserialize($this->strip_slashes($session)); + + if ( ! is_array($session) OR ! isset($session['last_activity'])) + { + log_message('error', 'The session cookie data did not contain a valid array. This could be a possible hacking attempt.'); + return FALSE; + } + + // Is the session current? + if (($session['last_activity'] + $this->sess_length) < $this->now) + { + $this->sess_destroy(); + return FALSE; + } + + // Does the IP Match? + if ($this->object->config->item('sess_match_ip') == TRUE AND $session['ip_address'] != $this->object->input->ip_address()) + { + $this->sess_destroy(); + return FALSE; + } + + // Does the User Agent Match? + if ($this->object->config->item('sess_match_useragent') == TRUE AND $session['user_agent'] != substr($this->object->input->user_agent(), 0, 50)) + { + $this->sess_destroy(); + return FALSE; + } + + // Is there a corresponding session in the DB? + if ($this->use_database === TRUE) + { + $this->object->db->where('session_id', $session['session_id']); + + if ($this->object->config->item('sess_match_ip') == TRUE) + { + $this->object->db->where('ip_address', $session['ip_address']); + } + + if ($this->object->config->item('sess_match_useragent') == TRUE) + { + $this->object->db->where('user_agent', $session['user_agent']); + } + + $query = $this->object->db->get($this->session_table); + + if ($query->num_rows() == 0) + { + $this->sess_destroy(); + return FALSE; + } + else + { + $row = $query->row(); + if (($row->last_activity + $this->sess_length) < $this->now) + { + $this->object->db->where('session_id', $session['session_id']); + $this->object->db->delete($this->session_table); + $this->sess_destroy(); + return FALSE; + } + } + } + + // Session is valid! + $this->userdata = $session; + unset($session); + + return TRUE; + } + // END sess_read() + + // -------------------------------------------------------------------- + + /** + * Write the session cookie + * + * @access public + * @return void + */ + function sess_write() + { + $cookie_data = serialize($this->userdata); + + if ($this->encryption == TRUE) + { + $cookie_data = $this->object->encrypt->encode($cookie_data); + } + + setcookie( + $this->sess_cookie, + $cookie_data, + $this->sess_length + $this->now, + $this->object->config->item('cookie_path'), + $this->object->config->item('cookie_domain'), + 0 + ); + } + // END sess_read() + + // -------------------------------------------------------------------- + + /** + * Create a new session + * + * @access public + * @return void + */ + function sess_create() + { + $sessid = ''; + while (strlen($sessid) < 32) + { + $sessid .= mt_rand(0, mt_getrandmax()); + } + + $this->userdata = array( + 'session_id' => md5(uniqid($sessid, TRUE)), + 'ip_address' => $this->object->input->ip_address(), + 'user_agent' => substr($this->object->input->user_agent(), 0, 50), + 'last_activity' => $this->now + ); + + + // Save the session in the DB if needed + if ($this->use_database === TRUE) + { + $this->object->db->query($this->object->db->insert_string($this->session_table, $this->userdata)); + } + + // Write the cookie + $this->userdata['last_visit'] = 0; + $this->sess_write(); + } + // END sess_read() + + // -------------------------------------------------------------------- + + /** + * Update an existing session + * + * @access public + * @return void + */ + function sess_update() + { + if (($this->userdata['last_activity'] + $this->sess_length) < $this->now) + { + $this->userdata['last_visit'] = $this->userdata['last_activity']; + } + + $this->userdata['last_activity'] = $this->now; + + // Update the session in the DB if needed + if ($this->use_database === TRUE) + { + $this->object->db->query($this->object->db->update_string($this->session_table, array('last_activity' => $this->now), array('session_id' => $this->userdata['session_id']))); + } + + // Write the cookie + $this->sess_write(); + } + // END sess_update() + + // -------------------------------------------------------------------- + + /** + * Destroy the current session + * + * @access public + * @return void + */ + function sess_destroy() + { + setcookie( + $this->sess_cookie, + addslashes(serialize(array())), + ($this->now - 31500000), + $this->object->config->item('cookie_path'), + $this->object->config->item('cookie_domain'), + 0 + ); + } + // END sess_destroy() + + // -------------------------------------------------------------------- + + /** + * Garbage collection + * + * This deletes expired session rows from database + * if the probability percentage is met + * + * @access public + * @return void + */ + function sess_gc() + { + srand(time()); + if ((rand() % 100) < $this->gc_probability) + { + $expire = $this->now - $this->sess_length; + + $this->object->db->where("last_activity < {$expire}"); + $this->object->db->delete($this->session_table); + + log_message('debug', 'Session garbage collection performed.'); + } + } + // END sess_destroy() + + // -------------------------------------------------------------------- + + /** + * Fetch a specific item form the session array + * + * @access public + * @param string + * @return string + */ + function userdata($item) + { + return ( ! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; + } + // END sess_destroy() + + // -------------------------------------------------------------------- + + /** + * Add or change data in the "userdata" array + * + * @access public + * @param mixed + * @param string + * @return void + */ + function set_userdata($newdata = array(), $newval = '') + { + if (is_string($newdata)) + { + $newdata = array($newdata => $newval); + } + + if (count($newdata) > 0) + { + foreach ($newdata as $key => $val) + { + $this->userdata[$key] = $val; + } + } + + $this->sess_write(); + } + // END set_userdata() + + // -------------------------------------------------------------------- + + /** + * Delete a session variable from the "userdata" array + * + * @access array + * @return void + */ + function unset_userdata($newdata = array()) + { + if (is_string($newdata)) + { + $newdata = array($newdata => ''); + } + + if (count($newdata) > 0) + { + foreach ($newdata as $key => $val) + { + unset($this->userdata[$key]); + } + } + + $this->sess_write(); + } + // END set_userdata() + + // -------------------------------------------------------------------- + + /** + * Strip slashes + * + * @access public + * @param mixed + * @return mixed + */ + function strip_slashes($vals) + { + if (is_array($vals)) + { + foreach ($vals as $key=>$val) + { + $vals[$key] = $this->strip_slashes($val); + } + } + else + { + $vals = stripslashes($vals); + } + + return $vals; + } + // END strip_slashes() +} +// END Session Class +?> \ No newline at end of file diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php new file mode 100644 index 000000000..13196eb69 --- /dev/null +++ b/system/libraries/Sha1.php @@ -0,0 +1,254 @@ +> 6) + 1; + + for ($i = 0; $i < $n * 16; $i++) + { + $x[$i] = 0; + } + + for ($i = 0; $i < strlen($str); $i++) + { + $x[$i >> 2] |= ord(substr($str, $i, 1)) << (24 - ($i % 4) * 8); + } + + $x[$i >> 2] |= 0x80 << (24 - ($i % 4) * 8); + + $x[$n * 16 - 1] = strlen($str) * 8; + + $a = 1732584193; + $b = -271733879; + $c = -1732584194; + $d = 271733878; + $e = -1009589776; + + for ($i = 0; $i < sizeof($x); $i += 16) + { + $olda = $a; + $oldb = $b; + $oldc = $c; + $oldd = $d; + $olde = $e; + + for($j = 0; $j < 80; $j++) + { + if ($j < 16) + { + $w[$j] = $x[$i + $j]; + } + else + { + $w[$j] = $this->_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1); + } + + $t = $this->_safe_add($this->_safe_add($this->_rol($a, 5), $this->_ft($j, $b, $c, $d)), $this->_safe_add($this->_safe_add($e, $w[$j]), $this->_kt($j))); + + $e = $d; + $d = $c; + $c = $this->_rol($b, 30); + $b = $a; + $a = $t; + } + + $a = $this->_safe_add($a, $olda); + $b = $this->_safe_add($b, $oldb); + $c = $this->_safe_add($c, $oldc); + $d = $this->_safe_add($d, $oldd); + $e = $this->_safe_add($e, $olde); + } + + return $this->_hex($a).$this->_hex($b).$this->_hex($c).$this->_hex($d).$this->_hex($e); + } + // END generate() + + // -------------------------------------------------------------------- + + /** + * Convert a decimal to hex + * + * @access private + * @param string + * @return string + */ + function _hex($str) + { + $str = dechex($str); + + if (strlen($str) == 7) + { + $str = '0'.$str; + } + + return $str; + } + // END _hex() + + // -------------------------------------------------------------------- + + /** + * Return result based on iteration + * + * @access private + * @return string + */ + function _ft($t, $b, $c, $d) + { + if ($t < 20) + return ($b & $c) | ((~$b) & $d); + if ($t < 40) + return $b ^ $c ^ $d; + if ($t < 60) + return ($b & $c) | ($b & $d) | ($c & $d); + + return $b ^ $c ^ $d; + } + // END _ft() + + // -------------------------------------------------------------------- + + /** + * Determine the additive constant + * + * @access private + * @return string + */ + function _kt($t) + { + if ($t < 20) + { + return 1518500249; + } + else if ($t < 40) + { + return 1859775393; + } + else if ($t < 60) + { + return -1894007588; + } + else + { + return -899497514; + } + } + // END _kt() + + // -------------------------------------------------------------------- + + /** + * Add integers, wrapping at 2^32 + * + * @access private + * @return string + */ + function _safe_add($x, $y) + { + $lsw = ($x & 0xFFFF) + ($y & 0xFFFF); + $msw = ($x >> 16) + ($y >> 16) + ($lsw >> 16); + + return ($msw << 16) | ($lsw & 0xFFFF); + } + // END _safe_add() + + // -------------------------------------------------------------------- + + /** + * Bitwise rotate a 32-bit number + * + * @access private + * @return integer + */ + function _rol($num, $cnt) + { + return ($num << $cnt) | $this->_zero_fill($num, 32 - $cnt); + } + + // -------------------------------------------------------------------- + + /** + * Pad string with zero + * + * @access private + * @return string + */ + function _zero_fill($a, $b) + { + $bin = decbin($a); + + if (strlen($bin) < $b) + { + $bin = 0; + } + else + { + $bin = substr($bin, 0, strlen($bin) - $b); + } + + for ($i=0; $i < $b; $i++) + { + $bin = "0".$bin; + } + + return bindec($bin); + } +} +// END CI_SHA +?> \ No newline at end of file diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php new file mode 100644 index 000000000..583c6d28d --- /dev/null +++ b/system/libraries/Trackback.php @@ -0,0 +1,561 @@ + '', 'title' => '', 'excerpt' => '', 'blog_name' => '', 'charset' => ''); + var $convert_ascii = TRUE; + var $response = ''; + var $error_msg = array(); + + /** + * Constructor + * + * @access public + */ + function 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) + { + if ( ! isset($tb_data[$item])) + { + $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])))); + break; + default : $$item = $this->convert_xml(strip_tags(stripslashes($tb_data[$item]))); + break; + } + + // Convert High ASCII Characters + if ($this->convert_ascii == TRUE) + { + if ($item == 'excerpt') + { + $$item = $this->convert_ascii($$item); + } + elseif ($item == 'title') + { + $$item = $this->convert_ascii($$item); + } + elseif($item == 'blog_name') + { + $$item = $this->convert_ascii($$item); + } + } + } + + // 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) + { + foreach ($ping_url as $url) + { + if ($this->process($url, $data) == FALSE) + { + $return = FALSE; + } + } + } + + return $return; + } + // END send() + + // -------------------------------------------------------------------- + + /** + * Receive Trackback Data + * + * This function simply validates the incoming TB data. + * It returns false on failure and true on success. + * If the data is valid it is set to the $this->data array + * so that it can be inserted into a database. + * + * @access public + * @return bool + */ + function receive() + { + foreach (array('url', 'title', 'blog_name', 'excerpt') as $val) + { + if ( ! isset($_POST[$val]) OR $_POST[$val] == '') + { + $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; + } + // END receive() + + // -------------------------------------------------------------------- + + /** + * Send Trackback Error Message + * + * Allows custom errros to be set. By default it + * sends the "incomplete information" error, as that's + * the most common one. + * + * @access public + * @param string + * @return void + */ + function send_error($message = 'Incomplete Information') + { + echo "\n\n1\n".$message."\n"; + exit; + } + // END send_error() + + // -------------------------------------------------------------------- + + /** + * Send Trackback Success Message + * + * This should be called when a trackback has been + * successfully received and inserted. + * + * @access public + * @return void + */ + function send_success() + { + echo "\n\n0\n"; + exit; + } + // END send_success() + + // -------------------------------------------------------------------- + + /** + * Fetch a particular item + * + * @access public + * @param string + * @return string + */ + function data($item) + { + return ( ! isset($this->data[$item])) ? '' : $this->data[$item]; + } + // END data() + + // -------------------------------------------------------------------- + + /** + * Process Trackback + * + * Opens a socket connection and passes the data to + * the server. Returns true on success, false on failure + * + * @access public + * @param string + * @param string + * @return bool + */ + function process($url, $data) + { + $target = parse_url($url); + + // Open the socket + if ( ! $fp = @fsockopen($target['host'], 80)) + { + $this->set_error('Invalid Connection: '.$url); + return FALSE; + } + + // 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 + if ($id = $this->get_id($url)) + { + $data = "tb_id=".$id."&".$data; + } + + // Transfer the data + fputs ($fp, "POST " . $path . " HTTP/1.0\r\n" ); + fputs ($fp, "Host: " . $target['host'] . "\r\n" ); + fputs ($fp, "Content-type: application/x-www-form-urlencoded\r\n" ); + fputs ($fp, "Content-length: " . strlen($data) . "\r\n" ); + fputs ($fp, "Connection: close\r\n\r\n" ); + fputs ($fp, $data); + + // Was it successful? + $this->response = ""; + + while(!feof($fp)) + { + $this->response .= fgets($fp, 128); + } + @fclose($fp); + + if ( ! eregi("0", $this->response)) + { + $message = 'An unknown error was encountered'; + + if (preg_match("/(.*?)<\/message>/is", $this->response, $match)) + { + $message = trim($match['1']); + } + + $this->set_error($message); + return FALSE; + } + + return TRUE; + } + // END process() + + // -------------------------------------------------------------------- + + /** + * Extract Trackback URLs + * + * This function lets multiple trackbacks be sent. + * It takes a string of URLs (separated by comma or + * space) and puts each URL into an array + * + * @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; + } + // END extract_urls() + + // -------------------------------------------------------------------- + + /** + * Validate URL + * + * Simply adds "http://" if missing + * + * @access public + * @param string + * @return string + */ + function validate_url($url) + { + $url = trim($url); + + if (substr($url, 0, 4) != "http") + { + $url = "http://".$url; + } + } + // END validate_url() + + // -------------------------------------------------------------------- + + /** + * Find the Trackback URL's ID + * + * @access public + * @param string + * @return string + */ + function get_id($url) + { + $tb_id = ""; + + if (strstr($url, '?')) + { + $tb_array = explode('/', $url); + $tb_end = $tb_array[count($tb_array)-1]; + + if ( ! ctype_digit($tb_end)) + { + $tb_end = $tb_array[count($tb_array)-2]; + } + + $tb_array = explode('=', $tb_end); + $tb_id = $tb_array[count($tb_array)-1]; + } + else + { + if (ereg("/$", $url)) + { + $url = substr($url, 0, -1); + } + + $tb_array = explode('/', $url); + $tb_id = $tb_array[count($tb_array)-1]; + + if ( ! ctype_digit($tb_id)) + { + $tb_id = $tb_array[count($tb_array)-2]; + } + } + + if ( ! preg_match ("/^([0-9]+)$/", $tb_id)) + { + return false; + } + else + { + return $tb_id; + } + } + // END get_id() + + // -------------------------------------------------------------------- + + /** + * Convert Reserved XML characters to Entities + * + * @access public + * @param string + * @return string + */ + 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); + + $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); + $str = preg_replace("/$temp(\w+);/","&\\1;", $str); + + return $str; + } + // END get_id() + + // -------------------------------------------------------------------- + + /** + * Character limiter + * + * Limits the string based on the character count. Will preserve complete words. + * + * @access public + * @param string + * @param integer + * @param string + * @return string + */ + function limit_characters($str, $n = 500, $end_char = '…') + { + if (strlen($str) < $n) + { + return $str; + } + + $str = preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $str)); + + if (strlen($str) <= $n) + { + return $str; + } + + $out = ""; + foreach (explode(' ', trim($str)) as $val) + { + $out .= $val.' '; + if (strlen($out) >= $n) + { + return trim($out).$end_char; + } + } + } + // END get_id() + + // -------------------------------------------------------------------- + + /** + * High ASCII to Entities + * + * Converts Hight ascii text and MS Word special chars + * to character entities + * + * @access public + * @param string + * @return string + */ + 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; + } + // END convert_ascii() + + // -------------------------------------------------------------------- + + /** + * Set error message + * + * @access public + * @param string + * @return void + */ + function set_error($msg) + { + log_message('error', $msg); + $this->error_msg[] = $msg; + } + // END convert_ascii() + + // -------------------------------------------------------------------- + + /** + * Show error messages + * + * @access public + * @param string + * @param string + * @return string + */ + function display_errors($open = '

', $close = '

') + { + $str = ''; + foreach ($this->error_msg as $val) + { + $str .= $open.$val.$close; + } + + return $str; + } + // END display_errors() +} +// END Trackback Class +?> \ No newline at end of file diff --git a/system/libraries/URI.php b/system/libraries/URI.php new file mode 100644 index 000000000..4c2fa9c7f --- /dev/null +++ b/system/libraries/URI.php @@ -0,0 +1,243 @@ +uri =& _load_class('CI_Router'); + log_message('debug', "URI Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Fetch a URI Segment + * + * This function returns the URI segment based on the number provided. + * + * @access public + * @param integer + * @param bool + * @return string + */ + function segment($n, $no_result = FALSE) + { + return ( ! isset($this->uri->segments[$n])) ? $no_result : $this->uri->segments[$n]; + } + + // -------------------------------------------------------------------- + + /** + * Generate a key value pair from the URI string + * + * This function generates and associative array of URI data starting + * at the supplied segment. For example, if this is your URI: + * + * www.your-site.com/user/search/name/joe/location/UK/gender/male + * + * You can use this function to generate an array with this prototype: + * + * array ( + * name => joe + * location => UK + * gender => male + * ) + * + * @access public + * @param integer the starting segment number + * @param array an array of default values + * @return array + */ + function uri_to_assoc($n = 3, $default = array()) + { + if ( ! ctype_digit($n)) + { + return $default; + } + + if (isset($this->keyval[$n])) + { + return $this->keyval[$n]; + } + + if ($this->total_segments() < $n) + { + if (count($default) == 0) + { + return array(); + } + + $retval = array(); + foreach ($default as $val) + { + $retval[$val] = FALSE; + } + return $default; + } + + $segments = array_slice($this->segment_array(), ($n - 1)); + + $i = 0; + $lastval = ''; + $retval = array(); + foreach ($segments as $seg) + { + if ($i % 2) + { + $retval[$lastval] = $seg; + } + else + { + $retval[$seg] = FALSE; + $lastval = $seg; + } + + $i++; + } + + if (count($default) > 0) + { + foreach ($default as $val) + { + if ( ! array_key_exists($val, $retval)) + { + $retval[$val] = FALSE; + } + } + } + + // Cache the array for reuse + $this->keyval[$n] = $retval; + return $retval; + } + + /** + * Generate a URI string from an associative array + * + * + * @access public + * @param array an associative array of key/values + * @return array + */ function assoc_to_uri($array) + { + $temp = array(); + foreach ((array)$array as $key => $val) + { + $temp[] = $key; + $temp[] = $val; + } + + return implode('/', $temp); + } + + + // -------------------------------------------------------------------- + + /** + * Fetch a URI Segment and add a trailing slash + * + * @access public + * @param integer + * @param string + * @return string + */ + function slash_segment($n, $where = 'trailing') + { + if ($where == 'trailing') + { + $trailing = '/'; + $leading = ''; + } + elseif ($where == 'leading') + { + $leading = '/'; + $trailing = ''; + } + else + { + $leading = '/'; + $trailing = '/'; + } + return ( ! isset($this->uri->segments[$n])) ? '' : $leading.$this->uri->segments[$n].$trailing; + } + + // -------------------------------------------------------------------- + + /** + * Segment Array + * + * @access public + * @return array + */ + function segment_array() + { + return $this->uri->segments; + } + + // -------------------------------------------------------------------- + + /** + * Total number of segments + * + * @access public + * @return integer + */ + function total_segments() + { + return count($this->uri->segments); + } + + // -------------------------------------------------------------------- + + /** + * Fetch the entire URI string + * + * @access public + * @return string + */ + function uri_string() + { + return $this->uri->uri_string; + } + +} +// END URI Class +?> \ No newline at end of file diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php new file mode 100644 index 000000000..bf50350ae --- /dev/null +++ b/system/libraries/Unit_test.php @@ -0,0 +1,331 @@ +active == FALSE) + return; + + if (in_array($expected, array('is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'))) + { + $expected = str_replace('is_float', 'is_double', $expected); + $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; + else + $result = ($test == $expected) ? TRUE : FALSE; + + $extype = gettype($expected); + } + + $back = $this->_backtrace(); + + $report[] = array ( + 'test_name' => $test_name, + 'test_datatype' => gettype($test), + 'res_datatype' => $extype, + 'result' => ($result === TRUE) ? 'passed' : 'failed', + 'file' => $back['file'], + 'line' => $back['line'] + ); + + $this->results[] = $report; + + return($this->report($this->result($report))); + } + + // -------------------------------------------------------------------- + + /** + * Generate a report + * + * Displays a table with the test data + * + * @access public + * @return string + */ + function report($result = array()) + { + if (count($result) == 0) + { + $result = $this->result(); + } + + $this->_parse_template(); + + $r = ''; + foreach ($result as $res) + { + $table = ''; + + foreach ($res as $key => $val) + { + $temp = $this->_template_rows; + $temp = str_replace('{item}', $key, $temp); + $temp = str_replace('{result}', $val, $temp); + $table .= $temp; + } + + $r .= str_replace('{rows}', $table, $this->_template); + } + + return $r; + } + + // -------------------------------------------------------------------- + + /** + * Use strict comparison + * + * Causes the evaluation to use === rather then == + * + * @access public + * @param bool + * @return null + */ + function use_strict($state = TRUE) + { + $this->strict = ($state == FALSE) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Make Unit testing active + * + * Enables/disables unit testing + * + * @access public + * @param bool + * @return null + */ + function active($state = TRUE) + { + $this->active = ($state == FALSE) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Result Array + * + * Returns the raw result data + * + * @access public + * @return array + */ + function result($results = array()) + { + $obj =& get_instance(); + $obj->load->language('unit_test'); + + if (count($results) == 0) + { + $results = $this->results; + } + + $retval = array(); + foreach ($results as $result) + { + $temp = array(); + foreach ($result as $key => $val) + { + if (is_array($val)) + { + foreach ($val as $k => $v) + { + if (FALSE !== ($line = $obj->lang->line(strtolower('ut_'.$v)))) + { + $v = $line; + } + $temp[$obj->lang->line('ut_'.$k)] = $v; + } + } + else + { + if (FALSE !== ($line = $obj->lang->line(strtolower('ut_'.$val)))) + { + $val = $line; + } + $temp[$obj->lang->line('ut_'.$key)] = $val; + } + } + + $retval[] = $temp; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Set the template + * + * This lets us set the template to be used to display results + * + * @access public + * @params string + * @return void + */ + function set_template($tempalte) + { + $this->_template = $tempalte; + } + + // -------------------------------------------------------------------- + + /** + * Generate a backtrace + * + * This lets us show file names and line numbers + * + * @access private + * @return array + */ + function _backtrace() + { + 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 + * + * @access private + * @return string + */ + function _default_template() + { + $this->_template = ' +
+ + {rows} +
'; + + $this->_template_rows = ' + + {item} + {result} + + '; + } + + // -------------------------------------------------------------------- + + /** + * Parse Template + * + * Harvests the data within the template {pseudo-variables} + * + * @access private + * @return void + */ + 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->_template_rows = $match['1']; + $this->_template = str_replace($match['0'], '{rows}', $this->_template); + } + +} +// END Unit_test Class + +/** + * Helper functions to test boolean true/false + * + * + * @access private + * @return bool + */ +function is_true($test) +{ + return (is_bool($test) AND $test === TRUE) ? TRUE : FALSE; +} +function is_false($test) +{ + return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; +} + +?> \ No newline at end of file diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php new file mode 100644 index 000000000..6d12dbcd7 --- /dev/null +++ b/system/libraries/Upload.php @@ -0,0 +1,775 @@ + 0) + { + $this->initialize($props); + } + + log_message('debug', "Upload Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Initialize preferences + * + * @access public + * @param array + * @return void + */ + function initialize($config = array()) + { + foreach ($config as $key => $val) + { + $method = 'set_'.$key; + if (method_exists($this, $method)) + { + $this->$method($val); + } + else + { + $this->$key = $val; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Perform the file upload + * + * @access public + * @return bool + */ + function do_upload() + { + // Is $_FILES['userfile'] set? If not, no reason to continue. + if ( ! isset($_FILES['userfile'])) + { + $this->set_error('upload_userfile_not_set'); + return FALSE; + } + + // Is the upload path valid? + if ( ! $this->validate_upload_path()) + { + return FALSE; + } + + // Was the file able to be uploaded? If not, determine the reason why. + if ( ! is_uploaded_file($_FILES['userfile']['tmp_name'])) + { + $error = ( ! isset($_FILES['userfile']['error'])) ? 4 : $_FILES['userfile']['error']; + + switch($error) + { + case 1 : $this->set_error('upload_file_exceeds_limit'); + break; + case 3 : $this->set_error('upload_file_partial'); + break; + case 4 : $this->set_error('upload_no_file_selected'); + break; + default : $this->set_error('upload_no_file_selected'); + break; + } + + return FALSE; + } + + // Set the uploaded data as class variables + $this->file_temp = $_FILES['userfile']['tmp_name']; + $this->file_name = $_FILES['userfile']['name']; + $this->file_size = $_FILES['userfile']['size']; + $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES['userfile']['type']); + $this->file_type = strtolower($this->file_type); + $this->file_ext = $this->get_extension($_FILES['userfile']['name']); + + // Convert the file size to kilobytes + if ($this->file_size > 0) + { + $this->file_size = round($this->file_size/1024, 2); + } + + // Is the file type allowed to be uploaded? + if ( ! $this->is_allowed_filetype()) + { + $this->set_error('upload_invalid_filetype'); + return FALSE; + } + + // Is the file size within the allowed maximum? + if ( ! $this->is_allowed_filesize()) + { + $this->set_error('upload_invalid_filesize'); + return FALSE; + } + + // Are the image dimensions within the allowed size? + // Note: This can fail if the server has an open_basdir restriction. + if ( ! $this->is_allowed_dimensions()) + { + $this->set_error('upload_invalid_dimensions'); + return FALSE; + } + + // Sanitize the file name for security + $this->file_name = $this->clean_file_name($this->file_name); + + // Remove white spaces in the name + if ($this->remove_spaces == TRUE) + { + $this->file_name = preg_replace("/\s+/", "_", $this->file_name); + } + + /* + * Validate the file name + * This function appends an number onto the end of + * the file if one with the same name already exists. + * If it returns false there was a problem. + */ + $this->orig_name = $this->file_name; + + if ($this->overwrite == FALSE) + { + $this->file_name = $this->set_filename($this->file_path, $this->file_name); + + if ($this->file_name === FALSE) + { + return FALSE; + } + } + + /* + * Move the file to the final destination + * To deal with different server configurations + * we'll attempt to use copy() first. If that fails + * we'll use move_uploaded_file(). One of the two should + * reliably work in most environments + */ + if ( ! @copy($this->file_temp, $this->file_path.$this->file_name)) + { + if ( ! @move_uploaded_file($this->file_temp, $this->file_path.$this->file_name)) + { + $this->set_error('upload_destination_error'); + return FALSE; + } + } + + /* + * Run the file through the XSS hacking filter + * This helps prevent malicious code from being + * embedded within a file. Scripts can easily + * be disguised as images or other file types. + */ + if ($this->xss_clean == TRUE) + { + $this->do_xss_clean(); + } + + /* + * Set the finalized image dimensions + * This sets the image width/height (assuming the + * file was an image). We use this information + * in the "data" function. + */ + $this->set_image_properties($this->file_path.$this->file_name); + + 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 ( + 'file_name' => $this->file_name, + 'file_type' => $this->file_type, + 'file_path' => $this->file_path, + 'full_path' => $this->file_path.$this->file_name, + 'raw_name' => str_replace($this->file_ext, '', $this->file_name), + 'orig_name' => $this->orig_name, + 'file_ext' => $this->file_ext, + 'file_size' => $this->file_size, + 'is_image' => $this->is_image(), + 'image_width' => $this->image_width, + 'image_height' => $this->image_height, + 'image_type' => $this->image_type, + 'image_size_str' => $this->image_size_str, + ); + } + + // -------------------------------------------------------------------- + + /** + * Set Upload Path + * + * @access public + * @param string + * @return void + */ + function set_upload_path($path) + { + $this->file_path = $path; + } + + // -------------------------------------------------------------------- + + /** + * Set the file name + * + * This function takes a filename/path as input and looks for the + * existnace of a file with the same name. If found, it will append a + * number to the end of the filename to avoid overwritting a pre-existing file. + * + * @access public + * @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; + } + + 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; + break; + } + } + + if ($new_filename == '') + { + $this->set_error('upload_bad_filename'); + return FALSE; + } + else + { + return $new_filename; + } + } + + // -------------------------------------------------------------------- + + /** + * Set Maximum File Size + * + * @access public + * @param integer + * @return void + */ + function set_max_filesize($n) + { + $this->max_size = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + } + + // -------------------------------------------------------------------- + + /** + * Set Maximum Image Width + * + * @access public + * @param integer + * @return void + */ + function set_max_width($n) + { + $this->max_width = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + } + + // -------------------------------------------------------------------- + + /** + * Set Maximum Image Height + * + * @access public + * @param integer + * @return void + */ + function set_max_height($n) + { + $this->max_height = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + } + + // -------------------------------------------------------------------- + + /** + * Set Allowed File Types + * + * @access public + * @param string + * @return void + */ + function set_allowed_types($types) + { + $this->allowed_types = explode('|', $types); + } + + // -------------------------------------------------------------------- + + /** + * Set Image Properties + * + * Uses GD to determine the width/height/type of image + * + * @access public + * @param string + * @return void + */ + function set_image_properties($path = '') + { + if ( ! $this->is_image()) + { + return; + } + + if (function_exists('getimagesize')) + { + if (FALSE !== ($D = @getimagesize($path))) + { + $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); + + $this->image_width = $D['0']; + $this->image_height = $D['1']; + $this->image_type = ( ! isset($types[$D['2']])) ? 'unknown' : $types[$D['2']]; + $this->image_size_str = $D['3']; // string containing height and width + } + } + } + + // -------------------------------------------------------------------- + + /** + * Set XSS Clean + * + * Enables the XSS flag so that the file that was uploaded + * will be run through the XSS filter. + * + * @access public + * @param bool + * @return void + */ + function set_xss_clean($flag = FALSE) + { + $this->xss_clean = ($flag == TRUE) ? TRUE : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Validate the image + * + * @access public + * @return bool + */ + function is_image() + { + $img_mimes = array( + 'image/gif', + 'image/jpg', + 'image/jpe', + 'image/jpeg', + 'image/pjpeg', + 'image/png', + 'image/x-png' + ); + + + return (in_array($this->file_type, $img_mimes)) ? TRUE : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Verify that the filetype is allowed + * + * @access public + * @return bool + */ + function is_allowed_filetype() + { + if (count($this->allowed_types) == 0) + { + $this->set_error('upload_no_file_types'); + return FALSE; + } + + foreach ($this->allowed_types as $val) + { + $mime = $this->mimes_types(strtolower($val)); + + if (is_array($mime)) + { + if (in_array($this->file_type, $mime)) + { + return TRUE; + } + } + else + { + if ($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) + { + return FALSE; + } + else + { + return TRUE; + } + } + + // -------------------------------------------------------------------- + + /** + * Verify that the image is within the allowed width/height + * + * @access public + * @return bool + */ + function is_allowed_dimensions() + { + if ( ! $this->is_image()) + { + return TRUE; + } + + if (function_exists('getimagesize')) + { + $D = @getimagesize($this->file_temp); + + if ($this->max_width > 0 AND $D['0'] > $this->max_width) + { + return FALSE; + } + + if ($this->max_height > 0 AND $D['1'] > $this->max_height) + { + return FALSE; + } + + return TRUE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * VAlidate Upload Path + * + * Verifies that it is a valid upload path with proper permissions. + * + * + * @access public + * @return bool + */ + function validate_upload_path() + { + if ($this->file_path == '') + { + $this->set_error('upload_no_filepath'); + return FALSE; + } + + if (function_exists('realpath') AND @realpath($this->file_path) !== FALSE) + { + $this->file_path = str_replace("\\", "/", realpath($this->file_path)); + } + + if ( ! @is_dir($this->file_path)) + { + $this->set_error('upload_no_filepath'); + return FALSE; + } + + if ( ! is_writable($this->file_path)) + { + $this->set_error('upload_not_writable'); + return FALSE; + } + + $this->file_path = preg_replace("/(.+?)\/*$/", "\\1/", $this->file_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( + "", + "'", + "<", + ">", + '"', + '&', + '$', + '=', + ';', + '?', + '/', + "%20", + "%22", + "%3c", // < + "%253c", // < + "%3e", // > + "%0e", // > + "%28", // ( + "%29", // ) + "%2528", // ( + "%26", // & + "%24", // $ + "%3f", // ? + "%3b", // ; + "%3d" // = + ); + + foreach ($bad as $val) + { + $filename = str_replace($val, '', $filename); + } + + return $filename; + } + + // -------------------------------------------------------------------- + + /** + * Runs the file through the XSS clean function + * + * This prevents people from embedding malicious code in their files. + * I'm not sure that it won't negatively affect certain files in unexpected ways, + * but so far I haven't found that it causes trouble. + * + * @access public + * @return void + */ + function do_xss_clean() + { + $file = $this->file_path.$this->file_name; + + if (filesize($file) == 0) + { + return FALSE; + } + + if ( ! $fp = @fopen($file, 'rb')) + { + return FALSE; + } + + flock($fp, LOCK_EX); + + $data = fread($fp, filesize($file)); + + $obj =& get_instance(); + $data = $obj->input->xss_clean($data); + + fwrite($fp, $data); + flock($fp, LOCK_UN); + fclose($fp); + } + + // -------------------------------------------------------------------- + + /** + * Set an error message + * + * @access public + * @param string + * @return void + */ + function set_error($msg) + { + $obj =& get_instance(); + $obj->lang->load('upload'); + + if (is_array($msg)) + { + foreach ($msg as $val) + { + $msg = ($obj->lang->line($val) == FALSE) ? $val : $obj->lang->line($val); + $this->error_msg[] = $msg; + log_message('error', $msg); + } + } + else + { + $msg = ($obj->lang->line($msg) == FALSE) ? $msg : $obj->lang->line($msg); + $this->error_msg[] = $msg; + log_message('error', $msg); + } + } + + // -------------------------------------------------------------------- + + /** + * Display the error message + * + * @access public + * @param string + * @param string + * @return string + */ + function display_errors($open = '

', $close = '

') + { + $str = ''; + foreach ($this->error_msg as $val) + { + $str .= $open.$val.$close; + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * List of Mime Types + * + * This is a list of mime types. We use it to validate + * the "allowed types" set by the developer + * + * @access public + * @param string + * @return string + */ + function mimes_types($mime) + { + if (count($this->mimes) == 0) + { + if (@include(APPPATH.'config/mimes'.EXT)) + { + $this->mimes = $mimes; + unset($mimes); + } + } + + return ( ! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime]; + } + +} +// END Upload Class +?> \ No newline at end of file diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php new file mode 100644 index 000000000..df8c70ee8 --- /dev/null +++ b/system/libraries/Validation.php @@ -0,0 +1,692 @@ +'; + var $_error_suffix = '

'; + var $obj; + + + /** + * Constructor + * + */ + function CI_Validation() + { + $this->obj =& get_instance(); + log_message('debug', "Validation Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Set Fields + * + * This function takes an array of field names as input + * and generates class variables with the same name, which will + * either be blank or contain the $_POST value corresponding to it + * + * @access public + * @param string + * @param string + * @return void + */ + function set_fields($data = '', $field = '') + { + if ($data == '') + return; + + if ( ! is_array($data)) + { + if ($field == '') + return; + + $data = array($data => $field); + } + + $this->_fields = $data; + + foreach($this->_fields as $key => $val) + { + $this->$key = ( ! isset($_POST[$key]) OR is_array($_POST[$key])) ? '' : $this->prep_for_form($_POST[$key]); + + $error = $key.'_error'; + if ( ! isset($this->$error)) + { + $this->$error = ''; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Set Rules + * + * This function takes an array of field names and validation + * rules as input ad simply stores is for use later. + * + * @access public + * @param mixed + * @param string + * @return void + */ + function set_rules($data, $rules = '') + { + if ( ! is_array($data)) + { + if ($rules == '') + return; + + $data[$data] = $rules; + } + + foreach ($data as $key => $val) + { + $this->_rules[$key] = $val; + } + } + + // -------------------------------------------------------------------- + + /** + * Set Error Message + * + * Lets users set their own error messages on the fly. Note: The key + * name has to match the function name that it corresponds to. + * + * @access public + * @param string + * @param string + * @return string + */ + function set_message($lang, $val = '') + { + if ( ! is_array($lang)) + { + $lang = array($lang => $val); + } + + $this->_error_messages = array_merge($this->_error_messages, $lang); + } + + // -------------------------------------------------------------------- + + /** + * Set The Error Delimiter + * + * Permits a prefix/suffix to be added to each error message + * + * @access public + * @param string + * @param string + * @return void + */ + function set_error_delimiters($prefix = '

', $suffix = '

') + { + $this->_error_prefix = $prefix; + $this->_error_suffix = $suffix; + } + + // -------------------------------------------------------------------- + + /** + * Run the Validator + * + * This function does all the work. + * + * @access public + * @return bool + */ + function run() + { + // Do we even have any data to process? Mm? + if (count($_POST) == 0 OR count($this->_rules) == 0) + { + return FALSE; + } + + // Load the language file containing error messages + $this->obj->lang->load('validation'); + + // Cycle through the rules and test for errors + foreach ($this->_rules as $field => $rules) + { + //Explode out the rules! + $ex = explode('|', $rules); + + // Is the field required? If not, if the field is blank we'll move on to the next text + if ( ! in_array('required', $ex)) + { + if ( ! isset($_POST[$field]) OR $_POST[$field] == '') + { + continue; + } + } + + /* + * Are we dealing with an "isset" rule? + * + * Before going further, we'll see if one of the rules + * is to check whether the item is set (typically this + * applies only to checkboxes). If so, we'll + * test for it here since there's not reason to go + * further + */ + if ( ! isset($_POST[$field])) + { + if (in_array('isset', $ex) OR in_array('required', $ex)) + { + if ( ! isset($this->messages['isset'])) + { + if (FALSE === ($line = $this->obj->lang->line('isset'))) + { + $line = 'The field was not set'; + } + } + else + { + $line = $this->_error_messages['isset']; + } + + $field = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; + $this->_error_array[] = sprintf($line, $field); + } + + continue; + } + + /* + * Set the current field + * + * The various prepping functions need to know the + * current field name so they can do this: + * + * $_POST[$this->_current_field] == 'bla bla'; + */ + $this->_current_field = $field; + + // Cycle through the rules! + foreach ($ex As $rule) + { + + // 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; + if (preg_match("/.*?(\[.*?\]).*/", $rule, $match)) + { + $param = substr(substr($match['1'], 1), 0, -1); + $rule = str_replace($match['1'], '', $rule); + } + + // Call the function that corresponds to the rule + if ($callback === TRUE) + { + if ( ! method_exists($this->obj, $rule)) + { + continue; + } + + $result = $this->obj->$rule($_POST[$field], $param); + } + else + { + if ( ! method_exists($this, $rule)) + { + /* + * Run the native PHP function if called for + * + * 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)) + { + $_POST[$field] = $rule($_POST[$field]); + $this->$field = $_POST[$field]; + } + + continue; + } + + $result = $this->$rule($_POST[$field], $param); + } + + // Did the rule test negatively? If so, grab the error. + if ($result === FALSE) + { + if ( ! isset($this->_error_messages[$rule])) + { + if (FALSE === ($line = $this->obj->lang->line($rule))) + { + $line = 'Unable to access an error message corresponding to your field name.'; + } + } + else + { + $line = $this->_error_messages[$rule];; + } + + // Build the error message + $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; + $mparam = ( ! isset($this->_fields[$param])) ? $param : $this->_fields[$param]; + $message = sprintf($line, $mfield, $mparam); + + // Set the error variable. Example: $this->username_error + $error = $field.'_error'; + $this->$error = $this->_error_prefix.$message.$this->_error_suffix; + + // Add the error to the error array + $this->_error_array[] = $message; + continue 2; + } + } + } + + $total_errors = count($this->_error_array); + + /* + * Recompile the class variables + * + * If any prepping functions were called the $_POST data + * might now be different then the corresponding class + * variables so we'll set them anew. + */ + if ($total_errors > 0) + { + $this->_safe_form_data = TRUE; + } + + $this->set_fields(); + + // Did we end up with any errors? + if ($total_errors == 0) + { + return TRUE; + } + + // Generate the error string + foreach ($this->_error_array as $val) + { + $this->error_string .= $this->_error_prefix.$val.$this->_error_suffix."\n"; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Required + * + * @access public + * @param string + * @return bool + */ + function required($str) + { + if ( ! is_array($str)) + { + return (trim($str) == '') ? FALSE : TRUE; + } + else + { + return ( ! empty($str)); + } + } + + // -------------------------------------------------------------------- + + /** + * Match one field to another + * + * @access public + * @param string + * @return bool + */ + function matches($str, $field) + { + if ( ! isset($_POST[$field])) + { + return FALSE; + } + + return ($str !== $_POST[$field]) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Minimum Length + * + * @access public + * @param string + * @return bool + */ + function min_length($str, $val) + { + if ( ! ctype_digit($val)) + { + return FALSE; + } + + return (strlen($str) < $val) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Max Length + * + * @access public + * @param string + * @return bool + */ + function max_length($str, $val) + { + if ( ! ctype_digit($val)) + { + return FALSE; + } + + return (strlen($str) > $val) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Exact Length + * + * @access public + * @param string + * @return bool + */ + function exact_length($str, $val) + { + if ( ! ctype_digit($val)) + { + return FALSE; + } + + 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; + } + + // -------------------------------------------------------------------- + + /** + * 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 ( ! ctype_digit($str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Set Select + * + * Enables pull-down lists to be set to the value the user + * selected in the event of an error + * + * @access public + * @param string + * @param string + * @return string + */ + function set_select($field = '', $value = '') + { + if ($field == '' OR $value == '' OR ! isset($_POST[$field])) + { + return ''; + } + + if ($_POST[$field] == $value) + { + return ' selected="selected"'; + } + } + + // -------------------------------------------------------------------- + + /** + * Set Radio + * + * Enables radio buttons to be set to the value the user + * selected in the event of an error + * + * @access public + * @param string + * @param string + * @return string + */ + function set_radio($field = '', $value = '') + { + if ($field == '' OR $value == '' OR ! isset($_POST[$field])) + { + return ''; + } + + if ($_POST[$field] == $value) + { + return ' checked="checked"'; + } + } + + // -------------------------------------------------------------------- + + /** + * Set Checkbox + * + * Enables checkboxes to be set to the value the user + * selected in the event of an error + * + * @access public + * @param string + * @param string + * @return string + */ + function set_checkbox($field = '', $value = '') + { + if ($field == '' OR $value == '' OR ! isset($_POST[$field])) + { + return ''; + } + + if ($_POST[$field] == $value) + { + return ' checked="checked"'; + } + } + + // -------------------------------------------------------------------- + + /** + * Prep data for form + * + * This function allows HTML to be safely shown in a form. + * Special characters are converted. + * + * @access public + * @param string + * @return string + */ + function prep_for_form($str = '') + { + if ($this->_safe_form_data == FALSE OR $str == '') + { + return $str; + } + + return str_replace(array("'", '"', '<', '>'), array("'", """, '<', '>'), stripslashes($str)); + } + + // -------------------------------------------------------------------- + + /** + * Prep URL + * + * @access public + * @param string + * @return string + */ + function prep_url($str = '') + { + if ($str == 'http://' OR $str == '') + { + $_POST[$this->_current_field] = ''; + return; + } + + if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') + { + $str = 'http://'.$str; + } + + $_POST[$this->_current_field] = $str; + } + + // -------------------------------------------------------------------- + + /** + * Strip Image Tags + * + * @access public + * @param string + * @return string + */ + function strip_image_tags($str) + { + $_POST[$this->_current_field] = $this->input->strip_image_tags($str); + } + + // -------------------------------------------------------------------- + + /** + * XSS Clean + * + * @access public + * @param string + * @return string + */ + function xss_clean($str) + { + $_POST[$this->_current_field] = $this->obj->input->xss_clean($str); + } + + // -------------------------------------------------------------------- + + /** + * Convert PHP tags to entities + * + * @access public + * @param string + * @return string + */ + function encode_php_tags($str) + { + $_POST[$this->_current_field] = str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); + } + +} +// END Validation Class +?> \ No newline at end of file diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php new file mode 100644 index 000000000..9eeb46a15 --- /dev/null +++ b/system/libraries/Xmlrpc.php @@ -0,0 +1,1409 @@ +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' + ); + + // Array of Valid Parents for Various XML-RPC elements + $this->valid_parents = array('BOOLEAN' => array('VALUE'), + 'I4' => array('VALUE'), + 'INT' => array('VALUE'), + 'STRING' => array('VALUE'), + 'DOUBLE' => array('VALUE'), + 'DATETIME.ISO8601' => array('VALUE'), + 'BASE64' => array('VALUE'), + 'ARRAY' => array('VALUE'), + 'STRUCT' => array('VALUE'), + 'PARAM' => array('PARAMS'), + 'METHODNAME' => array('METHODCALL'), + 'PARAMS' => array('METHODCALL', 'METHODRESPONSE'), + 'MEMBER' => array('STRUCT'), + 'NAME' => array('MEMBER'), + 'DATA' => array('ARRAY'), + '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'; + $this->xmlrpcerr['invalid_return'] = '2'; + $this->xmlrpcstr['invalid_return'] = 'The XML data receieved was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.'; + $this->xmlrpcerr['incorrect_params'] = '3'; + $this->xmlrpcstr['incorrect_params'] = 'Incorrect parameters were passed to method'; + $this->xmlrpcerr['introspect_unknown'] = '4'; + $this->xmlrpcstr['introspect_unknown'] = "Cannot inspect signature for request: method unknown"; + $this->xmlrpcerr['http_error'] = '5'; + $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 + //------------------------------------- + + function initialize($config = array()) + { + if (sizeof($config) > 0) + { + foreach ($config as $key => $val) + { + if (isset($this->$key)) + { + $this->$key = $val; + } + } + } + } + // END + + //------------------------------------- + // Take URL and parse it + //------------------------------------- + + function server($url, $port=80) + { + if (substr($url, 0, 4) != "http") + { + $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 + //------------------------------------- + + function timeout($seconds=5) + { + if ( ! is_null($this->client) && is_int($seconds)) + { + $this->client->timeout = $seconds; + } + } + // END + + //------------------------------------- + // Set Methods + //------------------------------------- + + function method($function) + { + $this->method = $function; + } + // END + + //------------------------------------- + // Take Array of Data and Create Objects + //------------------------------------- + + function request($incoming) + { + if ( ! is_array($incoming)) + { + // Send Error + } + + foreach($incoming as $key => $value) + { + $this->data[$key] = $this->values_parsing($value); + } + } + // END + + + //------------------------------------- + // Set Debug + //------------------------------------- + + function set_debug($flag = TRUE) + { + $this->debug = ($flag == TRUE) ? TRUE : FALSE; + } + + //------------------------------------- + // Values Parsing + //------------------------------------- + + function values_parsing($value, $return = FALSE) + { + if (is_array($value) && isset($value['0'])) + { + if ( ! isset($value['1']) OR ! isset($this->xmlrpcTypes[strtolower($value['1'])])) + { + $temp = new XML_RPC_Values($value['0'], 'string'); + } + elseif(is_array($value['0']) && ($value['1'] == 'struct' OR $value['1'] == 'array')) + { + while (list($k) = each($value['0'])) + { + $value['0'][$k] = $this->values_parsing($value['0'][$k], TRUE); + } + + $temp = new XML_RPC_Values($value['0'], $value['1']); + } + else + { + $temp = new XML_RPC_Values($value['0'], $value['1']); + } + } + else + { + $temp = new XML_RPC_Values($value, 'string'); + } + + return $temp; + } + // END + + + //------------------------------------- + // Sends XML-RPC Request + //------------------------------------- + + function send_request() + { + $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; + return FALSE; + } + elseif( ! is_object($this->result->val)) + { + $this->error = $this->result->errstr; + return FALSE; + } + + $this->response = $this->result->decode(); + + return TRUE; + } + // END + + //------------------------------------- + // Returns Error + //------------------------------------- + + function display_error() + { + return $this->error; + } + // END + + //------------------------------------- + // Returns Remote Server Response + //------------------------------------- + + function display_response() + { + 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 + * + * @category XML-RPC + * @author Paul Burdick + * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html + */ +class XML_RPC_Client extends CI_XML_RPC +{ + var $path = ''; + var $server = ''; + var $port = 80; + var $errno = ''; + var $errstring = ''; + var $timeout = 5; + var $no_multicall = false; + + function XML_RPC_Client($path, $server, $port=80) + { + parent::CI_XML_RPC(); + + $this->port = $port; + $this->server = $server; + $this->path = $path; + } + + function send($msg) + { + if (is_array($msg)) + { + // Multi-call disabled + $r = new XML_RPC_Response(0, $this->xmlrpcerr['multicall_recursion'],$this->xmlrpcstr['multicall_recursion']); + return $r; + } + + return $this->sendPayload($msg); + } + + 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"; + $op .= "Content-Type: text/xml$r"; + $op .= "User-Agent: {$this->xmlrpcName}$r"; + $op .= "Content-Length: ".strlen($msg->payload). "$r$r"; + $op .= $msg->payload; + + + if (!fputs($fp, $op, strlen($op))) + { + error_log($this->xmlrpcstr['http_error']); + $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']); + return $r; + } + $resp = $msg->parseResponse($fp); + fclose($fp); + return $resp; + } + +} // end class XML_RPC_Client + + +/** + * XML-RPC Response class + * + * @category XML-RPC + * @author Paul Burdick + * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html + */ +class XML_RPC_Response +{ + var $val = 0; + var $errno = 0; + var $errstr = ''; + var $headers = array(); + + function XML_RPC_Response($val, $code = 0, $fstr = '') + { + if ($code != 0) + { + // error + $this->errno = $code; + $this->errstr = htmlentities($fstr); + } + else if (!is_object($val)) + { + // programmer error, not an object + error_log("Invalid type '" . gettype($val) . "' (value: $val) passed to XML_RPC_Response. Defaulting to empty value."); + $this->val = new XML_RPC_Values(); + } + else + { + $this->val = $val; + } + } + + function faultCode() + { + return $this->errno; + } + + function faultString() + { + return $this->errstr; + } + + function value() + { + return $this->val; + } + + function prepare_response() + { + $result = "\n"; + if ($this->errno) + { + $result .= ' + + + + faultCode + ' . $this->errno . ' + + + faultString + ' . $this->errstr . ' + + + +'; + } + else + { + $result .= "\n\n" . + $this->val->serialize_class() . + "\n"; + } + $result .= "\n"; + return $result; + } + + function decode($array=FALSE) + { + $obj =& get_instance(); + + if ($array !== FALSE && is_array($array)) + { + while (list($key) = each($array)) + { + if (is_array($array[$key])) + { + $array[$key] = $this->decode($array[$key]); + } + else + { + $array[$key] = $obj->input->xss_clean($array[$key]); + } + } + + $result = $array; + } + else + { + $result = $this->xmlrpc_decoder($this->val); + + if (is_array($result)) + { + $result = $this->decode($result); + } + else + { + $result = $obj->input->xss_clean($result); + } + } + + return $result; + } + + + + //------------------------------------- + // XML-RPC Object to PHP Types + //------------------------------------- + + function xmlrpc_decoder($xmlrpc_val) + { + $kind = $xmlrpc_val->kindOf(); + + if($kind == 'scalar') + { + return $xmlrpc_val->scalarval(); + } + elseif($kind == 'array') + { + reset($xmlrpc_val->me); + list($a,$b) = each($xmlrpc_val->me); + $size = sizeof($b); + + $arr = array(); + + for($i = 0; $i < $size; $i++) + { + $arr[] = $this->xmlrpc_decoder($xmlrpc_val->me['array'][$i]); + } + return $arr; + } + elseif($kind == 'struct') + { + reset($xmlrpc_val->me['struct']); + $arr = array(); + + while(list($key,$value) = each($xmlrpc_val->me['struct'])) + { + $arr[$key] = $this->xmlrpc_decoder($value); + } + return $arr; + } + } + + + //------------------------------------- + // ISO-8601 time to server or UTC time + //------------------------------------- + + function iso8601_decode($time, $utc=0) + { + // return a timet in the localtime, or UTC + $t = 0; + if (ereg("([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})", $time, $regs)) + { + if ($utc == 1) + $t = gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); + else + $t = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); + } + return $t; + } + +} // End Response Class + + + +/** + * XML-RPC Message class + * + * @category XML-RPC + * @author Paul Burdick + * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html + */ +class XML_RPC_Message extends CI_XML_RPC +{ + var $payload; + var $method_name; + var $params = array(); + var $xh = array(); + + function XML_RPC_Message($method, $pars=0) + { + parent::CI_XML_RPC(); + + $this->method_name = $method; + if (is_array($pars) && sizeof($pars) > 0) + { + for($i=0; $iparams[] = $pars[$i]; + } + } + } + + //------------------------------------- + // Create Payload to Send + //------------------------------------- + + function createPayload() + { + $this->payload = "\r\n\r\n"; + $this->payload .= '' . $this->method_name . "\r\n"; + $this->payload .= "\r\n"; + + for($i=0; $iparams); $i++) + { + // $p = XML_RPC_Values + $p = $this->params[$i]; + $this->payload .= "\r\n".$p->serialize_class()."\r\n"; + } + + $this->payload .= "\r\n\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 "
";
+			echo "---DATA---\n" . htmlspecialchars($data) . "\n---END DATA---\n\n";
+			echo "
"; + } + + //------------------------------------- + // Check for data + //------------------------------------- + + if($data == "") + { + error_log($this->xmlrpcstr['no_data']); + $r = new XML_RPC_Response(0, $this->xmlrpcerr['no_data'], $this->xmlrpcstr['no_data']); + return $r; + } + + + //------------------------------------- + // Check for HTTP 200 Response + //------------------------------------- + + if(ereg("^HTTP",$data) && !ereg("^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; + + xml_set_object($parser, $this); + xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true); + xml_set_element_handler($parser, 'open_tag', 'closing_tag'); + xml_set_character_data_handler($parser, 'character_data'); + //xml_set_default_handler($parser, 'default_handler'); + + + //------------------------------------- + // GET HEADERS + //------------------------------------- + + $lines = explode("\r\n", $data); + while (($line = array_shift($lines))) + { + if (strlen($line) < 1) + { + break; + } + $this->xh[$parser]['headers'][] = $line; + } + $data = implode("\r\n", $lines); + + + //------------------------------------- + // PARSE XML DATA + //------------------------------------- + + if (!xml_parse($parser, $data, sizeof($data))) + { + $errstr = sprintf('XML error: %s at line %d', + xml_error_string(xml_get_error_code($parser)), + xml_get_current_line_number($parser)); + //error_log($errstr); + $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']); + xml_parser_free($parser); + return $r; + } + xml_parser_free($parser); + + // --------------------------------------- + // Got Ourselves Some Badness, It Seems + // --------------------------------------- + + if ($this->xh[$parser]['isf'] > 1) + { + if ($this->debug === TRUE) + { + echo "---Invalid Return---\n"; + 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; + } + elseif ( ! is_object($this->xh[$parser]['value'])) + { + $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 "
";
+			
+			if (count($this->xh[$parser]['headers'] > 0))
+			{
+				echo "---HEADERS---\n";
+				foreach ($this->xh[$parser]['headers'] as $header)
+				{
+					echo "$header\n";
+				}
+				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---
"; + } + + //------------------------------------- + // SEND RESPONSE + //------------------------------------- + + $v = $this->xh[$parser]['value']; + + if ($this->xh[$parser]['isf']) + { + $errno_v = $v->me['struct']['faultCode']; + $errstr_v = $v->me['struct']['faultString']; + $errno = $errno_v->scalarval(); + + if ($errno == 0) + { + // FAULT returned, errno needs to reflect that + $errno = -1; + } + + $r = new XML_RPC_Response($v, $errno, $errstr_v->scalarval()); + } + else + { + $r = new XML_RPC_Response($v); + } + + $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 + // lv - used to indicate "looking for a value": implements + // the logic to allow values with no types to be strings + // params - used to store parameters in method calls + // method - used to store method name + // stack - array with parent tree of the xml element, + // used to validate the nesting of elements + + //------------------------------------- + // Start Element Handler + //------------------------------------- + + function open_tag($the_parser, $name, $attrs) + { + // 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') + { + $this->xh[$the_parser]['isf'] = 2; + $this->xh[$the_parser]['isf_reason'] = 'Top level XML-RPC element is missing'; + return; + } + } + else + { + // not top level element: see if parent is OK + if (!in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name])) + { + $this->xh[$the_parser]['isf'] = 2; + $this->xh[$the_parser]['isf_reason'] = "XML-RPC element $name cannot be child of ".$this->xh[$the_parser]['stack'][0]; + 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': + case 'NAME': + $this->xh[$the_parser]['ac'] = ''; + break; + case 'FAULT': + $this->xh[$the_parser]['isf'] = 1; + break; + case 'PARAM': + $this->xh[$the_parser]['value'] = null; + break; + case 'VALUE': + $this->xh[$the_parser]['vt'] = 'value'; + $this->xh[$the_parser]['ac'] = ''; + $this->xh[$the_parser]['lv'] = 1; + break; + case 'I4': + case 'INT': + case 'STRING': + case 'BOOLEAN': + case 'DOUBLE': + case 'DATETIME.ISO8601': + case 'BASE64': + if ($this->xh[$the_parser]['vt'] != 'value') + { + //two data elements inside a value: an error occurred! + $this->xh[$the_parser]['isf'] = 2; + $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 to nothing to prevent errors later if no 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; + case 'DATA': + case 'METHODCALL': + case 'METHODRESPONSE': + case 'PARAMS': + // valid elements that add little to processing + break; + default: + /// An Invalid Element is Found, so we have trouble + $this->xh[$the_parser]['isf'] = 2; + $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); + + if ($name != 'VALUE') $this->xh[$the_parser]['lv'] = 0; + } + // END + + + //------------------------------------- + // End Element Handler + //------------------------------------- + + 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': + case 'ARRAY': + $cur_val = array_shift($this->xh[$the_parser]['valuestack']); + $this->xh[$the_parser]['value'] = ( ! isset($cur_val['values'])) ? array() : $cur_val['values']; + $this->xh[$the_parser]['vt'] = strtolower($name); + break; + case 'NAME': + $this->xh[$the_parser]['valuestack'][0]['name'] = $this->xh[$the_parser]['ac']; + break; + case 'BOOLEAN': + case 'I4': + case 'INT': + case 'STRING': + case 'DOUBLE': + 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']; + } + elseif ($name=='DATETIME.ISO8601') + { + $this->xh[$the_parser]['vt'] = $this->xmlrpcDateTime; + $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; + } + elseif ($name=='BASE64') + { + $this->xh[$the_parser]['value'] = base64_decode($this->xh[$the_parser]['ac']); + } + elseif ($name=='BOOLEAN') + { + // Translated BOOLEAN values to TRUE AND FALSE + if ($this->xh[$the_parser]['ac'] == '1') + { + $this->xh[$the_parser]['value'] = TRUE; + } + else + { + $this->xh[$the_parser]['value'] = FALSE; + } + } + elseif ($name=='DOUBLE') + { + // we have a DOUBLE + // we must check that only 0123456789-. are characters here + if (!ereg("^[+-]?[eE0123456789 \\t\\.]+$", $this->xh[$the_parser]['ac'])) + { + $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND'; + } + else + { + $this->xh[$the_parser]['value'] = (double)$this->xh[$the_parser]['ac']; + } + } + else + { + // we have an I4/INT + // we must check that only 0123456789- are characters here + if (!ereg("^[+-]?[0123456789 \\t]+$", $this->xh[$the_parser]['ac'])) + { + $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND'; + } + else + { + $this->xh[$the_parser]['value'] = (int)$this->xh[$the_parser]['ac']; + } + } + $this->xh[$the_parser]['ac'] = ''; + $this->xh[$the_parser]['lv'] = 3; // indicate we've found a value + break; + case 'VALUE': + // This if() detects if no scalar was inside + if ($this->xh[$the_parser]['vt']=='value') + { + $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 + $this->xh[$the_parser]['valuestack'][0]['values'][] = $temp; + } + else + { + // Struct + $this->xh[$the_parser]['value'] = $temp; + } + 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']) + { + $this->xh[$the_parser]['valuestack'][0]['values'][$this->xh[$the_parser]['valuestack'][0]['name']] = $this->xh[$the_parser]['value']; + } + break; + case 'DATA': + $this->xh[$the_parser]['ac']=''; + break; + case 'PARAM': + if ($this->xh[$the_parser]['value']) + { + $this->xh[$the_parser]['params'][] = $this->xh[$the_parser]['value']; + } + break; + case 'METHODNAME': + $this->xh[$the_parser]['method'] = ereg_replace("^[\n\r\t ]+", '', $this->xh[$the_parser]['ac']); + break; + case 'PARAMS': + case 'FAULT': + case 'METHODCALL': + case 'METHORESPONSE': + // We're all good kids with nuthin' to do + break; + default: + // End of an Invalid Element. Taken care of during the opening tag though + break; + } + } + + //------------------------------------- + // Parses Character Data + //------------------------------------- + + 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) + { + if ($this->xh[$the_parser]['lv'] == 1) + { + $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) + { + $obj =& get_instance(); + + if ($array !== FALSE && is_array($array)) + { + while (list($key) = each($array)) + { + if (is_array($array[$key])) + { + $array[$key] = $this->output_parameters($array[$key]); + } + else + { + $array[$key] = $obj->input->xss_clean($array[$key]); + } + } + + $parameters = $array; + } + else + { + $parameters = array(); + + for ($i = 0; $i < sizeof($this->params); $i++) + { + $a_param = $this->decode_message($this->params[$i]); + + if (is_array($a_param)) + { + $parameters[] = $this->output_parameters($a_param); + } + else + { + $parameters[] = $obj->input->xss_clean($a_param); + } + } + } + + return $parameters; + } + + + function decode_message($param) + { + $kind = $param->kindOf(); + + if($kind == 'scalar') + { + return $param->scalarval(); + } + elseif($kind == 'array') + { + reset($param->me); + list($a,$b) = each($param->me); + + $arr = array(); + + for($i = 0; $i < sizeof($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 + + + +/** + * XML-RPC Values class + * + * @category XML-RPC + * @author Paul Burdick + * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html + */ +class XML_RPC_Values extends CI_XML_RPC +{ + var $me = array(); + var $mytype = 0; + + function XML_RPC_Values($val=-1, $type='') + { + parent::CI_XML_RPC(); + + if ($val != -1 || $type != '') + { + $type = $type == '' ? 'string' : $type; + + if ($this->xmlrpcTypes[$type] == 1) + { + $this->addScalar($val,$type); + } + elseif ($this->xmlrpcTypes[$type] == 2) + { + $this->addArray($val); + } + elseif ($this->xmlrpcTypes[$type] == 3) + { + $this->addStruct($val); + } + } + } + + function addScalar($val, $type='string') + { + $typeof = $this->xmlrpcTypes[$type]; + + if ($this->mytype==1) + { + echo 'XML_RPC_Values: scalar can have only one value
'; + return 0; + } + + if ($typeof != 1) + { + echo 'XML_RPC_Values: not a scalar type (${typeof})
'; + return 0; + } + + if ($type == $this->xmlrpcBoolean) + { + if (strcasecmp($val,'true')==0 || $val==1 || ($val==true && strcasecmp($val,'false'))) + { + $val = 1; + } + else + { + $val=0; + } + } + + if ($this->mytype == 2) + { + // adding to an array here + $ar = $this->me['array']; + $ar[] = new XML_RPC_Values($val, $type); + $this->me['array'] = $ar; + } + else + { + // a scalar, so set the value and remember we're scalar + $this->me[$type] = $val; + $this->mytype = $typeof; + } + return 1; + } + + function addArray($vals) + { + if ($this->mytype != 0) + { + echo 'XML_RPC_Values: already initialized as a [' . $this->kindOf() . ']
'; + return 0; + } + + $this->mytype = $this->xmlrpcTypes['array']; + $this->me['array'] = $vals; + return 1; + } + + function addStruct($vals) + { + if ($this->mytype != 0) + { + echo 'XML_RPC_Values: already initialized as a [' . $this->kindOf() . ']
'; + return 0; + } + $this->mytype = $this->xmlrpcTypes['struct']; + $this->me['struct'] = $vals; + return 1; + } + + function kindOf() + { + switch($this->mytype) + { + case 3: + return 'struct'; + break; + case 2: + return 'array'; + break; + case 1: + return 'scalar'; + break; + default: + return 'undef'; + } + } + + function serializedata($typ, $val) + { + $rs = ''; + + switch($this->xmlrpcTypes[$typ]) + { + case 3: + // struct + $rs .= "\n"; + reset($val); + while(list($key2, $val2) = each($val)) + { + $rs .= "\n{$key2}\n"; + $rs .= $this->serializeval($val2); + $rs .= "\n"; + } + $rs .= ''; + break; + case 2: + // array + $rs .= "\n\n"; + for($i=0; $i < sizeof($val); $i++) + { + $rs .= $this->serializeval($val[$i]); + } + $rs.="\n\n"; + break; + case 1: + // others + switch ($typ) + { + case $this->xmlrpcBase64: + $rs .= "<{$typ}>" . base64_encode($val) . "\n"; + break; + case $this->xmlrpcBoolean: + $rs .= "<{$typ}>" . ($val ? '1' : '0') . "\n"; + break; + case $this->xmlrpcString: + $rs .= "<{$typ}>" . htmlspecialchars($val). "\n"; + break; + default: + $rs .= "<{$typ}>{$val}\n"; + break; + } + default: + break; + } + return $rs; + } + + function serialize_class() + { + return $this->serializeval($this); + } + + function serializeval($o) + { + + $ar = $o->me; + reset($ar); + + list($typ, $val) = each($ar); + $rs = "\n".$this->serializedata($typ, $val)."\n"; + return $rs; + } + + function scalarval() + { + reset($this->me); + list($a,$b) = each($this->me); + return $b; + } + + + //------------------------------------- + // 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); + } + else + { + if (function_exists('gmstrftime')) + $t = gmstrftime("%Y%m%dT%H:%M:%S", $time); + else + $t = strftime("%Y%m%dT%H:%M:%S", $time - date('Z')); + } + return $t; + } + +} +// END XML_RPC_Values Class +?> \ No newline at end of file diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php new file mode 100644 index 000000000..eaec87a6d --- /dev/null +++ b/system/libraries/Xmlrpcs.php @@ -0,0 +1,492 @@ +set_system_methods(); + + if (isset($config['functions']) && is_array($config['functions'])) + { + $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 = $config['functions']; + } + + if (isset($config['debug'])) + { + $this->debug = $config['debug']; + } + } + + //------------------------------------- + // Setting of System Methods + //------------------------------------- + + function set_system_methods () + { + $system_methods = array( + 'system.listMethods' => array( + 'function' => 'this.listMethods', + 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString), array($this->xmlrpcArray)), + 'docstring' => 'Returns an array of available methods on this server'), + 'system.methodHelp' => array( + 'function' => 'this.methodHelp', + 'signature' => array(array($this->xmlrpcString, $this->xmlrpcString)), + 'docstring' => 'Returns a documentation string for the specified method'), + 'system.methodSignature' => array( + 'function' => 'this.methodSignature', + 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString)), + 'docstring' => 'Returns an array describing the return type and required parameters of a method'), + 'system.multicall' => array( + 'function' => 'this.multicall', + 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcArray)), + 'docstring' => 'Combine multiple RPC calls in one request. See http://www.xmlrpc.com/discuss/msgReader$1208 for details') + ); + } + + + //------------------------------------- + // Main Server Function + //------------------------------------- + + function serve() + { + $r = $this->parseRequest(); + $payload = 'xmlrpc_defencoding.'"?'.'>'."\n"; + $payload .= $this->debug_msg; + $payload .= $r->prepare_response(); + + header("Content-Type: text/xml"); + header("Content-Length: ".strlen($payload)); + echo $payload; + } + + //------------------------------------- + // Add Method to Class + //------------------------------------- + + function add_to_map($methodname,$function,$sig,$doc) + { + $this->methods[$methodname] = array( + 'function' => $function, + 'signature' => $sig, + 'docstring' => $doc + ); + } + + + //------------------------------------- + // Parse Server Request + //------------------------------------- + + function parseRequest($data='') + { + global $HTTP_RAW_POST_DATA; + + //------------------------------------- + // Get Data + //------------------------------------- + + if ($data == '') + { + $data = $HTTP_RAW_POST_DATA; + } + + + //------------------------------------- + // 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'] = ''; + $parser_object->xh[$parser]['params'] = array(); + $parser_object->xh[$parser]['stack'] = array(); + $parser_object->xh[$parser]['valuestack'] = array(); + $parser_object->xh[$parser]['method'] = ''; + + xml_set_object($parser, $parser_object); + xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true); + 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 + $r = new XML_RPC_Response(0, + $this->xmlrpcerrxml + xml_get_error_code($parser), + sprintf('XML error: %s at line %d', + xml_error_string(xml_get_error_code($parser)), + xml_get_current_line_number($parser))); + xml_parser_free($parser); + } + elseif($parser_object->xh[$parser]['isf']) + { + return new XML_RPC_Response(0, + $this->xmlrpcerr['invalid_return'], + $this->xmlrpcstr['invalid_retrun']); + } + else + { + xml_parser_free($parser); + + $m = new XML_RPC_Message($parser_object->xh[$parser]['method']); + $plist=''; + + for($i=0; $i < sizeof($parser_object->xh[$parser]['params']); $i++) + { + $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 "
";
+				echo "---PLIST---\n" . $plist . "\n---PLIST END---\n\n";
+				echo "
"; + } + + $r = $this->execute($m); + } + + //------------------------------------- + // SET DEBUGGING MESSAGE + //------------------------------------- + + if ($this->debug === TRUE) + { + $this->debug_msg = "\n"; + } + + return $r; + } + + //------------------------------------- + // Executes the Method + //------------------------------------- + + function execute($m) + { + $methName = $m->method_name; + + // Check to see if it is a system call + // If so, load the system_methods + $sysCall = ereg("^system\.", $methName); + $methods = $sysCall ? $this->system_methods : $this->methods; + + //------------------------------------- + // Check for Function + //------------------------------------- + + if (!isset($methods[$methName]['function'])) + { + return new XML_RPC_Response(0, + $this->xmlrpcerr['unknown_method'], + $this->xmlrpcstr['unknown_method']); + } + else + { + // See if we are calling function in an object + + $method_parts = explode(".",$methods[$methName]['function']); + $objectCall = (isset($method_parts['1']) && $method_parts['1'] != "") ? true : false; + + if ($objectCall && !is_callable(array($method_parts['0'],$method_parts['1']))) + { + return new XML_RPC_Response(0, + $this->xmlrpcerr['unknown_method'], + $this->xmlrpcstr['unknown_method']); + } + elseif (!$objectCall && !is_callable($methods[$methName]['function'])) + { + return new XML_RPC_Response(0, + $this->xmlrpcerr['unknown_method'], + $this->xmlrpcstr['unknown_method']); + } + } + + //------------------------------------- + // Checking Methods Signature + //------------------------------------- + + if (isset($methods[$methName]['signature'])) + { + $sig = $methods[$methName]['signature']; + for($i=0; $iparams)+1) + { + for($n=0; $n < sizeof($m->params); $n++) + { + $p = $m->params[$n]; + $pt = ($p->kindOf() == 'scalar') ? $p->scalartyp() : $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'] . + ": Wanted {$wanted}, got {$pt} at param {$pno})"); + } + } + } + } + } + + //------------------------------------- + // Calls the Function + //------------------------------------- + + if ($objectCall) + { + if ($method_parts['1'] == "this") + { + return call_user_func(array($this, $method_parts['0']), $m); + } + else + { + $obj =& get_instance(); + return $obj->$method_parts['1']($m); + //$class = new $method_parts['0']; + //return $class->$method_parts['1']($m); + //return call_user_func(array(&$method_parts['0'],$method_parts['1']), $m); + } + } + else + { + return call_user_func($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'); + } + + $v->addArray($output); + return new XML_RPC_Response($v); + } + + //------------------------------------- + // Server Function: Return Signature for Method + //------------------------------------- + + function methodSignature($m) + { + $methName = $m->getParam(0); + $method_name = $methName->scalarval(); + + $methods = ereg("^system\.", $method_name) ? $this->system_methods : $this->methods; + + if (isset($methods[$method_name])) + { + if ($methods[$method_name]['signature']) + { + $sigs = array(); + $signature = $methods[$method_name]['signature']; + + for($i=0; $i < sizeof($signature); $i++) + { + $cursig = array(); + $inSig = $signature[$i]; + for($j=0; $jxmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); + } + return $r; + } + + //------------------------------------- + // Server Function: Doc String for Method + //------------------------------------- + + function methodHelp($m) + { + $methName = $m->getParam(0); + $method_name = $methName->scalarval(); + + $methods = ereg("^system\.", $method_name) ? $this->system_methods : $this->methods; + + if (isset($methods[$methName])) + { + $docstring = isset($methods[$method_name]['docstring']) ? $methods[$method_name]['docstring'] : ''; + $r = new XML_RPC_Response(new XML_RPC_Values($docstring, 'string')); + } + else + { + $r = new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); + } + return $r; + } + + //------------------------------------- + // Server Function: Multi-call + //------------------------------------- + + function multicall($m) + { + $calls = $m->getParam(0); + list($a,$b)=each($calls->me); + $result = array(); + + for ($i = 0; $i < sizeof($b); $i++) + { + $call = $calls->me['array'][$i]; + $result[$i] = $this->do_multicall($call); + } + + return new XML_RPC_Response(new XML_RPC_Values($result, 'array')); + } + + + //------------------------------------- + // Multi-call Function: Error Handling + //------------------------------------- + + function multicall_error($err) + { + $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' || $scalar_type != 'string') + return $this->multicall_error('notstring'); + elseif ($scalar_value == 'system.multicall') + return $this->multicall_error('recursion'); + elseif (!$params = $call->me['struct']['params']) + return $this->multicall_error('noparams'); + elseif ($params->kindOf() != 'array') + return $this->multicall_error('notarray'); + + list($a,$b)=each($params->me); + $numParams = sizeof($b); + + $msg = new XML_RPC_Message($scalar_value); + for ($i = 0; $i < $numParams; $i++) + { + $msg->params[] = $params->me['array'][$i]; + } + + $result = $this->execute($msg); + + if ($result->faultCode() != 0) + { + return $this->multicall_error($result); + } + + return new XML_RPC_Values(array($result->value()), 'array'); + } + +} +// END XML_RPC_Server class +?> \ No newline at end of file diff --git a/system/libraries/index.html b/system/libraries/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/libraries/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d4e95072203a5cf4f1d50d16fe3e490f275a4307 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 26 Aug 2006 01:15:06 +0000 Subject: --- system/libraries/Router.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index abc253eff..b61dfb79c 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -300,16 +300,27 @@ class CI_Router { } // Loop through the route array looking for wildcards - foreach ($this->routes as $key => $val) + foreach (array_slice($this->routes, 1) as $key => $val) { if (count(explode('/', $key)) != $num) continue; - - if (preg_match("|".str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key))."$|", $uri)) - { + + // Convert wildcards to RegEx + $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); + + // Does the regex match this URI ? + if (preg_match('|^'.$key.'$|', $uri)) + { + // Do we have a replacemnt? + if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) + { + $val = preg_replace('|^'.$key.'$|', $val, $uri); + } + $this->_compile_segments(explode('/', $val), TRUE); break; } + } } // END set_method() -- cgit v1.2.3-24-g4f1b From 45c872b0ac215d590e785fe393241a06facd7e05 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 26 Aug 2006 04:51:38 +0000 Subject: --- system/libraries/Router.php | 211 +++++++++++++++++++++++++++++--------------- 1 file changed, 142 insertions(+), 69 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index b61dfb79c..7839de2d9 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -34,6 +34,7 @@ class CI_Router { var $routes = array(); var $class = ''; var $method = 'index'; + var $directory = ''; var $uri_protocol = 'auto'; var $default_controller; var $scaffolding_request = FALSE; // Must be set to FALSE @@ -121,6 +122,7 @@ class CI_Router { log_message('debug', "No URI present. Default controller set."); return; } + unset($this->routes['default_controller']); // Do we need to remove the suffix specified in the config file? if ($this->config->item('url_suffix') != "") @@ -129,13 +131,20 @@ class CI_Router { } // Explode the URI Segments. The individual segments will - // be stored in the $this->segments array. - $this->_compile_segments(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string))); - - - // Remap the class/method if a route exists - unset($this->routes['default_controller']); + // be stored in the $this->segments array. + $i = 1; + foreach(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val) + { + // Filter segments for security + $val = trim($this->_filter_uri($val)); + + if ($val != '') + $this->segments[$i++] = $val; + } + $this->_compile_segments($this->segments); + + // Do we have any custom routing to deal with? if (count($this->routes) > 0) { $this->_parse_routes(); @@ -157,19 +166,15 @@ class CI_Router { * @param bool * @return void */ - function _compile_segments($segs, $route = FALSE) - { - $segments = array(); - - $i = 1; - foreach($segs as $val) + function _compile_segments($segments = array()) + { + $segments = $this->_validate_segments($segments); + + if (count($segments) == 0) { - $val = trim($this->_filter_uri($val)); - - if ($val != '') - $segments[$i++] = $val; + return; } - + $this->set_class($segments['1']); if (isset($segments['2'])) @@ -186,15 +191,54 @@ class CI_Router { $this->set_method($segments['2']); } } - - if ($route == FALSE) + } + // END _compile_segments() + + // -------------------------------------------------------------------- + + /** + * Validates the supplied segments. Attempts to determine the path to + * the controller. + * + * @access private + * @param array + * @return array + */ + function _validate_segments($segments) + { + // Does the requested controller exist? + if ( ! file_exists(APPPATH.'controllers/'.$segments['1'].EXT)) { - $this->segments = $segments; + // Is it a directory? No? Smite them! + if ( ! is_dir(APPPATH.'controllers/'.$segments['1'])) + { + show_404(); + } + else + { + $this->set_directory($segments['1']); + $segs = array_slice($segments, 1); + + if (count($segs) == 0) + { + $this->set_class($this->default_controller); + $this->set_method('index'); + $this->directory = ''; + return array(); + } + + $i = 1; + $segments = array(); + foreach ($segs as $val) + { + $segments[$i++] = $val; + } + } } - unset($segments); + return $segments; } - // END _compile_segments() + // END _validate_segments() // -------------------------------------------------------------------- @@ -218,6 +262,56 @@ class CI_Router { // -------------------------------------------------------------------- + /** + * Parse Routes + * + * This function matches any routes that may exist in + * the config/routes.php file against the URI to + * determine if the class/method need to be remapped. + * + * @access private + * @return void + */ + function _parse_routes() + { + // Turn the segment array into a URI string + $uri = implode('/', $this->segments); + $num = count($this->segments); + + // Is there a literal match? If so we're done + if (isset($this->routes[$uri])) + { + $this->_compile_segments(explode('/', $this->routes[$uri])); + return; + } + + // Loop through the route array looking for wildcards + foreach (array_slice($this->routes, 1) as $key => $val) + { + if (count(explode('/', $key)) != $num) + continue; + + // Convert wildcards to RegEx + $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); + + // Does the RegEx match? + if (preg_match('|^'.$key.'$|', $uri)) + { + // Do we have a back-reference? + if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) + { + $val = preg_replace('|^'.$key.'$|', $val, $uri); + } + + $this->_compile_segments(explode('/', $val)); + return; + } + } + } + // END set_method() + + // -------------------------------------------------------------------- + /** * Set the class name * @@ -229,7 +323,7 @@ class CI_Router { { $this->class = $class; } - // END _filter_uri() + // END set_class() // -------------------------------------------------------------------- @@ -243,7 +337,7 @@ class CI_Router { { return $this->class; } - // END _filter_uri() + // END fetch_class() // -------------------------------------------------------------------- @@ -259,7 +353,7 @@ class CI_Router { $this->method = $method; } // END set_method() - + // -------------------------------------------------------------------- /** @@ -272,58 +366,37 @@ class CI_Router { { return $this->method; } - // END set_method() - + // END fetch_method() + // -------------------------------------------------------------------- /** - * Parse Routes + * Set the directory name * - * This function matches any routes that may exist in - * the config/routes.php file against the URI to - * determine if the class/method need to be remapped. - * - * @access private + * @access public + * @param string * @return void - */ - function _parse_routes() + */ + function set_directory($dir) { - // Turn the segment array into a URI string - $uri = implode('/', $this->segments); - $num = count($this->segments); + $this->directory = $dir.'/'; + } + // END set_directory() - // Is there a literal match? If so we're done - if (isset($this->routes[$uri])) - { - $this->_compile_segments(explode('/', $this->routes[$uri]), TRUE); - return; - } - - // Loop through the route array looking for wildcards - foreach (array_slice($this->routes, 1) as $key => $val) - { - if (count(explode('/', $key)) != $num) - continue; - - // Convert wildcards to RegEx - $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); - - // Does the regex match this URI ? - if (preg_match('|^'.$key.'$|', $uri)) - { - // Do we have a replacemnt? - if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) - { - $val = preg_replace('|^'.$key.'$|', $val, $uri); - } - - $this->_compile_segments(explode('/', $val), TRUE); - break; - } - - } + // -------------------------------------------------------------------- + + /** + * Fetch the sub-directory (if any) that contains the requested controller class + * + * @access public + * @return string + */ + function fetch_directory() + { + return $this->directory; } - // END set_method() + // END fetch_directory() + } // END Router Class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From e07fbb376a741e21e69a182eada322c4d3b7e62e Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 26 Aug 2006 17:11:01 +0000 Subject: --- system/libraries/Router.php | 84 +++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 38 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 7839de2d9..678145458 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -132,23 +132,25 @@ class CI_Router { // Explode the URI Segments. The individual segments will // be stored in the $this->segments array. - $i = 1; foreach(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val) { // Filter segments for security $val = trim($this->_filter_uri($val)); if ($val != '') - $this->segments[$i++] = $val; + $this->segments[] = $val; } - $this->_compile_segments($this->segments); + // Parse any custom routing that may exist + $this->_parse_routes(); - // Do we have any custom routing to deal with? - if (count($this->routes) > 0) + // Re-index the segment array so that it starts with 1 rather than 0 + $i = 1; + foreach ($this->segments as $val) { - $this->_parse_routes(); + $this->segments[$i++] = $val; } + unset($this->segments['0']); } // END _set_route_mapping() @@ -175,12 +177,12 @@ class CI_Router { return; } - $this->set_class($segments['1']); + $this->set_class($segments['0']); - if (isset($segments['2'])) + if (isset($segments['1'])) { // A scaffolding request. No funny business with the URL - if ($this->routes['scaffolding_trigger'] == $segments['2'] AND $segments['2'] != '_ci_scaffolding') + if ($this->routes['scaffolding_trigger'] == $segments['1'] AND $segments['1'] != '_ci_scaffolding') { $this->scaffolding_request = TRUE; unset($this->routes['scaffolding_trigger']); @@ -188,7 +190,7 @@ class CI_Router { else { // A standard method request - $this->set_method($segments['2']); + $this->set_method($segments['1']); } } } @@ -206,37 +208,32 @@ class CI_Router { */ function _validate_segments($segments) { - // Does the requested controller exist? - if ( ! file_exists(APPPATH.'controllers/'.$segments['1'].EXT)) + // Does the requested controller exist in the root folder? + if (file_exists(APPPATH.'controllers/'.$segments['0'].EXT)) { - // Is it a directory? No? Smite them! - if ( ! is_dir(APPPATH.'controllers/'.$segments['1'])) + 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) { - show_404(); + $this->set_class($this->default_controller); + $this->set_method('index'); + $this->directory = ''; + return array(); } - else - { - $this->set_directory($segments['1']); - $segs = array_slice($segments, 1); - if (count($segs) == 0) - { - $this->set_class($this->default_controller); - $this->set_method('index'); - $this->directory = ''; - return array(); - } - - $i = 1; - $segments = array(); - foreach ($segs as $val) - { - $segments[$i++] = $val; - } - } + return $segments; } - - return $segments; + + // Can't find the requested controller... + show_404(); } // END _validate_segments() @@ -274,6 +271,13 @@ class CI_Router { */ function _parse_routes() { + // Do we even have any custom routing to deal with? + if (count($this->routes) == 0) + { + $this->_compile_segments($this->segments); + return; + } + // Turn the segment array into a URI string $uri = implode('/', $this->segments); $num = count($this->segments); @@ -284,7 +288,7 @@ class CI_Router { $this->_compile_segments(explode('/', $this->routes[$uri])); return; } - + // Loop through the route array looking for wildcards foreach (array_slice($this->routes, 1) as $key => $val) { @@ -306,7 +310,11 @@ class CI_Router { $this->_compile_segments(explode('/', $val)); return; } - } + } + + // If we got this far it means we didn't encounter a + // matching route so we'll set the site default route + $this->_compile_segments($this->segments); } // END set_method() -- cgit v1.2.3-24-g4f1b From b071bb5a92aade551345a495fb13f5678f3978d0 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 26 Aug 2006 19:28:37 +0000 Subject: --- system/libraries/Calendar.php | 2 +- system/libraries/Loader.php | 2 +- system/libraries/Router.php | 45 +++++++++++++++++++++++-------------------- system/libraries/URI.php | 14 +++++++------- 4 files changed, 33 insertions(+), 30 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 013f06796..b77dd1b6f 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -263,7 +263,7 @@ class CI_Calendar { } else { - $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_novermber', '12' => 'cal_december'); + $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]; diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index e2467fa64..3d2501fc0 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -478,7 +478,7 @@ class CI_Loader { if ($path == '') { $ext = pathinfo($view, PATHINFO_EXTENSION); - $file = ($ext == '') ? $view.EXT : $view; + $file = ($ext != EXT) ? $view.EXT : $view; $path = $this->view_path.$file; } else diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 678145458..b28ead953 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -87,25 +87,31 @@ class CI_Router { // Fetch the URI string Depending on the server, // the URI will be available in one of two globals - switch ($this->config->item('uri_protocol')) + if ($this->config->item('uri_protocol') == 'auto') { - case 'path_info' : $this->uri_string = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); - break; - case 'query_string' : $this->uri_string = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); - break; - default : - $path_info = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); - - if ($path_info != '' AND $path_info != "/".SELF) - { - $this->uri_string = $path_info; - } - else - { - $this->uri_string = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); - } - break; + $path_info = getenv('PATH_INFO'); + if ($path_info != '' AND $path_info != "/".SELF) + { + $this->uri_string = $path_info; + } + else + { + $path_info = getenv('ORIG_PATH_INFO'); + if ($path_info != '' AND $path_info != "/".SELF) + { + $this->uri_string = $path_info; + } + else + { + $this->uri_string = getenv('QUERY_STRING'); + } + } + } + else + { + $this->uri_string = getenv(strtoupper($this->config->item('uri_protocol'))); } + // Is there a URI string? If not, the default controller specified // by the admin in the "routes" file will be shown. @@ -291,10 +297,7 @@ class CI_Router { // Loop through the route array looking for wildcards foreach (array_slice($this->routes, 1) as $key => $val) - { - if (count(explode('/', $key)) != $num) - continue; - + { // Convert wildcards to RegEx $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 4c2fa9c7f..c5fd4625b 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -28,7 +28,7 @@ */ class CI_URI { - var $uri; + var $router; var $keyval = array(); /** @@ -42,7 +42,7 @@ class CI_URI { */ function CI_URI() { - $this->uri =& _load_class('CI_Router'); + $this->router =& _load_class('CI_Router'); log_message('debug', "URI Class Initialized"); } @@ -60,7 +60,7 @@ class CI_URI { */ function segment($n, $no_result = FALSE) { - return ( ! isset($this->uri->segments[$n])) ? $no_result : $this->uri->segments[$n]; + return ( ! isset($this->router->segments[$n])) ? $no_result : $this->router->segments[$n]; } // -------------------------------------------------------------------- @@ -196,7 +196,7 @@ class CI_URI { $leading = '/'; $trailing = '/'; } - return ( ! isset($this->uri->segments[$n])) ? '' : $leading.$this->uri->segments[$n].$trailing; + return ( ! isset($this->router->segments[$n])) ? '' : $leading.$this->router->segments[$n].$trailing; } // -------------------------------------------------------------------- @@ -209,7 +209,7 @@ class CI_URI { */ function segment_array() { - return $this->uri->segments; + return $this->router->segments; } // -------------------------------------------------------------------- @@ -222,7 +222,7 @@ class CI_URI { */ function total_segments() { - return count($this->uri->segments); + return count($this->router->segments); } // -------------------------------------------------------------------- @@ -235,7 +235,7 @@ class CI_URI { */ function uri_string() { - return $this->uri->uri_string; + return $this->router->uri_string; } } -- cgit v1.2.3-24-g4f1b From 141808ad31d4eefad4c6c3dbaf8306fac2342668 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 27 Aug 2006 01:52:51 +0000 Subject: --- system/libraries/Encrypt.php | 2 +- system/libraries/Language.php | 2 +- system/libraries/Log.php | 2 +- system/libraries/Validation.php | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 532bfe1f1..bcffdf1ab 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -322,7 +322,7 @@ class CI_Encrypt { */ function set_hash($type = 'sha1') { - $this->_hash_type = ($type != 'sha1' OR $type != 'md5') ? 'sha1' : $type; + $this->_hash_type = ($type != 'sha1' AND $type != 'md5') ? 'sha1' : $type; } // END set_hash() diff --git a/system/libraries/Language.php b/system/libraries/Language.php index b668aa060..328d53e46 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -68,7 +68,7 @@ class CI_Language { if ( ! file_exists(BASEPATH.'language/'.$idiom.'/'.$langfile)) { - show_error('Unable to load the requested language file: language/'.$langfile.EXT); + show_error('Unable to load the requested language file: language/'.$langfile); } include_once(BASEPATH.'language/'.$idiom.'/'.$langfile); diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 35e30b64c..17b96b2c2 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -88,7 +88,7 @@ class CI_Log { return FALSE; } - $filepath = $this->log_path.'log-'.date('Y-m-d').'.php'; + $filepath = $this->log_path.'log-'.date('Y-m-d').EXT; $message = ''; if ( ! file_exists($filepath)) diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index df8c70ee8..e037e69c5 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -252,12 +252,12 @@ class CI_Validation { // Strip the parameter (if exists) from the rule // Rules can contain a parameter: max_length[5] $param = FALSE; - if (preg_match("/.*?(\[.*?\]).*/", $rule, $match)) + if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match)) { - $param = substr(substr($match['1'], 1), 0, -1); - $rule = str_replace($match['1'], '', $rule); + $rule = $match[1]; + $param = $match[2]; } - + // Call the function that corresponds to the rule if ($callback === TRUE) { -- cgit v1.2.3-24-g4f1b From 57b3d39cb79bb3b8d193e0e345a62e3396e519f2 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 27 Aug 2006 15:28:31 +0000 Subject: --- system/libraries/Log.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 17b96b2c2..de5a9b836 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -40,7 +40,7 @@ class CI_Log { * @param string the error threshold * @param string the date formatting codes */ - function CI_Log($path = '', $threshold = '', $date_fmt = '') + function CI_Log($path = '', $threshold = 4, $date_fmt = '') { $this->log_path = ($path != '') ? $path : BASEPATH.'logs/'; -- cgit v1.2.3-24-g4f1b From b4473d4407311cc5e4b2306cf5fa51221d5826f8 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 27 Aug 2006 15:46:31 +0000 Subject: --- system/libraries/Controller.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index ec21f8d66..06e54b2d1 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -127,7 +127,12 @@ class Controller extends CI_Base { { $name = $model; } - + + if (in_array($name, $this->_ci_models)) + { + return; + } + if (isset($this->$name)) { show_error('The model name you are loading is the name of a resource that is already being used: '.$name); -- cgit v1.2.3-24-g4f1b From 0d29605b1e774efd57ffd8f5ccc8eaec1e9ca576 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 27 Aug 2006 15:48:38 +0000 Subject: --- system/libraries/Controller.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 06e54b2d1..768b154e8 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -128,7 +128,8 @@ class Controller extends CI_Base { $name = $model; } - if (in_array($name, $this->_ci_models)) + $obj =& get_instance(); + if (in_array($name, $obj->_ci_models)) { return; } -- cgit v1.2.3-24-g4f1b From 1082bddc0c065895a3b39607cb930f5a101f54fb Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 27 Aug 2006 19:32:02 +0000 Subject: --- system/libraries/Config.php | 5 +++-- system/libraries/Router.php | 14 ++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Config.php b/system/libraries/Config.php index 85b295796..bd138331f 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -53,7 +53,7 @@ class CI_Config { * * @access public * @param string the config file name - * @return void + * @return boolean if the file was loaded correctly */ function load($file = '') { @@ -61,7 +61,7 @@ class CI_Config { if (in_array($file, $this->is_loaded)) { - return; + return TRUE; } include_once(APPPATH.'config/'.$file.EXT); @@ -77,6 +77,7 @@ class CI_Config { unset($config); log_message('debug', 'Config file loaded: config/'.$file.EXT); + return TRUE; } // END load() diff --git a/system/libraries/Router.php b/system/libraries/Router.php index b28ead953..2219f5739 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -254,12 +254,14 @@ class CI_Router { */ function _filter_uri($str) { - if ( ! preg_match("/^[a-z0-9~\s\%\.:_-]+$/i", $str)) - { - exit('The URI you submitted has disallowed characters: '.$str); - } - - return $str; + if ($this->config->item('permitted_uri_chars') != '') + { + if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) + { + exit('The URI you submitted has disallowed characters: '.$str); + } + } + return $str; } // END _filter_uri() -- cgit v1.2.3-24-g4f1b From 671dc754ef954eecf4c2e8301dde5b3aba6bfedc Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 2 Sep 2006 02:36:03 +0000 Subject: --- system/libraries/Config.php | 99 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 86 insertions(+), 13 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Config.php b/system/libraries/Config.php index bd138331f..f7f813f86 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -36,8 +36,12 @@ class CI_Config { * * Sets the $config data from the primary config.php file as a class variable * - * @access public - */ + * @access public + * @param string the config file name + * @param boolean if configuration values should be loaded into their own section + * @param boolean true if errors should just return false, false if an error message should be displayed + * @return boolean if the file was successfully loaded or not + */ function CI_Config() { $this->config =& _get_config(); @@ -55,7 +59,7 @@ class CI_Config { * @param string the config file name * @return boolean if the file was loaded correctly */ - function load($file = '') + function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) { $file = ($file == '') ? 'config' : str_replace(EXT, '', $file); @@ -63,15 +67,42 @@ class CI_Config { { return TRUE; } + + if ( ! file_exists(APPPATH.'config/'.$file.EXT)) + { + if ($fail_gracefully === TRUE) + { + return FALSE; + } + show_error('The configuration file '.$file.EXT.' does not exist.'); + } include_once(APPPATH.'config/'.$file.EXT); if ( ! isset($config) OR ! is_array($config)) { + if ($fail_gracefully === TRUE) + { + return FALSE; + } show_error('Your '.$file.EXT.' file does not appear to contain a valid configuration array.'); } - $this->config = array_merge($this->config, $config); + if ($use_sections === TRUE) + { + if (isset($this->config[$file])) + { + $this->config[$file] = array_merge($this->config[$file], $config); + } + else + { + $this->config[$file] = $config; + } + } + else + { + $this->config = array_merge($this->config, $config); + } $this->is_loaded[] = $file; unset($config); @@ -86,6 +117,48 @@ class CI_Config { /** * Fetch a config file item * + * + * @access public + * @param string the config item name + * @param string the index name + * @param bool + * @return string + */ + function item($item, $index = '') + { + if ($index == '') + { + if ( ! isset($this->config[$item])) + { + return FALSE; + } + + $pref = $this->config[$item]; + } + else + { + if ( ! isset($this->config[$index])) + { + return FALSE; + } + + if ( ! isset($this->config[$index][$item])) + { + return FALSE; + } + + $pref = $this->config[$index][$item]; + } + + return $pref; + } + // END item() + + // -------------------------------------------------------------------- + + /** + * Fetch a config file item - adds slash after item + * * The second parameter allows a slash to be added to the end of * the item, in the case of a path. * @@ -94,7 +167,7 @@ class CI_Config { * @param bool * @return string */ - function item($item, $slash = FALSE) + function slash_item($item) { if ( ! isset($this->config[$item])) { @@ -103,20 +176,20 @@ class CI_Config { $pref = $this->config[$item]; - if ($pref == '') - { - return $pref; + if ($pref != '') + { + if (ereg("/$", $pref) === FALSE) + { + $pref .= '/'; + } } - - if ($slash !== FALSE AND ereg("/$", $pref) === FALSE) - { - $pref .= '/'; - } return $pref; } // END item() + + // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From eb6db84333c40ed8d15dec5014564120ee0c60e6 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 2 Sep 2006 02:39:45 +0000 Subject: --- system/libraries/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index e037e69c5..30faa85ed 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -208,7 +208,7 @@ class CI_Validation { { if (in_array('isset', $ex) OR in_array('required', $ex)) { - if ( ! isset($this->messages['isset'])) + if ( ! isset($this->_error_messages['isset'])) { if (FALSE === ($line = $this->obj->lang->line('isset'))) { -- cgit v1.2.3-24-g4f1b From 2ed76d5ac89ec7869dcb64c050360fb2f99e9326 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 2 Sep 2006 17:34:52 +0000 Subject: --- system/libraries/Output.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Output.php b/system/libraries/Output.php index f5db3e0d0..73f03863e 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -147,7 +147,7 @@ class CI_Output { return; } - $uri = $obj->config->item('base_url', 1). + $uri = $obj->config->slash_item('base_url'). $obj->config->item('index_page'). $obj->uri->uri_string(); -- cgit v1.2.3-24-g4f1b From 337b270b6e566e81d3ee3b5575a3f274c000b459 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 2 Sep 2006 17:43:16 +0000 Subject: --- system/libraries/Loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 3d2501fc0..f005adcf0 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -478,7 +478,7 @@ class CI_Loader { if ($path == '') { $ext = pathinfo($view, PATHINFO_EXTENSION); - $file = ($ext != EXT) ? $view.EXT : $view; + $file = ($ext != '') ? $view.EXT : $view; $path = $this->view_path.$file; } else -- cgit v1.2.3-24-g4f1b From 6ac4bea2da9e64fb0b434f52177353f6bd65b8e6 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 2 Sep 2006 17:46:15 +0000 Subject: --- system/libraries/Loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index f005adcf0..e2467fa64 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -478,7 +478,7 @@ class CI_Loader { if ($path == '') { $ext = pathinfo($view, PATHINFO_EXTENSION); - $file = ($ext != '') ? $view.EXT : $view; + $file = ($ext == '') ? $view.EXT : $view; $path = $this->view_path.$file; } else -- cgit v1.2.3-24-g4f1b From 1cf89aab5fff8c8068cbf0ed18038b6e4fd4f605 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 3 Sep 2006 18:24:39 +0000 Subject: --- system/libraries/Email.php | 4 ++-- system/libraries/Image_lib.php | 2 +- system/libraries/Log.php | 6 +++--- system/libraries/Output.php | 2 +- system/libraries/Pagination.php | 2 +- system/libraries/Router.php | 14 +++++++++++--- system/libraries/Session.php | 2 +- system/libraries/Trackback.php | 4 ++-- system/libraries/URI.php | 4 ++-- system/libraries/Validation.php | 8 ++++---- 10 files changed, 28 insertions(+), 20 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 96dc0014d..abc77a54d 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -275,7 +275,7 @@ class CI_Email { */ function bcc($bcc, $limit = '') { - if ($limit != '' && ctype_digit($limit)) + if ($limit != '' && is_numeric($limit)) { $this->bcc_batch_mode = true; $this->bcc_batch_size = $limit; @@ -475,7 +475,7 @@ class CI_Email { */ function set_priority($n = 3) { - if ( ! ctype_digit($n)) + if ( ! is_numeric($n)) { $this->priority = 3; return; diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 854f0484b..18e3253f7 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -291,7 +291,7 @@ class CI_Image_lib { // Set the quality $this->quality = trim(str_replace("%", "", $this->quality)); - if ($this->quality == '' OR $this->quality == 0 OR ! ctype_digit($this->quality)) + if ($this->quality == '' OR $this->quality == 0 OR ! is_numeric($this->quality)) $this->quality = 90; // Set the x/y coordinates diff --git a/system/libraries/Log.php b/system/libraries/Log.php index de5a9b836..6c78316f1 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -43,13 +43,13 @@ class CI_Log { function CI_Log($path = '', $threshold = 4, $date_fmt = '') { $this->log_path = ($path != '') ? $path : BASEPATH.'logs/'; - + if ( ! is_dir($this->log_path) OR ! is_writable($this->log_path)) { $this->_enabled = FALSE; } - if (ctype_digit($threshold)) + if (is_numeric($threshold)) { $this->_threshold = $threshold; } @@ -77,7 +77,7 @@ class CI_Log { function write_log($level = 'error', $msg, $php_error = FALSE) { if ($this->_enabled === FALSE) - { + { return FALSE; } diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 73f03863e..7a03cf9c7 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -78,7 +78,7 @@ class CI_Output { */ function cache($time) { - $this->cache_expiration = ( ! ctype_digit($time)) ? 0 : $time; + $this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time; } // -------------------------------------------------------------------- diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 0bbb577a3..9d558f00a 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -128,7 +128,7 @@ class CI_Pagination { $this->cur_page = $obj->uri->segment($this->uri_segment); } - if ( ! ctype_digit($this->cur_page)) + if ( ! is_numeric($this->cur_page)) { $this->cur_page = 0; } diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 2219f5739..1c67113f6 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -219,15 +219,23 @@ class CI_Router { { 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) + 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(); + } + } + else { $this->set_class($this->default_controller); $this->set_method('index'); diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 4f08cf692..94efee55c 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -99,7 +99,7 @@ class CI_Session { */ $expiration = $this->object->config->item('sess_expiration'); - if (ctype_digit($expiration)) + if (is_numeric($expiration)) { if ($expiration > 0) { diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index 583c6d28d..8f9680d44 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -368,7 +368,7 @@ class CI_Trackback { $tb_array = explode('/', $url); $tb_end = $tb_array[count($tb_array)-1]; - if ( ! ctype_digit($tb_end)) + if ( ! is_numeric($tb_end)) { $tb_end = $tb_array[count($tb_array)-2]; } @@ -386,7 +386,7 @@ class CI_Trackback { $tb_array = explode('/', $url); $tb_id = $tb_array[count($tb_array)-1]; - if ( ! ctype_digit($tb_id)) + if ( ! is_numeric($tb_id)) { $tb_id = $tb_array[count($tb_array)-2]; } diff --git a/system/libraries/URI.php b/system/libraries/URI.php index c5fd4625b..ba6279e88 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -88,7 +88,7 @@ class CI_URI { */ function uri_to_assoc($n = 3, $default = array()) { - if ( ! ctype_digit($n)) + if ( ! is_numeric($n)) { return $default; } @@ -110,7 +110,7 @@ class CI_URI { { $retval[$val] = FALSE; } - return $default; + return $retval; } $segments = array_slice($this->segment_array(), ($n - 1)); diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 30faa85ed..44f49ff62 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -404,7 +404,7 @@ class CI_Validation { */ function min_length($str, $val) { - if ( ! ctype_digit($val)) + if ( ! is_numeric($val)) { return FALSE; } @@ -423,7 +423,7 @@ class CI_Validation { */ function max_length($str, $val) { - if ( ! ctype_digit($val)) + if ( ! is_numeric($val)) { return FALSE; } @@ -442,7 +442,7 @@ class CI_Validation { */ function exact_length($str, $val) { - if ( ! ctype_digit($val)) + if ( ! is_numeric($val)) { return FALSE; } @@ -517,7 +517,7 @@ class CI_Validation { */ function numeric($str) { - return ( ! ctype_digit($str)) ? FALSE : TRUE; + return ( ! is_numeric($str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 6cd2ee9a7aa926b607922d933abc3f21b9e3868e Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 4 Sep 2006 07:11:16 +0000 Subject: --- system/libraries/Config.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Config.php b/system/libraries/Config.php index f7f813f86..532f70d42 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -208,12 +208,12 @@ class CI_Config { if ($uri == '') { - return $this->item('base_url', 1).$this->item('index_page'); + return $this->slash_item('base_url').$this->item('index_page'); } else { $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix'); - return $this->item('base_url', 1).$this->item('index_page', 1).preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix; + return $this->slash_item('base_url').$this->slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix; } } // END site_url() -- cgit v1.2.3-24-g4f1b From 813711e6ddfa347fd0d74c109c14fe10a919f668 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 4 Sep 2006 07:13:57 +0000 Subject: --- system/libraries/Config.php | 2 +- system/libraries/Router.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Config.php b/system/libraries/Config.php index 532f70d42..108c94ab7 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -229,7 +229,7 @@ class CI_Config { function system_url() { $x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH)); - return $this->item('base_url', 1).end($x).'/'; + return $this->slash_item('base_url').end($x).'/'; } // END system_url() diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 1c67113f6..c7e855a78 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -312,12 +312,12 @@ class CI_Router { $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); // Does the RegEx match? - if (preg_match('|^'.$key.'$|', $uri)) + if (preg_match('#^'.preg_quote($key).'$#', $uri)) { // Do we have a back-reference? if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) { - $val = preg_replace('|^'.$key.'$|', $val, $uri); + $val = preg_replace('#^'.preg_quote($key).'$#', $val, $uri); } $this->_compile_segments(explode('/', $val)); -- cgit v1.2.3-24-g4f1b From 27818494dca469e96709fd9c54ba8f8461d88714 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 5 Sep 2006 03:31:28 +0000 Subject: --- system/libraries/Router.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index c7e855a78..de1a6e9a8 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -239,8 +239,14 @@ class CI_Router { { $this->set_class($this->default_controller); $this->set_method('index'); - $this->directory = ''; - return array(); + + // 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; -- cgit v1.2.3-24-g4f1b From 2e5872ac0527c342e066bdc2e8facf452858dd39 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 6 Sep 2006 02:32:55 +0000 Subject: --- system/libraries/Loader.php | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index e2467fa64..a140fb5a2 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -565,15 +565,7 @@ class CI_Loader { { if (isset($autoload[$type])) { - if ( ! is_array($autoload[$type])) - { - $autoload[$type] = array($autoload[$type]); - } - - foreach ($autoload[$type] as $item) - { - $this->$type($item); - } + $this->$type($autoload[$type]); } } } @@ -592,20 +584,9 @@ class CI_Loader { */ function _ci_object_to_array($object) { - if ( ! is_object($object)) - { - return $object; - } - - $array = array(); - foreach (get_object_vars($object) as $key => $val) - { - $array[$key] = $val; - } - - return $array; + return (is_object($object)) ? get_object_vars($object) : $object; } + // END _ci_object_to_array() } -// END Loader Class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 764672b45108814fc643be65b53b18f0b6507112 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 15 Sep 2006 20:02:05 +0000 Subject: --- system/libraries/Hooks.php | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index 389e7ac14..7ff0592ff 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -66,34 +66,6 @@ class CI_Hooks { } // END CI_Hooks() - // -------------------------------------------------------------------- - - /** - * Does a given hook exist? - * - * Returns TRUE/FALSE based on whether a given hook exists - * - * @access private - * @param string - * @return bool - */ - function _hook_exists($which = '') - { - if ( ! $this->enabled) - { - return FALSE; - } - - if ( ! isset($this->hooks[$which])) - { - return FALSE; - } - - return TRUE; - } - // END hook_exists() - - // -------------------------------------------------------------------- /** @@ -107,6 +79,11 @@ class CI_Hooks { */ function _call_hook($which = '') { + if ( ! $this->enabled OR ! isset($this->hooks[$which])) + { + return FALSE; + } + if (isset($this->hooks[$which][0]) AND is_array($this->hooks[$which][0])) { foreach ($this->hooks[$which] as $val) @@ -118,6 +95,8 @@ class CI_Hooks { { $this->_run_hook($this->hooks[$which]); } + + return TRUE; } // END hook_exists() @@ -144,7 +123,7 @@ class CI_Hooks { // ----------------------------------- // If the script being called happens to have the same - // extension call within it a loop can happen + // hook call within it a loop can happen if ($this->in_progress == TRUE) { -- cgit v1.2.3-24-g4f1b From 71430b4c30f01c861abe379becc670748e3b4a19 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 15 Sep 2006 20:29:25 +0000 Subject: --- system/libraries/Router.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index de1a6e9a8..1dd1e5426 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -318,12 +318,12 @@ class CI_Router { $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); // Does the RegEx match? - if (preg_match('#^'.preg_quote($key).'$#', $uri)) + if (preg_match('#^'.$key.'$#', $uri)) { // Do we have a back-reference? if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) { - $val = preg_replace('#^'.preg_quote($key).'$#', $val, $uri); + $val = preg_replace('#^'.$key.'$#', $val, $uri); } $this->_compile_segments(explode('/', $val)); -- cgit v1.2.3-24-g4f1b From 633ec3758910482863299c7122dda3c15d9758a8 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 15 Sep 2006 20:43:32 +0000 Subject: --- system/libraries/Log.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 6c78316f1..392742584 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -40,23 +40,25 @@ class CI_Log { * @param string the error threshold * @param string the date formatting codes */ - function CI_Log($path = '', $threshold = 4, $date_fmt = '') - { - $this->log_path = ($path != '') ? $path : BASEPATH.'logs/'; + 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_writable($this->log_path)) { $this->_enabled = FALSE; } - if (is_numeric($threshold)) + if (is_numeric($config['log_threshold'])) { - $this->_threshold = $threshold; + $this->_threshold = $config['log_threshold']; } - if ($date_fmt != '') + if ($config['log_date_format'] != '') { - $this->_date_fmt = $date_fmt; + $this->_date_fmt = $config['log_date_format']; } } // END CI_Log() -- cgit v1.2.3-24-g4f1b From 1856f58a16da54f12414350f2e2a833d0cdd7d45 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 15 Sep 2006 20:48:15 +0000 Subject: --- system/libraries/Output.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 7a03cf9c7..9523599e7 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -147,7 +147,7 @@ class CI_Output { return; } - $uri = $obj->config->slash_item('base_url'). + $uri = $obj->config->item('base_url'). $obj->config->item('index_page'). $obj->uri->uri_string(); @@ -191,8 +191,10 @@ class CI_Output { } // Build the file path. The file name is an MD5 hash of the full URI - $uri = $CFG->item('base_url', 1).$CFG->item('index_page').$RTR->uri_string; - + $uri = $obj->config->item('base_url'). + $obj->config->item('index_page'). + $obj->uri->uri_string(); + $filepath = $cache_path.md5($uri); if ( ! @file_exists($filepath)) -- cgit v1.2.3-24-g4f1b From dac65764e5ead0bcc9e7fcb2477926d7a2c1dc95 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 17 Sep 2006 18:05:43 +0000 Subject: --- system/libraries/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 44f49ff62..e4fd36698 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -187,7 +187,7 @@ class CI_Validation { $ex = explode('|', $rules); // Is the field required? If not, if the field is blank we'll move on to the next text - if ( ! in_array('required', $ex)) + if ( ! in_array('required', $ex) AND strpos($rules, 'callback_') === FALSE) { if ( ! isset($_POST[$field]) OR $_POST[$field] == '') { -- cgit v1.2.3-24-g4f1b From f6d823ee041caab303a7aba6ecd8c358c6970113 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 17 Sep 2006 18:10:57 +0000 Subject: --- system/libraries/Unit_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index bf50350ae..b2f4bf8cd 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -223,9 +223,9 @@ class CI_Unit_test { * @params string * @return void */ - function set_template($tempalte) + function set_template($template) { - $this->_template = $tempalte; + $this->_template = $template; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From c55b02bcee63c0ea4563583e54959b9f068ea9e9 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 18 Sep 2006 07:44:58 +0000 Subject: --- system/libraries/Output.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system/libraries') diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 9523599e7..c5a9a6281 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -191,6 +191,7 @@ class CI_Output { } // Build the file path. The file name is an MD5 hash of the full URI + $obj =& get_instance(); $uri = $obj->config->item('base_url'). $obj->config->item('index_page'). $obj->uri->uri_string(); -- cgit v1.2.3-24-g4f1b From 15c2bcc24c4b4f4999c5dc73eab57b9b3a6f942e Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 18 Sep 2006 08:17:56 +0000 Subject: --- system/libraries/Output.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Output.php b/system/libraries/Output.php index c5a9a6281..fd07a9f6e 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -178,7 +178,7 @@ class CI_Output { * @access public * @return void */ - function _display_cache() + function _display_cache(&$CFG, &$RTR) { $CFG =& _load_class('CI_Config'); $RTR =& _load_class('CI_Router'); @@ -191,10 +191,9 @@ class CI_Output { } // Build the file path. The file name is an MD5 hash of the full URI - $obj =& get_instance(); - $uri = $obj->config->item('base_url'). - $obj->config->item('index_page'). - $obj->uri->uri_string(); + $uri = $CFG->item('base_url'). + $CFG->item('index_page'). + $RTR->uri_string; $filepath = $cache_path.md5($uri); -- cgit v1.2.3-24-g4f1b From 89a8b9700cd8b27da1f27a18ab5f9d4c5ca2cef4 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 18 Sep 2006 15:46:28 +0000 Subject: --- system/libraries/Validation.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index e4fd36698..227cf9f9a 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -240,7 +240,6 @@ class CI_Validation { // Cycle through the rules! foreach ($ex As $rule) { - // Is the rule a callback? $callback = FALSE; if (substr($rule, 0, 9) == 'callback_') @@ -267,6 +266,12 @@ class CI_Validation { } $result = $this->obj->$rule($_POST[$field], $param); + + // If the field isn't requires we'll move on... + if ( ! in_array('required', $ex)) + { + continue; + } } else { -- cgit v1.2.3-24-g4f1b From d183cb5255817dc431196964becef0db037f0620 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 20 Sep 2006 21:06:32 +0000 Subject: --- system/libraries/Language.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Language.php b/system/libraries/Language.php index 328d53e46..41dab46f4 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -66,12 +66,24 @@ class CI_Language { $idiom = ($deft_lang == '') ? 'english' : $deft_lang; } - if ( ! file_exists(BASEPATH.'language/'.$idiom.'/'.$langfile)) + // Determine where the language file is and load it + + if (file_exists(APPPATH.'language/'.$idiom.'/'.$langfile)) { - show_error('Unable to load the requested language file: language/'.$langfile); + include_once(APPPATH.'language/'.$idiom.'/'.$langfile); + } + else + { + if (file_exists(BASEPATH.'language/'.$idiom.'/'.$langfile)) + { + include_once(BASEPATH.'language/'.$idiom.'/'.$langfile); + } + else + { + show_error('Unable to load the requested language file: language/'.$langfile); + } } - include_once(BASEPATH.'language/'.$idiom.'/'.$langfile); if ( ! isset($lang)) { -- cgit v1.2.3-24-g4f1b From 480da81d6111a5c1faf4433707ee8d3b3de8031e Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 20 Sep 2006 21:11:04 +0000 Subject: --- system/libraries/Loader.php | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index a140fb5a2..ead55dff7 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -243,12 +243,21 @@ class CI_Loader { $helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper'); - if ( ! file_exists(BASEPATH.'helpers/'.$helper.EXT)) + if (file_exists(APPPATH.'helpers/'.$helper.EXT)) { - show_error('Unable to load the requested file: helpers/'.$helper.EXT); + include_once(APPPATH.'helpers/'.$helper.EXT); + } + else + { + if (file_exists(BASEPATH.'helpers/'.$helper.EXT)) + { + include_once(BASEPATH.'helpers/'.$helper.EXT); + } + else + { + show_error('Unable to load the requested file: helpers/'.$helper.EXT); + } } - - include_once(BASEPATH.'helpers/'.$helper.EXT); $this->helpers[$helper] = TRUE; } @@ -300,14 +309,23 @@ class CI_Loader { continue; } - $plugin = strtolower(str_replace(EXT, '', str_replace('_plugin.', '', $plugin)).'_pi'); + $plugin = strtolower(str_replace(EXT, '', str_replace('_plugin.', '', $plugin)).'_pi'); - if ( ! file_exists(BASEPATH.'plugins/'.$plugin.EXT)) + if (file_exists(APPPATH.'plugins/'.$plugin.EXT)) { - show_error('Unable to load the requested file: plugins/'.$plugin.EXT); + include_once(APPPATH.'plugins/'.$plugin.EXT); + } + else + { + if (file_exists(BASEPATH.'plugins/'.$plugin.EXT)) + { + include_once(BASEPATH.'plugins/'.$plugin.EXT); + } + else + { + show_error('Unable to load the requested file: plugins/'.$plugin.EXT); + } } - - include_once(BASEPATH.'plugins/'.$plugin.EXT); $this->plugins[$plugin] = TRUE; } -- cgit v1.2.3-24-g4f1b From e348efb92de213fcfbc312993d8b21a30eb280c0 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 20 Sep 2006 21:13:26 +0000 Subject: --- system/libraries/Validation.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 227cf9f9a..065e7a2d5 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -246,8 +246,8 @@ class CI_Validation { { $rule = substr($rule, 9); $callback = TRUE; - } - + } + // Strip the parameter (if exists) from the rule // Rules can contain a parameter: max_length[5] $param = FALSE; @@ -265,13 +265,14 @@ class CI_Validation { continue; } - $result = $this->obj->$rule($_POST[$field], $param); + $result = $this->obj->$rule($_POST[$field], $param); - // If the field isn't requires we'll move on... - if ( ! in_array('required', $ex)) + // If the field isn't required and we just processed a callback we'll move on... + if ( ! in_array('required', $ex) AND $result !== FALSE) { - continue; + continue 2; } + } else { @@ -295,7 +296,7 @@ class CI_Validation { $result = $this->$rule($_POST[$field], $param); } - + // Did the rule test negatively? If so, grab the error. if ($result === FALSE) { @@ -323,8 +324,9 @@ class CI_Validation { // Add the error to the error array $this->_error_array[] = $message; continue 2; - } + } } + } $total_errors = count($this->_error_array); -- cgit v1.2.3-24-g4f1b From 0fce0f2fcf04db02a1633c155f9d6af3a95c5aa6 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 20 Sep 2006 21:13:41 +0000 Subject: --- system/libraries/Inflector.php | 160 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 system/libraries/Inflector.php (limited to 'system/libraries') diff --git a/system/libraries/Inflector.php b/system/libraries/Inflector.php new file mode 100644 index 000000000..b27228a54 --- /dev/null +++ b/system/libraries/Inflector.php @@ -0,0 +1,160 @@ + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From f9e890c755a414496930a3a6ff37ad75815e8a48 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 20 Sep 2006 23:59:14 +0000 Subject: --- system/libraries/Inflector.php | 160 ----------------------------------------- 1 file changed, 160 deletions(-) delete mode 100644 system/libraries/Inflector.php (limited to 'system/libraries') diff --git a/system/libraries/Inflector.php b/system/libraries/Inflector.php deleted file mode 100644 index b27228a54..000000000 --- a/system/libraries/Inflector.php +++ /dev/null @@ -1,160 +0,0 @@ - \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d16d6c2055f119a4df9812548ed13449f6c806f9 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 00:45:12 +0000 Subject: --- system/libraries/Email.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index abc77a54d..5b991d1fa 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -130,7 +130,7 @@ class CI_Email { * @access public * @return void */ - function clear() + function clear($clear_attachments = FALSE) { $this->_subject = ""; $this->_body = ""; @@ -143,6 +143,13 @@ class CI_Email { $this->_set_header('User-Agent', $this->useragent); $this->_set_header('Date', $this->_set_date()); + + if ($clear_attachments !== FALSE) + { + $this->_attach_name = array(); + $this->_attach_type = array(); + $this->_attach_disp = array(); + } } // END clear() @@ -735,6 +742,11 @@ class CI_Email { */ function _get_alt_message() { + if ($this->alt_message != "") + { + return $this->word_wrap($this->alt_message, '76'); + } + if (eregi( '\', $this->_body, $match)) { $body = $match['1']; -- cgit v1.2.3-24-g4f1b From 460f2678d1ba46f231466232cf1352353d62d598 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 02:41:37 +0000 Subject: --- system/libraries/Output.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'system/libraries') diff --git a/system/libraries/Output.php b/system/libraries/Output.php index fd07a9f6e..b09bf2a53 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -30,6 +30,7 @@ class CI_Output { var $final_output; var $cache_expiration = 0; + var $headers = array(); function CI_Output() { @@ -66,6 +67,26 @@ class CI_Output { { $this->final_output = $output; } + + // -------------------------------------------------------------------- + + /** + * Set Header + * + * Lets you set a server header which will be outputted with the final display. + * + * Note: If a file is cached, headers will not be sent. We need to figure out + * how to permit header data to be saved with the cache data... + * + * @access public + * @param string + * @return void + */ + function set_header($header) + { + $this->headers[] = $header; + } + // -------------------------------------------------------------------- @@ -110,17 +131,30 @@ class CI_Output { $output =& $this->final_output; } + // Do we need to write a cache file? if ($this->cache_expiration > 0) { $this->_write_cache($output); } + // Parse out the elapsed time and memory usage, and + // swap the pseudo-variables with the data $elapsed = $BM->elapsed_time('code_igniter_start', 'code_igniter_end'); $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; $output = str_replace('{memory_usage}', $memory, $output); $output = str_replace('{elapsed_time}', $elapsed, $output); + // Are there any server headers to send? + if (count($this->headers) > 0) + { + foreach ($this->headers as $header) + { + @header($header); + } + } + + // Send it to the browser! echo $output; log_message('debug', "Final output sent to browser"); -- cgit v1.2.3-24-g4f1b From bc042dd0692a6b4b89f11f88e6e3763162ce8048 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 02:46:59 +0000 Subject: --- system/libraries/Exceptions.php | 2 +- system/libraries/Input.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Exceptions.php b/system/libraries/Exceptions.php index a72dbf841..c3af801ae 100644 --- a/system/libraries/Exceptions.php +++ b/system/libraries/Exceptions.php @@ -53,7 +53,7 @@ class CI_Exceptions { */ function CI_Exceptions() { - log_message('debug', "Output Class Initialized"); + // Note: Do not log messages from this constructor. } // END CI_Exceptions() diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 6aba5dd43..dbf939b18 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -430,7 +430,7 @@ class CI_Input { * But it doesn't seem to pose a problem. * */ - $str = str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); // '), array('<?php', '<?PHP', '<?', '?>'), $str); /* * Compact any exploded words -- cgit v1.2.3-24-g4f1b From 9aaa75ed7cd7b2a95cff5b8a52a59c1e6dcf9da6 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 04:45:20 +0000 Subject: --- system/libraries/Output.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Output.php b/system/libraries/Output.php index b09bf2a53..4a3adb858 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -86,7 +86,6 @@ class CI_Output { { $this->headers[] = $header; } - // -------------------------------------------------------------------- @@ -145,6 +144,19 @@ class CI_Output { $output = str_replace('{memory_usage}', $memory, $output); $output = str_replace('{elapsed_time}', $elapsed, $output); + // Is compression requested? + $CFG =& _load_class('CI_Config'); + if ($CFG->item('compress_output') === TRUE) + { + if (extension_loaded('zlib')) + { + if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) AND strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE) + { + ob_start('ob_gzhandler'); + } + } + } + // Are there any server headers to send? if (count($this->headers) > 0) { -- cgit v1.2.3-24-g4f1b From 885b0343036695ad673fc24ba7682fc155c54036 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 05:36:15 +0000 Subject: --- system/libraries/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 065e7a2d5..f9b51d778 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -524,7 +524,7 @@ class CI_Validation { */ function numeric($str) { - return ( ! is_numeric($str)) ? FALSE : TRUE; + return ( ! ereg("^[0-9]+$", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From d48ef1c8e2e84067a58818291935593d70e491f8 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 06:22:05 +0000 Subject: --- system/libraries/Controller.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 768b154e8..5a32e65c0 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -232,16 +232,20 @@ class Controller extends CI_Base { } unset($autoload['config']); - if ( ! is_array($autoload['core'])) + // A little tweak to remain backward compatible + // The $autoload['core'] item was deprecated + if ( ! isset($autoload['libraries'])) { - $autoload['core'] = array($autoload['core']); + $autoload['libraries'] = $autoload['core']; + } - foreach ($autoload['core'] as $item) + foreach ($autoload['libraries'] as $item) { $this->_ci_initialize($item); } - + unset($autoload['libraries']); + return $autoload; } // END _ci_autoload() -- cgit v1.2.3-24-g4f1b From bc4fffbc55d7d04a98a50f1aefa414f965d90644 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 15:30:56 +0000 Subject: --- system/libraries/Upload.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 6d12dbcd7..98edd654f 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -98,10 +98,10 @@ class CI_Upload { * @access public * @return bool */ - function do_upload() + function do_upload($field = 'userfile') { - // Is $_FILES['userfile'] set? If not, no reason to continue. - if ( ! isset($_FILES['userfile'])) + // Is $_FILES[$field] set? If not, no reason to continue. + if ( ! isset($_FILES[$field])) { $this->set_error('upload_userfile_not_set'); return FALSE; @@ -114,9 +114,9 @@ class CI_Upload { } // Was the file able to be uploaded? If not, determine the reason why. - if ( ! is_uploaded_file($_FILES['userfile']['tmp_name'])) + if ( ! is_uploaded_file($_FILES[$field]['tmp_name'])) { - $error = ( ! isset($_FILES['userfile']['error'])) ? 4 : $_FILES['userfile']['error']; + $error = ( ! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error']; switch($error) { @@ -134,12 +134,12 @@ class CI_Upload { } // Set the uploaded data as class variables - $this->file_temp = $_FILES['userfile']['tmp_name']; - $this->file_name = $_FILES['userfile']['name']; - $this->file_size = $_FILES['userfile']['size']; - $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES['userfile']['type']); + $this->file_temp = $_FILES[$field]['tmp_name']; + $this->file_name = $_FILES[$field]['name']; + $this->file_size = $_FILES[$field]['size']; + $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']); $this->file_type = strtolower($this->file_type); - $this->file_ext = $this->get_extension($_FILES['userfile']['name']); + $this->file_ext = $this->get_extension($_FILES[$field]['name']); // Convert the file size to kilobytes if ($this->file_size > 0) -- cgit v1.2.3-24-g4f1b From daf454dabe983f621570bcef10d6d8babedfb8a8 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 17:01:27 +0000 Subject: --- system/libraries/URI.php | 93 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 91 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/URI.php b/system/libraries/URI.php index ba6279e88..11562eb29 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -65,6 +65,25 @@ class CI_URI { // -------------------------------------------------------------------- + /** + * Fetch a URI "routed" Segment + * + * This function returns the re-routed URI segment (assuming routing rules are used) + * based on the number provided. If there is no routing this function returns the + * same result as $this->segment() + * + * @access public + * @param integer + * @param bool + * @return string + */ + function rsegment($n, $no_result = FALSE) + { + return ( ! isset($this->router->rsegments[$n])) ? $no_result : $this->router->rsegments[$n]; + } + + // -------------------------------------------------------------------- + /** * Generate a key value pair from the URI string * @@ -168,7 +187,6 @@ class CI_URI { return implode('/', $temp); } - // -------------------------------------------------------------------- /** @@ -180,6 +198,37 @@ class CI_URI { * @return string */ function slash_segment($n, $where = 'trailing') + { + return $this->_slash_segment($n, $where, 'segment'); + } + + // -------------------------------------------------------------------- + + /** + * Fetch a URI Segment and add a trailing slash + * + * @access public + * @param integer + * @param string + * @return string + */ + function slash_rsegment($n, $where = 'trailing') + { + return $this->_slash_segment($n, $where, 'rsegment'); + } + + // -------------------------------------------------------------------- + + /** + * Fetch a URI Segment and add a trailing slash - helper function + * + * @access private + * @param integer + * @param string + * @param string + * @return string + */ + function _slash_segment($n, $where = 'trailing', $which = 'segment') { if ($where == 'trailing') { @@ -196,7 +245,7 @@ class CI_URI { $leading = '/'; $trailing = '/'; } - return ( ! isset($this->router->segments[$n])) ? '' : $leading.$this->router->segments[$n].$trailing; + return ( ! isset($this->router->$which[$n])) ? '' : $leading.$this->router->$which[$n].$trailing; } // -------------------------------------------------------------------- @@ -211,6 +260,19 @@ class CI_URI { { return $this->router->segments; } + + // -------------------------------------------------------------------- + + /** + * Routed Segment Array + * + * @access public + * @return array + */ + function rsegment_array() + { + return $this->router->rsegments; + } // -------------------------------------------------------------------- @@ -224,6 +286,19 @@ class CI_URI { { return count($this->router->segments); } + + // -------------------------------------------------------------------- + + /** + * Total number of routed segments + * + * @access public + * @return integer + */ + function total_rsegments() + { + return count($this->router->rsegments); + } // -------------------------------------------------------------------- @@ -238,6 +313,20 @@ class CI_URI { return $this->router->uri_string; } + + // -------------------------------------------------------------------- + + /** + * Fetch the entire Re-routed URI string + * + * @access public + * @return string + */ + function uri_rstring() + { + return '/'.implode('/', $this->rsegment_array()).'/'; + } + } // END URI Class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 99bccd6aea613901d7eaf74f141f78342e2ec333 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 17:05:40 +0000 Subject: --- system/libraries/Router.php | 55 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 7 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 1dd1e5426..868fd909e 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -31,6 +31,7 @@ class CI_Router { var $config; var $uri_string = ''; var $segments = array(); + var $rsegments = array(); var $routes = array(); var $class = ''; var $method = 'index'; @@ -78,7 +79,7 @@ class CI_Router { } // Load the routes.php file - include_once(APPPATH.'config/routes'.EXT); + @include_once(APPPATH.'config/routes'.EXT); $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route; unset($route); @@ -151,12 +152,7 @@ class CI_Router { $this->_parse_routes(); // Re-index the segment array so that it starts with 1 rather than 0 - $i = 1; - foreach ($this->segments as $val) - { - $this->segments[$i++] = $val; - } - unset($this->segments['0']); + $this->_reindex_segments(); } // END _set_route_mapping() @@ -199,6 +195,11 @@ class CI_Router { $this->set_method($segments['1']); } } + + // Update our "routed" segment array to contain the segments. + // Note: If there is no custom routing, this array will be + // identical to $this->segments + $this->rsegments = $segments; } // END _compile_segments() @@ -256,6 +257,46 @@ class CI_Router { show_404(); } // END _validate_segments() + + // -------------------------------------------------------------------- + /** + * Re-index Segments + * + * This function re-indexes the $this->segment array so that it + * starts at 1 rather then 0. Doing so makes it simpler to + * use functions like $this->uri->segment(n) since there is + * a 1:1 relationship between the segment array and the actual segments. + * + * @access private + * @return void + */ + function _reindex_segments() + { + // Is the routed segment array different then the main segment array? + $diff = (count(array_diff($this->rsegments, $this->segments)) == 0) ? FALSE : TRUE; + + $i = 1; + foreach ($this->segments as $val) + { + $this->segments[$i++] = $val; + } + unset($this->segments['0']); + + if ($diff == FALSE) + { + $this->rsegments = $this->segments; + } + else + { + $i = 1; + foreach ($this->rsegments as $val) + { + $this->rsegments[$i++] = $val; + } + unset($this->rsegments['0']); + } + } + // END _reindex_segments() // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 05633d7348b85147a46a7396c3bee1928335fa7a Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 17:22:21 +0000 Subject: --- system/libraries/Parser.php | 2 +- system/libraries/URI.php | 41 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 9f6a814ae..b07b64fdd 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -47,7 +47,7 @@ class CI_Parser { $OUT =& _load_class('CI_Output'); $obj =& get_instance(); - $template = $obj->load->view($template, '', TRUE); + $template = $obj->load->view($template, $data, TRUE); if ($template == '') { diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 11562eb29..e831d9526 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -107,6 +107,41 @@ class CI_URI { */ function uri_to_assoc($n = 3, $default = array()) { + return $this->_uri_to_assoc($n, $default, 'segment'); + } + /** + * Identical to above only it uses the re-routed segment array + * + */ + function ruri_to_assoc($n = 3, $default = array()) + { + return $this->_uri_to_assoc($n, $default, 'rsegment'); + } + + // -------------------------------------------------------------------- + + /** + * Generate a key value pair from the URI string or Re-routed URI string + * + * @access private + * @param integer the starting segment number + * @param array an array of default values + * @param string which array we should use + * @return array + */ + function _uri_to_assoc($n = 3, $default = array(), $which = 'segment') + { + if ($which == 'segment') + { + $total_segments = 'total_segments'; + $segment_array = 'segment_array'; + } + else + { + $total_segments = 'total_rsegments'; + $segment_array = 'rsegment_array'; + } + if ( ! is_numeric($n)) { return $default; @@ -117,7 +152,7 @@ class CI_URI { return $this->keyval[$n]; } - if ($this->total_segments() < $n) + if ($this->$total_segments() < $n) { if (count($default) == 0) { @@ -132,7 +167,7 @@ class CI_URI { return $retval; } - $segments = array_slice($this->segment_array(), ($n - 1)); + $segments = array_slice($this->$segment_array(), ($n - 1)); $i = 0; $lastval = ''; @@ -322,7 +357,7 @@ class CI_URI { * @access public * @return string */ - function uri_rstring() + function ruri_string() { return '/'.implode('/', $this->rsegment_array()).'/'; } -- cgit v1.2.3-24-g4f1b From c1fa07415179d63762f1a22f0f74660a8034707f Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 23:50:23 +0000 Subject: --- system/libraries/Controller.php | 2 +- system/libraries/Output.php | 22 +++++++++++++++------- system/libraries/URI.php | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 5a32e65c0..0dd6ee6a4 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -380,7 +380,7 @@ class Controller extends CI_Base { eval('class CI_DB extends CI_DB_driver { }'); } } - + require_once(BASEPATH.'drivers/DB_'.$params['dbdriver'].EXT); // Instantiate the DB adapter diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 4a3adb858..ec3660c6c 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -123,8 +123,8 @@ class CI_Output { */ function _display($output = '') { - $BM =& _load_class('CI_Benchmark'); - + $obj =& get_instance(); + if ($output == '') { $output =& $this->final_output; @@ -138,15 +138,14 @@ class CI_Output { // Parse out the elapsed time and memory usage, and // swap the pseudo-variables with the data - $elapsed = $BM->elapsed_time('code_igniter_start', 'code_igniter_end'); + $elapsed = $obj->benchmark->elapsed_time('code_igniter_start', 'code_igniter_end'); $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; $output = str_replace('{memory_usage}', $memory, $output); $output = str_replace('{elapsed_time}', $elapsed, $output); // Is compression requested? - $CFG =& _load_class('CI_Config'); - if ($CFG->item('compress_output') === TRUE) + if ($obj->config->item('compress_output') === TRUE) { if (extension_loaded('zlib')) { @@ -166,8 +165,17 @@ class CI_Output { } } - // Send it to the browser! - echo $output; + // Send the finalized output either directly + // to the browser or to the user's _output() + // function if it exists + if (method_exists($obj, '_output')) + { + $obj->_output($output); + } + else + { + echo $output; // Send it to the browser! + } log_message('debug', "Final output sent to browser"); log_message('debug', "Total execution time: ".$elapsed); diff --git a/system/libraries/URI.php b/system/libraries/URI.php index e831d9526..89ca42e44 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -280,7 +280,7 @@ class CI_URI { $leading = '/'; $trailing = '/'; } - return ( ! isset($this->router->$which[$n])) ? '' : $leading.$this->router->$which[$n].$trailing; + return $leading.$this->$which($n).$trailing; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 592cdcbc58963f0cf811aea59db9907943460770 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 22 Sep 2006 18:45:42 +0000 Subject: --- system/libraries/Router.php | 138 +++++++++++++++++++++++++++++++++----------- 1 file changed, 104 insertions(+), 34 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 868fd909e..5bbf9e6ca 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -77,45 +77,18 @@ class CI_Router { return; } - - // Load the routes.php file + + // Load the routes.php file and set the default controller @include_once(APPPATH.'config/routes'.EXT); $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route; unset($route); - // Set the default controller - $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); - - // Fetch the URI string Depending on the server, - // the URI will be available in one of two globals - if ($this->config->item('uri_protocol') == 'auto') - { - $path_info = getenv('PATH_INFO'); - if ($path_info != '' AND $path_info != "/".SELF) - { - $this->uri_string = $path_info; - } - else - { - $path_info = getenv('ORIG_PATH_INFO'); - if ($path_info != '' AND $path_info != "/".SELF) - { - $this->uri_string = $path_info; - } - else - { - $this->uri_string = getenv('QUERY_STRING'); - } - } - } - else - { - $this->uri_string = getenv(strtoupper($this->config->item('uri_protocol'))); - } - + $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); - // Is there a URI string? If not, the default controller specified - // by the admin in the "routes" file will be shown. + // Get the URI string + $this->uri_string = $this->_get_uri_string(); + + // Is there a URI string? If not, the default controller specified in the "routes" file will be shown. if ($this->uri_string == '') { if ($this->default_controller === FALSE) @@ -300,6 +273,103 @@ class CI_Router { // -------------------------------------------------------------------- + /** + * Get the URI String + * + * @access private + * @return string + */ + function _get_uri_string() + { + if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') + { + $path_info = getenv('PATH_INFO'); + if ($path_info != '' AND $path_info != "/".SELF) + { + return $path_info; + } + else + { + $req_uri = $this->_parse_request_uri(); + + if ($req_uri != "") + { + return $req_uri; + } + else + { + $path_info = getenv('ORIG_PATH_INFO'); + if ($path_info != '' AND $path_info != "/".SELF) + { + return $path_info; + } + else + { + return getenv('QUERY_STRING'); + } + } + } + } + else + { + $uri = strtoupper($this->config->item('uri_protocol')); + + if ($uri == 'REQUEST_URI') + { + return $this->_parse_request_uri(); + } + + return getenv($uri); + } + } + // END _get_uri_string() + + // -------------------------------------------------------------------- + + /** + * Parse the REQUEST_URI + * + * Due to the way REQUEST_URI works it usually contains path info + * that makes it unusable as URI data. We'll trim off the unnecessary + * data, hopefully arriving at a valid URI that we can use. + * + * @access private + * @return string + */ + function _parse_request_uri() + { + $request_uri = getenv('REQUEST_URI'); + $fc_path = FCPATH; + + if (strpos($request_uri, '?') !== FALSE) + { + $fc_path .= '?'; + } + + $parsed_uri = explode("/", preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $request_uri))); + + $i = 0; + foreach(explode("/", $fc_path) as $segment) + { + if ($segment == $parsed_uri[$i]) + { + $i++; + } + } + + $parsed_uri = implode("/", array_slice($parsed_uri, $i)); + + if ($parsed_uri != '') + { + $parsed_uri = '/'.$parsed_uri; + } + + return $parsed_uri; + } + // END _parse_request_uri() + + // -------------------------------------------------------------------- + /** * Filter segments for malicious characters * -- cgit v1.2.3-24-g4f1b From dbd8aec6121f1d0a295031c268964357ebcc84e0 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 22 Sep 2006 19:20:09 +0000 Subject: --- system/libraries/Router.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 5bbf9e6ca..d1751a0e9 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -85,11 +85,8 @@ class CI_Router { $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); - // Get the URI string - $this->uri_string = $this->_get_uri_string(); - // Is there a URI string? If not, the default controller specified in the "routes" file will be shown. - if ($this->uri_string == '') + if (($this->uri_string = $this->_get_uri_string()) == '') { if ($this->default_controller === FALSE) { @@ -338,7 +335,11 @@ class CI_Router { */ function _parse_request_uri() { - $request_uri = getenv('REQUEST_URI'); + if (($request_uri = getenv('REQUEST_URI')) == '') + { + return ''; + } + $fc_path = FCPATH; if (strpos($request_uri, '?') !== FALSE) -- cgit v1.2.3-24-g4f1b From 212a3fa070a02c812b84ca937c5cb411400e6f3d Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 23 Sep 2006 04:22:39 +0000 Subject: --- system/libraries/Loader.php | 24 ++++++++---------------- system/libraries/Parser.php | 4 +--- 2 files changed, 9 insertions(+), 19 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index ead55dff7..d966e2862 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -454,9 +454,7 @@ class CI_Loader { * @return void */ function _ci_load($data) - { - $OUT =& _load_class('CI_Output'); - + { // This allows anything loaded using $this->load (viwes, files, etc.) // to become accessible from within the Controller and Model functions. $obj =& get_instance(); @@ -477,15 +475,11 @@ class CI_Loader { /* * Extract and cached variables * - * You can either set variables using the dedicated - * $this->load_vars() 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. - * + * You can either set variables using the dedicated $this->load_vars() + * 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($vars)) { $this->cached_vars = array_merge($this->cached_vars, $vars); @@ -515,10 +509,8 @@ class CI_Loader { * need post processing? For one thing, in order to * show the elapsed page load time. Unless we * can intercept the content right before it's sent to - * the browser and then stop the timer, it won't be acurate. - * + * the browser and then stop the timer it won't be acurate. */ - if ( ! file_exists($path)) { show_error('Unable to load the requested file: '.$file); @@ -541,7 +533,7 @@ class CI_Loader { /* * Flush the buffer... or buff the flusher? * - * In order to permit templates (views) to be nested within + * In order to permit views to be nested within * other views, we need to flush the content back out whenever * we are beyond the first level of output buffering so that * it can be seen and included properly by the first included @@ -554,7 +546,7 @@ class CI_Loader { } else { - $OUT->set_output(ob_get_contents()); + $obj->output->set_output(ob_get_contents()); ob_end_clean(); } } diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index b07b64fdd..17a985fd7 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -44,8 +44,6 @@ class CI_Parser { */ function parse($template, $data, $return = FALSE) { - $OUT =& _load_class('CI_Output'); - $obj =& get_instance(); $template = $obj->load->view($template, $data, TRUE); @@ -68,7 +66,7 @@ class CI_Parser { if ($return == FALSE) { - $OUT->final_output = $template; + $obj->output->final_output = $template; } return $template; -- cgit v1.2.3-24-g4f1b From 4e9f3f90ed26a0dc4bcacf106d6421bf725b5ae3 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 23 Sep 2006 17:39:20 +0000 Subject: --- system/libraries/Parser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 17a985fd7..63dc023a2 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -54,11 +54,11 @@ class CI_Parser { foreach ($data as $key => $val) { - if ( ! is_array($val)) + if (is_string($val)) { $template = $this->_parse_single($key, $val, $template); } - else + elseif (is_array($val)) { $template = $this->_parse_pair($key, $val, $template); } -- cgit v1.2.3-24-g4f1b From b5a651cd710f7454425b9b94ff4a44fc4edacaba Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 23 Sep 2006 17:39:41 +0000 Subject: --- system/libraries/Output.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Output.php b/system/libraries/Output.php index ec3660c6c..5a158245f 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -123,7 +123,10 @@ class CI_Output { */ function _display($output = '') { - $obj =& get_instance(); + // Note: We can't use $obj =& _get_instance() since this function + // is sometimes called by the caching mechanism, which happens before + // it's available. Instead we'll use globals... + global $BM, $CFG; if ($output == '') { @@ -138,14 +141,14 @@ class CI_Output { // Parse out the elapsed time and memory usage, and // swap the pseudo-variables with the data - $elapsed = $obj->benchmark->elapsed_time('code_igniter_start', 'code_igniter_end'); + $elapsed = $BM->elapsed_time('code_igniter_start', 'code_igniter_end'); $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; $output = str_replace('{memory_usage}', $memory, $output); $output = str_replace('{elapsed_time}', $elapsed, $output); // Is compression requested? - if ($obj->config->item('compress_output') === TRUE) + if ($CFG->item('compress_output') === TRUE) { if (extension_loaded('zlib')) { @@ -168,7 +171,7 @@ class CI_Output { // Send the finalized output either directly // to the browser or to the user's _output() // function if it exists - if (method_exists($obj, '_output')) + if (function_exists('_get_instance') AND method_exists($obj, '_output')) { $obj->_output($output); } -- cgit v1.2.3-24-g4f1b From e885d787cde65d9ab003426bf79047de57c83ebe Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 23 Sep 2006 20:25:05 +0000 Subject: --- system/libraries/Xmlrpcs.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index eaec87a6d..0543c3b78 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -223,7 +223,7 @@ class CI_XML_RPC_Server extends CI_XML_RPC // Executes the Method //------------------------------------- - function execute($m) + function _execute($m) { $methName = $m->method_name; -- cgit v1.2.3-24-g4f1b From 3c023b12c3d27f0e2773e671b854e52e2dc0d1d6 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 03:04:10 +0000 Subject: --- system/libraries/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index f9b51d778..153657e31 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -524,7 +524,7 @@ class CI_Validation { */ function numeric($str) { - return ( ! ereg("^[0-9]+$", $str)) ? FALSE : TRUE; + return ( ! ereg("^[0-9\.]+$", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 5808346898ec9c602893fc54540958a8c556be29 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 17:58:27 +0000 Subject: --- system/libraries/Controller.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 0dd6ee6a4..5be10500b 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -362,11 +362,11 @@ class Controller extends CI_Base { $params['active_r'] = TRUE; } - require_once(BASEPATH.'drivers/DB_driver'.EXT); + require_once(BASEPATH.'database/DB_driver'.EXT); if ( ! isset($params['active_r']) OR $params['active_r'] == TRUE) { - require_once(BASEPATH.'drivers/DB_active_record'.EXT); + require_once(BASEPATH.'database/DB_active_record'.EXT); if ( ! class_exists('CI_DB')) { @@ -381,7 +381,7 @@ class Controller extends CI_Base { } } - require_once(BASEPATH.'drivers/DB_'.$params['dbdriver'].EXT); + require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].EXT); // Instantiate the DB adapter $driver = 'CI_DB_'. $params['dbdriver']; -- cgit v1.2.3-24-g4f1b From 46563d570944d6c5af8b4f46ba1eeca111eabaa4 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 18:14:22 +0000 Subject: --- system/libraries/Controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 5be10500b..61c8363fa 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -381,10 +381,10 @@ class Controller extends CI_Base { } } - require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].EXT); + require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver'.EXT); // Instantiate the DB adapter - $driver = 'CI_DB_'. $params['dbdriver']; + $driver = 'CI_DB_'. $params['dbdriver'].'_driver'; $DB = new $driver($params); if ($return === TRUE) -- cgit v1.2.3-24-g4f1b From c9a8bab572388bbba541f1cf8f12a46e2103e447 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 20:28:33 +0000 Subject: --- system/libraries/Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 61c8363fa..b91cf3b07 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -366,7 +366,7 @@ class Controller extends CI_Base { if ( ! isset($params['active_r']) OR $params['active_r'] == TRUE) { - require_once(BASEPATH.'database/DB_active_record'.EXT); + require_once(BASEPATH.'database/DB_active_rec'.EXT); if ( ! class_exists('CI_DB')) { -- cgit v1.2.3-24-g4f1b From a5e812c007b8dfbc4c117df379d63060f08b096a Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 02:17:30 +0000 Subject: --- system/libraries/Controller.php | 46 +++++++++++++++++++++++++++++++++++++++-- system/libraries/Loader.php | 25 +++++++++++++++++++++- 2 files changed, 68 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index b91cf3b07..5fdbd9f9f 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -384,7 +384,7 @@ class Controller extends CI_Base { require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver'.EXT); // Instantiate the DB adapter - $driver = 'CI_DB_'. $params['dbdriver'].'_driver'; + $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; $DB = new $driver($params); if ($return === TRUE) @@ -397,7 +397,49 @@ class Controller extends CI_Base { $obj->db =& $DB; } // END _ci_init_database() - + + + // -------------------------------------------------------------------- + + /** + * Initialize Database Utilities Class + * + * @access private + * @param mixed database platform + * @param bool whether to return the object + * @return void + */ + function _ci_init_dbutils($db = '', $return = FALSE) + { + if ($this->_ci_is_loaded('dbutils') == TRUE AND $return == FALSE) + { + return; + } + + if ($this->_ci_is_loaded('db') == FALSE) + { + $this->_ci_init_database(); + } + + require_once(BASEPATH.'database/DB_utility'.EXT); + require_once(BASEPATH.'database/drivers/'.$this->db->dbdriver.'/'.$this->db->dbdriver.'_utility'.EXT); + + + // Instantiate the DB adapter + $driver = 'CI_DB_'.$this->db->dbdriver.'_utility'; + $DB = new $driver(); + + if ($return === TRUE) + { + return $DB; + } + + $obj =& get_instance(); + $obj->ci_is_loaded[] = 'dbutils'; + $obj->dbutil =& $DB; + } + // END _ci_init_database() + // -------------------------------------------------------------------- /** diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index d966e2862..f4a9f821d 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -108,7 +108,7 @@ class CI_Loader { * @param string the DB credentials * @param bool whether to return the DB object * @param bool whether to enable active record (this allows us to override the config setting) - * @return mixed + * @return object */ function database($db = '', $return = FALSE, $active_record = FALSE) { @@ -125,6 +125,29 @@ class CI_Loader { } } // END database() + + // -------------------------------------------------------------------- + + /** + * Database Utilities Loader + * + * @access public + * @param string the DB platform + * @param bool whether to return the DB object + * @return object + */ + function dbutils($db = '', $return = FALSE) + { + $obj =& get_instance(); + + if ( ! is_bool($return)) + { + $return = FALSE; + } + + return $obj->_ci_init_dbutils($db, $return); + } + // END dbutils() // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 83b05a860a5f208d15942b517385848cfe4887bb Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 21:06:46 +0000 Subject: --- system/libraries/Loader.php | 7 +++++-- system/libraries/Router.php | 20 ++++++++++---------- system/libraries/Validation.php | 16 +++++++++++++++- 3 files changed, 30 insertions(+), 13 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index f4a9f821d..b69d3f049 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -363,7 +363,10 @@ class CI_Loader { * Load Script * * This function loads the specified include file from the - * application/scripts/ folder + * application/scripts/ folder. + * + * NOTE: This feature has been deprecated but it will remain available + * for legacy users. * * @access public * @param array @@ -496,7 +499,7 @@ class CI_Loader { } /* - * Extract and cached variables + * Extract and cache variables * * You can either set variables using the dedicated $this->load_vars() * function or via the second parameter of this function. We'll merge diff --git a/system/libraries/Router.php b/system/libraries/Router.php index d1751a0e9..d7740f5f3 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -149,12 +149,12 @@ class CI_Router { return; } - $this->set_class($segments['0']); + $this->set_class($segments[0]); - if (isset($segments['1'])) + if (isset($segments[1])) { // A scaffolding request. No funny business with the URL - if ($this->routes['scaffolding_trigger'] == $segments['1'] AND $segments['1'] != '_ci_scaffolding') + if ($this->routes['scaffolding_trigger'] == $segments[1] AND $segments[1] != '_ci_scaffolding') { $this->scaffolding_request = TRUE; unset($this->routes['scaffolding_trigger']); @@ -162,7 +162,7 @@ class CI_Router { else { // A standard method request - $this->set_method($segments['1']); + $this->set_method($segments[1]); } } @@ -186,22 +186,22 @@ class CI_Router { function _validate_segments($segments) { // Does the requested controller exist in the root folder? - if (file_exists(APPPATH.'controllers/'.$segments['0'].EXT)) + if (file_exists(APPPATH.'controllers/'.$segments[0].EXT)) { return $segments; } // Is the controller in a sub-folder? - if (is_dir(APPPATH.'controllers/'.$segments['0'])) + if (is_dir(APPPATH.'controllers/'.$segments[0])) { // Set the directory and remove it from the segment array - $this->set_directory($segments['0']); + $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)) + if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT)) { show_404(); } @@ -250,7 +250,7 @@ class CI_Router { { $this->segments[$i++] = $val; } - unset($this->segments['0']); + unset($this->segments[0]); if ($diff == FALSE) { @@ -263,7 +263,7 @@ class CI_Router { { $this->rsegments[$i++] = $val; } - unset($this->rsegments['0']); + unset($this->rsegments[0]); } } // END _reindex_segments() diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 153657e31..b65b9be52 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -519,13 +519,27 @@ class CI_Validation { * Numeric * * @access public - * @param string + * @param int * @return bool */ function numeric($str) { return ( ! ereg("^[0-9\.]+$", $str)) ? FALSE : TRUE; } + + // -------------------------------------------------------------------- + + /** + * Is Numeric + * + * @access public + * @param string + * @return bool + */ + function is_numeric($str) + { + return ( ! is_numeric($str)) ? FALSE : TRUE; + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 9cd4e8e639a1a09fd6ca426f1af94586f30d4a80 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 23:26:25 +0000 Subject: --- system/libraries/Controller.php | 2 +- system/libraries/Loader.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 5fdbd9f9f..da5f2e072 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -409,7 +409,7 @@ class Controller extends CI_Base { * @param bool whether to return the object * @return void */ - function _ci_init_dbutils($db = '', $return = FALSE) + function _ci_init_dbutil($db = '', $return = FALSE) { if ($this->_ci_is_loaded('dbutils') == TRUE AND $return == FALSE) { diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index b69d3f049..833e37640 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -136,7 +136,7 @@ class CI_Loader { * @param bool whether to return the DB object * @return object */ - function dbutils($db = '', $return = FALSE) + function dbutil($db = '', $return = FALSE) { $obj =& get_instance(); @@ -145,7 +145,7 @@ class CI_Loader { $return = FALSE; } - return $obj->_ci_init_dbutils($db, $return); + return $obj->_ci_init_dbutil($db, $return); } // END dbutils() -- cgit v1.2.3-24-g4f1b From 30c3b9709a12b7346c7057e656a491ffb9168f55 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 26 Sep 2006 02:09:47 +0000 Subject: --- system/libraries/Controller.php | 42 ----------------------------------------- 1 file changed, 42 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index da5f2e072..afd963a7a 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -397,49 +397,7 @@ class Controller extends CI_Base { $obj->db =& $DB; } // END _ci_init_database() - - - // -------------------------------------------------------------------- - - /** - * Initialize Database Utilities Class - * - * @access private - * @param mixed database platform - * @param bool whether to return the object - * @return void - */ - function _ci_init_dbutil($db = '', $return = FALSE) - { - if ($this->_ci_is_loaded('dbutils') == TRUE AND $return == FALSE) - { - return; - } - - if ($this->_ci_is_loaded('db') == FALSE) - { - $this->_ci_init_database(); - } - - require_once(BASEPATH.'database/DB_utility'.EXT); - require_once(BASEPATH.'database/drivers/'.$this->db->dbdriver.'/'.$this->db->dbdriver.'_utility'.EXT); - - // Instantiate the DB adapter - $driver = 'CI_DB_'.$this->db->dbdriver.'_utility'; - $DB = new $driver(); - - if ($return === TRUE) - { - return $DB; - } - - $obj =& get_instance(); - $obj->ci_is_loaded[] = 'dbutils'; - $obj->dbutil =& $DB; - } - // END _ci_init_database() - // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From e79dc7130a0003a07833609487b8ebb5ebcf31c8 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 26 Sep 2006 03:52:45 +0000 Subject: --- system/libraries/Calendar.php | 7 ++++++- system/libraries/Controller.php | 42 ++++++++++++++++++++--------------------- system/libraries/Email.php | 5 +++++ system/libraries/Encrypt.php | 5 +++++ system/libraries/Image_lib.php | 11 +++++++++++ system/libraries/Loader.php | 20 +++++++------------- system/libraries/Model.php | 9 +++++---- system/libraries/Pagination.php | 11 +++++++++++ system/libraries/Parser.php | 5 +++++ system/libraries/Session.php | 5 +++++ system/libraries/Trackback.php | 5 +++++ system/libraries/Unit_test.php | 5 +++++ system/libraries/Upload.php | 11 +++++++++++ system/libraries/Validation.php | 5 +++++ system/libraries/Xmlrpc.php | 13 +++++++++++++ system/libraries/Xmlrpcs.php | 33 +++++++++++++++++++++++++++++++- 16 files changed, 151 insertions(+), 41 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index b77dd1b6f..a3c070390 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -13,6 +13,11 @@ * @filesource */ +// INITIALIZE THE CLASS --------------------------------------------------- + +$obj =& get_instance(); +$obj->calendar =& new CI_Calendar(); + // ------------------------------------------------------------------------ /** @@ -25,7 +30,7 @@ * @category Libraries * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/libraries/calendar.html - */ + */ class CI_Calendar { var $lang; diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index afd963a7a..97aa4b789 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -29,7 +29,6 @@ */ class Controller extends CI_Base { - var $ci_is_loaded = array(); var $_ci_models = array(); var $_ci_scaffolding = FALSE; var $_ci_scaff_table = FALSE; @@ -54,15 +53,18 @@ class Controller extends CI_Base { // This allows anything loaded using $this->load (viwes, files, etc.) // to become accessible from within the Controller class functions. - foreach ($this->ci_is_loaded as $val) + foreach (get_object_vars($this) as $key => $var) { - $this->load->$val =& $this->$val; + if (is_object($var)) + { + $this->load->$key =& $this->$key; + } } - + log_message('debug', "Controller Class Initialized"); } // END Controller() - + // -------------------------------------------------------------------- /** @@ -75,27 +77,28 @@ class Controller extends CI_Base { * @param mixed any additional parameters * @return void */ - function _ci_initialize($what, $params = FALSE) + function _ci_initialize($class, $params = FALSE) { - $method = '_ci_init_'.strtolower(str_replace(EXT, '', $what)); + $class = strtolower(str_replace(EXT, '', $class)); + $method = '_ci_init_'.$class; if ( ! method_exists($this, $method)) - { - $method = substr($method, 4); + { + $class = ucfirst($class); - if ( ! file_exists(APPPATH.'init/'.$method.EXT)) + if ( ! file_exists(APPPATH.'libraries/'.$class.EXT)) { - if ( ! file_exists(BASEPATH.'init/'.$method.EXT)) + if ( ! file_exists(BASEPATH.'libraries/'.$class.EXT)) { - log_message('error', "Unable to load the requested class: ".$what); - show_error("Unable to load the class: ".$what); + log_message('error', "Unable to load the requested class: ".$class); + show_error("Unable to load the class: ".$class); } - include(BASEPATH.'init/'.$method.EXT); + include_once(BASEPATH.'libraries/'.$class.EXT); } else { - include(APPPATH.'init/'.$method.EXT); + include_once(APPPATH.'libraries/'.$class.EXT); } } else @@ -268,11 +271,9 @@ class Controller extends CI_Base { { $class = strtolower($val); $this->$class =& _load_class('CI_'.$val); - $this->ci_is_loaded[] = $class; } $this->lang =& _load_class('CI_Language'); - $this->ci_is_loaded[] = 'lang'; // In PHP 4 the Controller class is a child of CI_Loader. // In PHP 5 we run it as its own class. @@ -280,8 +281,6 @@ class Controller extends CI_Base { { $this->load = new CI_Loader(); } - - $this->ci_is_loaded[] = 'load'; } // END _ci_assign_core() @@ -393,7 +392,6 @@ class Controller extends CI_Base { } $obj =& get_instance(); - $obj->ci_is_loaded[] = 'db'; $obj->db =& $DB; } // END _ci_init_database() @@ -409,10 +407,10 @@ class Controller extends CI_Base { */ function _ci_is_loaded($class) { - return ( ! in_array($class, $this->ci_is_loaded)) ? FALSE : TRUE; + return ( ! isset($this->$class) OR ! is_object($this->$class)) ? FALSE : TRUE; } // END _ci_is_loaded() - + // -------------------------------------------------------------------- /** diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 5b991d1fa..c153043d9 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -13,6 +13,11 @@ * @filesource */ +// INITIALIZE THE CLASS --------------------------------------------------- + +$obj =& get_instance(); +$obj->email =& new CI_Email(); + // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index bcffdf1ab..446f64aa6 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -13,6 +13,11 @@ * @filesource */ +// INITIALIZE THE CLASS --------------------------------------------------- + +$obj =& get_instance(); +$obj->encrypt =& new CI_Encrypt(); + // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 18e3253f7..86ed05943 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -13,6 +13,17 @@ * @filesource */ +// INITIALIZE THE CLASS --------------------------------------------------- + +$config = array(); +if (file_exists(APPPATH.'config/image_lib'.EXT)) +{ + include_once(APPPATH.'config/image_lib'.EXT); +} + +$obj =& get_instance(); +$obj->image_lib =& new CI_Image_lib($config); + // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 833e37640..7449fa34a 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -136,15 +136,9 @@ class CI_Loader { * @param bool whether to return the DB object * @return object */ - function dbutil($db = '', $return = FALSE) + function dbutil() { $obj =& get_instance(); - - if ( ! is_bool($return)) - { - $return = FALSE; - } - return $obj->_ci_init_dbutil($db, $return); } // END dbutils() @@ -484,14 +478,14 @@ class CI_Loader { // This allows anything loaded using $this->load (viwes, files, etc.) // to become accessible from within the Controller and Model functions. $obj =& get_instance(); - foreach ($obj->ci_is_loaded as $val) + foreach (get_object_vars($obj) as $key => $var) { - if ( ! isset($this->$val)) + if (is_object($var)) { - $this->$val =& $obj->$val; - } - } - + $this->$key =& $obj->$key; + } + } + // Set the default data variables foreach (array('view', 'vars', 'path', 'return') as $val) { diff --git a/system/libraries/Model.php b/system/libraries/Model.php index 9834f8278..55c995636 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -50,20 +50,21 @@ class Model { function _assign_libraries($use_reference = TRUE) { $obj =& get_instance(); - foreach ($obj->ci_is_loaded as $val) + foreach (get_object_vars($obj) as $key => $var) { - if ( ! isset($this->$val)) + if (is_object($var) AND ! isset($this->$key)) { if ($use_reference === TRUE) { - $this->$val =& $obj->$val; + $this->$key =& $obj->$key; } else { - $this->$val = $obj->$val; + $this->$key = $obj->$key; } } } + } // END _assign_libraries() diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 9d558f00a..d83a2bd0f 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -13,6 +13,17 @@ * @filesource */ +// INITIALIZE THE CLASS --------------------------------------------------- + +$config = array(); +if (file_exists(APPPATH.'config/pagination'.EXT)) +{ + include_once(APPPATH.'config/pagination'.EXT); +} + +$obj =& get_instance(); +$obj->pagination =& new CI_Pagination($config); + // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 63dc023a2..5bc2eb5a3 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -13,6 +13,11 @@ * @filesource */ +// INITIALIZE THE CLASS --------------------------------------------------- + +$obj =& get_instance(); +$obj->parser =& new CI_Parser(); + // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 94efee55c..bcd2e4d7e 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -13,6 +13,11 @@ * @filesource */ +// INITIALIZE THE CLASS --------------------------------------------------- + +$obj =& get_instance(); +$obj->session =& new CI_Session(); + // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index 8f9680d44..9b6138453 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -13,6 +13,11 @@ * @filesource */ +// INITIALIZE THE CLASS --------------------------------------------------- + +$obj =& get_instance(); +$obj->trackback =& new CI_Trackback(); + // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index b2f4bf8cd..19fac79a7 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -13,6 +13,11 @@ * @filesource */ +// INITIALIZE THE CLASS --------------------------------------------------- + +$obj =& get_instance(); +$obj->unit =& new CI_Unit_test(); + // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 98edd654f..26f216544 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -13,6 +13,17 @@ * @filesource */ +// INITIALIZE THE CLASS --------------------------------------------------- + +$config = array(); +if (file_exists(APPPATH.'config/upload'.EXT)) +{ + include_once(APPPATH.'config/upload'.EXT); +} + +$obj =& get_instance(); +$obj->upload = new CI_Upload($config); + // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index b65b9be52..6c755a991 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -13,6 +13,11 @@ * @filesource */ +// INITIALIZE THE CLASS --------------------------------------------------- + +$obj =& get_instance(); +$obj->validation =& new CI_Validation(); + // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 9eeb46a15..b470f720a 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -18,6 +18,19 @@ if ( ! function_exists('xml_parser_create')) show_error('Your PHP installation does not support XML'); } +// INITIALIZE THE CLASS --------------------------------------------------- + +$config = array(); +if (file_exists(APPPATH.'config/xmlrpc'.EXT)) +{ + include_once(APPPATH.'config/xmlrpc'.EXT); +} + +$obj =& get_instance(); +$obj->xmlrpc = new CI_XML_RPC($config); + +// ------------------------------------------------------------------------ + /** * XML-RPC request handler class * diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 0543c3b78..4d50dfb96 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -12,7 +12,38 @@ * @since Version 1.0 * @filesource */ - + + +// INITIALIZE THE CLASS --------------------------------------------------- + +$config = array(); +if (file_exists(APPPATH.'config/xmlrpcs'.EXT)) +{ + include_once(APPPATH.'config/xmlrpcs'.EXT); +} + +if ( ! class_exists('CI_XML_RPC')) +{ + if ( ! file_exists(BASEPATH.'libraries/Xmlrpc'.EXT)) + { + if ( ! file_exists(APPPATH.'libraries/Xmlrpc'.EXT)) + { + show_error('Unable to locate the Xmlrpc class'); + } + else + { + require_once(APPPATH.'libraries/Xmlrpc'.EXT); + } + } + else + { + require_once(BASEPATH.'libraries/Xmlrpc'.EXT); + } +} + +$obj =& get_instance(); +$obj->xmlrpcs = new CI_XML_RPC_Server($config); + // ------------------------------------------------------------------------ /** -- cgit v1.2.3-24-g4f1b From 7981a9a752c339611ae10a252469f9dbc266fb96 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 26 Sep 2006 07:52:09 +0000 Subject: --- system/libraries/Calendar.php | 2 +- system/libraries/Controller.php | 137 +++++++++++++++++++++++++++------------- system/libraries/Email.php | 2 +- system/libraries/Encrypt.php | 2 +- system/libraries/Image_lib.php | 2 +- system/libraries/Loader.php | 23 +------ system/libraries/Pagination.php | 2 +- system/libraries/Parser.php | 2 +- system/libraries/Session.php | 2 +- system/libraries/Unit_test.php | 2 +- system/libraries/Upload.php | 2 +- system/libraries/Validation.php | 2 +- system/libraries/Xmlrpc.php | 26 +++----- system/libraries/Xmlrpcs.php | 57 ++++++++--------- 14 files changed, 142 insertions(+), 121 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index a3c070390..bde98113a 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -16,7 +16,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->calendar =& new CI_Calendar(); +$obj->init_class('CI_Calendar'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 97aa4b789..74b233ef3 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -32,6 +32,8 @@ class Controller extends CI_Base { var $_ci_models = array(); var $_ci_scaffolding = FALSE; var $_ci_scaff_table = FALSE; + var $_ci_last_handle = NULL; + var $_ci_last_params = NULL; /** * Constructor @@ -63,57 +65,117 @@ class Controller extends CI_Base { log_message('debug', "Controller Class Initialized"); } - // END Controller() // -------------------------------------------------------------------- /** * Initialization Handler * - * Looks for the existence of a handler method and calls it + * Designed to be called from the class files themselves. + * See: http://www.codeigniter.com/user_guide/general/creating_libraries.html + * + * @access public + * @param string class name + * @param string variable name + * @param mixed any additional parameters + * @return void + */ + function init_class($class, $varname = '', $params = NULL) + { + // First figure out what variable we're going to + // use to instantiate the class to + if ($varname == '') + { + $varname = ( ! is_null($this->_ci_last_handle)) ? $this->_ci_last_handle : strtolower(str_replace('CI_', '', $class)); + } + + // Are there any parameters? + if ($params === NULL AND $this->_ci_last_params !== NULL) + { + $params = $this->_ci_last_params; + } + + // Instantiate the class + if ( ! is_null($params)) + { + $this->$varname = new $class($params); + } + else + { + $this->$varname = new $class; + } + + $this->_ci_last_params = NULL; + $this->_ci_last_handle = NULL; + } + + // -------------------------------------------------------------------- + + /** + * Initialization Handler + * + * This function loads the requested class. * * @access private * @param string the item that is being loaded * @param mixed any additional parameters * @return void */ - function _ci_initialize($class, $params = FALSE) - { + function _ci_init_class($class, $params = NULL) + { + // Prep the class name $class = strtolower(str_replace(EXT, '', $class)); + + // These are used by $this->init_class() above. + // They lets us dynamically set the object name and pass parameters + $this->_ci_last_handle = $class; + $this->_ci_last_params = $params; + + // Does THIS file (Controller.php) contain an initialization + // function that maps to the requested class? + $method = '_ci_init_'.$class; - - if ( ! method_exists($this, $method)) - { - $class = ucfirst($class); - if ( ! file_exists(APPPATH.'libraries/'.$class.EXT)) + if (method_exists($this, $method)) + { + if (is_null($params)) { - if ( ! file_exists(BASEPATH.'libraries/'.$class.EXT)) - { - log_message('error', "Unable to load the requested class: ".$class); - show_error("Unable to load the class: ".$class); - } - - include_once(BASEPATH.'libraries/'.$class.EXT); + $this->$method(); } else { - include_once(APPPATH.'libraries/'.$class.EXT); - } + $this->$method($params); + } + + // We're done... + return TRUE; } - else + + // Lets search for the requested library file and load it. + // We'll assume that the file we load contains a call to + // $obj->init_class() so that the class can get instantiated. + // For backward compatibility we'll test for filenames that are + // both uppercase and lower. + + foreach (array(ucfirst($class), $class) as $filename) { - if ($params === FALSE) + for ($i = 1; $i < 3; $i++) { - $this->$method(); - } - else - { - $this->$method($params); + $path = ($i % 2) ? APPPATH : BASEPATH; + + if (file_exists($path.'libraries/'.$filename.EXT)) + { + include_once($path.'libraries/'.$filename.EXT); + return TRUE; + } } + } + + // If we got this far we were unable to find the requested class + log_message('error', "Unable to load the requested class: ".$class); + show_error("Unable to load the class: ".$class); } - // END _ci_initialize() // -------------------------------------------------------------------- @@ -124,7 +186,7 @@ class Controller extends CI_Base { * @param string * @return array */ - function _ci_load_model($model, $name = '', $db_conn = FALSE) + function _ci_init_model($model, $name = '', $db_conn = FALSE) { if ($name == '') { @@ -168,9 +230,7 @@ class Controller extends CI_Base { $this->$name = new $model(); $this->_ci_models[] = $name; $this->_ci_assign_to_models(); - } - // END _ci_load_model() - + } // -------------------------------------------------------------------- @@ -195,9 +255,7 @@ class Controller extends CI_Base { { $obj->$model->_assign_libraries(); } - } - // END _ci_assign_to_models() - + } // -------------------------------------------------------------------- @@ -245,13 +303,12 @@ class Controller extends CI_Base { foreach ($autoload['libraries'] as $item) { - $this->_ci_initialize($item); + $this->_ci_init_class($item); } unset($autoload['libraries']); return $autoload; } - // END _ci_autoload() // -------------------------------------------------------------------- @@ -282,7 +339,6 @@ class Controller extends CI_Base { $this->load = new CI_Loader(); } } - // END _ci_assign_core() // -------------------------------------------------------------------- @@ -311,7 +367,6 @@ class Controller extends CI_Base { $this->_ci_scaffolding = TRUE; $this->_ci_scaff_table = $table; } - // END _ci_init_scaffolding() // -------------------------------------------------------------------- @@ -324,7 +379,7 @@ class Controller extends CI_Base { * @return void */ function _ci_init_database($params = '', $return = FALSE, $active_record = FALSE) - { + { if ($this->_ci_is_loaded('db') == TRUE AND $return == FALSE AND $active_record == FALSE) { return; @@ -394,7 +449,6 @@ class Controller extends CI_Base { $obj =& get_instance(); $obj->db =& $DB; } - // END _ci_init_database() // -------------------------------------------------------------------- @@ -409,7 +463,6 @@ class Controller extends CI_Base { { return ( ! isset($this->$class) OR ! is_object($this->$class)) ? FALSE : TRUE; } - // END _ci_is_loaded() // -------------------------------------------------------------------- @@ -440,13 +493,11 @@ class Controller extends CI_Base { } $this->_ci_init_database("", FALSE, TRUE); - - $this->_ci_initialize('pagination'); + $this->_ci_init_class('pagination'); require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); $this->scaff = new Scaffolding($this->_ci_scaff_table); $this->scaff->$method(); } - // END _ci_scaffolding() } // END _Controller class diff --git a/system/libraries/Email.php b/system/libraries/Email.php index c153043d9..c9b9365ec 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -16,7 +16,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->email =& new CI_Email(); +$obj->init_class('CI_Email'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 446f64aa6..6a3ca17b0 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -16,7 +16,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->encrypt =& new CI_Encrypt(); +$obj->init_class('CI_Encrypt'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 86ed05943..4962760eb 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -22,7 +22,7 @@ if (file_exists(APPPATH.'config/image_lib'.EXT)) } $obj =& get_instance(); -$obj->image_lib =& new CI_Image_lib($config); +$obj->init_class('CI_Image_lib', '', $config); // ------------------------------------------------------------------------ diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 7449fa34a..df067cbc1 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -66,13 +66,13 @@ class CI_Loader { * @param mixed any initialization parameters * @return void */ - function library($class, $param = FALSE) + function library($class, $param = NULL) { if ($class == '') return; $obj =& get_instance(); - $obj->_ci_initialize($class, $param); + $obj->_ci_init_class($class, $param); $obj->_ci_assign_to_models(); } // END library() @@ -95,7 +95,7 @@ class CI_Loader { return; $obj =& get_instance(); - $obj->_ci_load_model($model, $name, $db_conn); + $obj->_ci_init_model($model, $name, $db_conn); } // END library() @@ -125,23 +125,6 @@ class CI_Loader { } } // END database() - - // -------------------------------------------------------------------- - - /** - * Database Utilities Loader - * - * @access public - * @param string the DB platform - * @param bool whether to return the DB object - * @return object - */ - function dbutil() - { - $obj =& get_instance(); - return $obj->_ci_init_dbutil($db, $return); - } - // END dbutils() // -------------------------------------------------------------------- diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index d83a2bd0f..cd55d56e0 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -22,7 +22,7 @@ if (file_exists(APPPATH.'config/pagination'.EXT)) } $obj =& get_instance(); -$obj->pagination =& new CI_Pagination($config); +$obj->init_class('CI_Pagination', '', $config); // ------------------------------------------------------------------------ diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 5bc2eb5a3..76182271f 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -16,7 +16,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->parser =& new CI_Parser(); +$obj->init_class('CI_Parser'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Session.php b/system/libraries/Session.php index bcd2e4d7e..76acbfea9 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -16,7 +16,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->session =& new CI_Session(); +$obj->init_class('CI_Session'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 19fac79a7..04c3c199b 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -16,7 +16,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->unit =& new CI_Unit_test(); +$obj->init_class('CI_Unit_test'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 26f216544..3a6a6fc34 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -22,7 +22,7 @@ if (file_exists(APPPATH.'config/upload'.EXT)) } $obj =& get_instance(); -$obj->upload = new CI_Upload($config); +$obj->init_class('CI_Upload', '', $config); // ------------------------------------------------------------------------ diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 6c755a991..34cacd5d8 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -16,7 +16,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->validation =& new CI_Validation(); +$obj->init_class('CI_Validation'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index b470f720a..24f79f2ba 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author Rick Ellis, Paul Burdick * @copyright Copyright (c) 2006, pMachine, Inc. * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com @@ -20,14 +20,8 @@ if ( ! function_exists('xml_parser_create')) // INITIALIZE THE CLASS --------------------------------------------------- -$config = array(); -if (file_exists(APPPATH.'config/xmlrpc'.EXT)) -{ - include_once(APPPATH.'config/xmlrpc'.EXT); -} - $obj =& get_instance(); -$obj->xmlrpc = new CI_XML_RPC($config); +$obj->init_class('CI_Xmlrpc'); // ------------------------------------------------------------------------ @@ -40,7 +34,7 @@ $obj->xmlrpc = new CI_XML_RPC($config); * @author Paul Burdick * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html */ -class CI_XML_RPC { +class CI_Xmlrpc { var $debug = FALSE; // Debugging on or off var $xmlrpcI4 = 'i4'; @@ -78,7 +72,7 @@ class CI_XML_RPC { // VALUES THAT MULTIPLE CLASSES NEED //------------------------------------- - function CI_XML_RPC ($config = array()) + function CI_Xmlrpc ($config = array()) { $this->xmlrpcName = $this->xmlrpcName; @@ -351,7 +345,7 @@ class CI_XML_RPC { * @author Paul Burdick * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html */ -class XML_RPC_Client extends CI_XML_RPC +class XML_RPC_Client extends CI_Xmlrpc { var $path = ''; var $server = ''; @@ -363,7 +357,7 @@ class XML_RPC_Client extends CI_XML_RPC function XML_RPC_Client($path, $server, $port=80) { - parent::CI_XML_RPC(); + parent::CI_Xmlrpc(); $this->port = $port; $this->server = $server; @@ -609,7 +603,7 @@ class XML_RPC_Response * @author Paul Burdick * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html */ -class XML_RPC_Message extends CI_XML_RPC +class XML_RPC_Message extends CI_Xmlrpc { var $payload; var $method_name; @@ -618,7 +612,7 @@ class XML_RPC_Message extends CI_XML_RPC function XML_RPC_Message($method, $pars=0) { - parent::CI_XML_RPC(); + parent::CI_Xmlrpc(); $this->method_name = $method; if (is_array($pars) && sizeof($pars) > 0) @@ -1206,14 +1200,14 @@ class XML_RPC_Message extends CI_XML_RPC * @author Paul Burdick * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html */ -class XML_RPC_Values extends CI_XML_RPC +class XML_RPC_Values extends CI_Xmlrpc { var $me = array(); var $mytype = 0; function XML_RPC_Values($val=-1, $type='') { - parent::CI_XML_RPC(); + parent::CI_Xmlrpc(); if ($val != -1 || $type != '') { diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 4d50dfb96..a95764a98 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author Rick Ellis, Paul Burdick * @copyright Copyright (c) 2006, pMachine, Inc. * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com @@ -13,36 +13,18 @@ * @filesource */ +if ( ! function_exists('xml_parser_create')) +{ + show_error('Your PHP installation does not support XML'); +} + // INITIALIZE THE CLASS --------------------------------------------------- -$config = array(); -if (file_exists(APPPATH.'config/xmlrpcs'.EXT)) -{ - include_once(APPPATH.'config/xmlrpcs'.EXT); -} +require_once(BASEPATH.'libraries/Xmlrpc'.EXT); -if ( ! class_exists('CI_XML_RPC')) -{ - if ( ! file_exists(BASEPATH.'libraries/Xmlrpc'.EXT)) - { - if ( ! file_exists(APPPATH.'libraries/Xmlrpc'.EXT)) - { - show_error('Unable to locate the Xmlrpc class'); - } - else - { - require_once(APPPATH.'libraries/Xmlrpc'.EXT); - } - } - else - { - require_once(BASEPATH.'libraries/Xmlrpc'.EXT); - } -} - -$obj =& get_instance(); -$obj->xmlrpcs = new CI_XML_RPC_Server($config); +// The initialization code is at the bottom of this file. It seems to +// cause an error to have it at the top // ------------------------------------------------------------------------ @@ -55,7 +37,7 @@ $obj->xmlrpcs = new CI_XML_RPC_Server($config); * @author Paul Burdick * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html */ -class CI_XML_RPC_Server extends CI_XML_RPC +class CI_Xmlrpcs extends CI_Xmlrpc { var $methods = array(); //array of methods mapped to function names and signatures var $debug_msg = ''; // Debug Message @@ -67,9 +49,9 @@ class CI_XML_RPC_Server extends CI_XML_RPC // Constructor, more or less //------------------------------------- - function CI_XML_RPC_Server($config=array()) + function CI_Xmlrpcs($config=array()) { - parent::CI_XML_RPC(); + parent::CI_Xmlrpc(); $this->set_system_methods(); if (isset($config['functions']) && is_array($config['functions'])) @@ -235,7 +217,7 @@ class CI_XML_RPC_Server extends CI_XML_RPC echo ""; } - $r = $this->execute($m); + $r = $this->_execute($m); } //------------------------------------- @@ -508,7 +490,7 @@ class CI_XML_RPC_Server extends CI_XML_RPC $msg->params[] = $params->me['array'][$i]; } - $result = $this->execute($msg); + $result = $this->_execute($msg); if ($result->faultCode() != 0) { @@ -520,4 +502,15 @@ class CI_XML_RPC_Server extends CI_XML_RPC } // END XML_RPC_Server class + + +// INITIALIZE THE CLASS --------------------------------------------------- + +$obj =& get_instance(); +$obj->init_class('CI_Xmlrpc'); +$obj->init_class('CI_Xmlrpcs'); + +// ------------------------------------------------------------------------ + + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 6e00bab0ecfbbdd35d135a297d54a4989a44e500 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 26 Sep 2006 08:13:06 +0000 Subject: --- system/libraries/Controller.php | 28 +++++++++++++++++++++++- system/libraries/Loader.php | 47 ++++++++++++++++++++++++----------------- 2 files changed, 55 insertions(+), 20 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 74b233ef3..9d858e6c2 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -301,9 +301,18 @@ class Controller extends CI_Base { } + $exceptions = array('dbutil', 'dbexport'); + foreach ($autoload['libraries'] as $item) { - $this->_ci_init_class($item); + if ( ! in_array($item, $exceptions)) + { + $this->_ci_init_class($item); + } + else + { + $this->_ci_init_dbextra($item); + } } unset($autoload['libraries']); @@ -452,6 +461,23 @@ class Controller extends CI_Base { // -------------------------------------------------------------------- + /** + * Initialize Database Ancillary Classes + * + * @access private + * @param str class name + * @return void + */ + function _ci_init_dbextra($class) + { + $map = array('dbutil' => 'DB_utility', 'dbexport' => 'DB_export'); + require_once(BASEPATH.'database/'.$map[$class].EXT); + + $this->init_class('CI_'.$map[$class], $class); + } + + // -------------------------------------------------------------------- + /** * Returns TRUE if a class is loaded, FALSE if not * diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index df067cbc1..90d824049 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -51,7 +51,6 @@ class CI_Loader { log_message('debug', "Loader Class Initialized"); } - // END CI_Loader() // -------------------------------------------------------------------- @@ -75,7 +74,6 @@ class CI_Loader { $obj->_ci_init_class($class, $param); $obj->_ci_assign_to_models(); } - // END library() // -------------------------------------------------------------------- @@ -97,7 +95,6 @@ class CI_Loader { $obj =& get_instance(); $obj->_ci_init_model($model, $name, $db_conn); } - // END library() // -------------------------------------------------------------------- @@ -124,10 +121,37 @@ class CI_Loader { $obj->_ci_assign_to_models(); } } - // END database() // -------------------------------------------------------------------- + /** + * Database Utiliy Loader + * + * @access public + * @return object + */ + function dbutil() + { + $obj =& get_instance(); + $obj->_ci_init_dbextra('dbutil'); + } + + // -------------------------------------------------------------------- + + /** + * Database Export Loader + * + * @access public + * @return object + */ + function dbexport() + { + $obj =& get_instance(); + $obj->_ci_init_dbextra('dbexport'); + } + + // -------------------------------------------------------------------- + /** * Scaffolding Loader * @@ -145,7 +169,6 @@ class CI_Loader { $obj =& get_instance(); $obj->_ci_init_scaffolding($table); } - // END scaffolding() // -------------------------------------------------------------------- @@ -170,7 +193,6 @@ class CI_Loader { { return $this->_ci_load(array('view' => $view, 'vars' => $this->_ci_object_to_array($vars), 'return' => $return)); } - // END view() // -------------------------------------------------------------------- @@ -188,7 +210,6 @@ class CI_Loader { { return $this->_ci_load(array('path' => $path, 'return' => $return)); } - // END file() // -------------------------------------------------------------------- @@ -214,7 +235,6 @@ class CI_Loader { } } } - // END vars() // -------------------------------------------------------------------- @@ -264,7 +284,6 @@ class CI_Loader { log_message('debug', 'Helpers loaded: '.implode(', ', $helpers)); } - // END helper() // -------------------------------------------------------------------- @@ -282,7 +301,6 @@ class CI_Loader { { $this->helper($helpers); } - // END helpers() // -------------------------------------------------------------------- @@ -332,7 +350,6 @@ class CI_Loader { log_message('debug', 'Plugins loaded: '.implode(', ', $plugins)); } - // END plugin() // -------------------------------------------------------------------- @@ -377,7 +394,6 @@ class CI_Loader { log_message('debug', 'Scripts loaded: '.implode(', ', $scripts)); } - // END script() // -------------------------------------------------------------------- @@ -395,7 +411,6 @@ class CI_Loader { { $this->plugin($plugins); } - // END plugins() // -------------------------------------------------------------------- @@ -411,7 +426,6 @@ class CI_Loader { $obj =& get_instance(); return $obj->lang->load($file, $lang, $return); } - // END language() // -------------------------------------------------------------------- @@ -427,7 +441,6 @@ class CI_Loader { $obj =& get_instance(); $obj->config->load($file); } - // END config() // -------------------------------------------------------------------- @@ -442,7 +455,6 @@ class CI_Loader { { $this->view_path = $path; } - // END _ci_set_view_path() // -------------------------------------------------------------------- @@ -553,7 +565,6 @@ class CI_Loader { ob_end_clean(); } } - // END _load() // -------------------------------------------------------------------- @@ -582,7 +593,6 @@ class CI_Loader { } } } - // END _ci_autoloader() // -------------------------------------------------------------------- @@ -599,7 +609,6 @@ class CI_Loader { { return (is_object($object)) ? get_object_vars($object) : $object; } - // END _ci_object_to_array() } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 41a1685573aa0ede15a9bf7b373c36a0406fb19d Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 26 Sep 2006 18:17:19 +0000 Subject: --- system/libraries/Controller.php | 4 +--- system/libraries/Email.php | 8 +++++++- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 9d858e6c2..23c050e18 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -82,8 +82,7 @@ class Controller extends CI_Base { */ function init_class($class, $varname = '', $params = NULL) { - // First figure out what variable we're going to - // use to instantiate the class to + // First figure out what variable we're going to assign the class to if ($varname == '') { $varname = ( ! is_null($this->_ci_last_handle)) ? $this->_ci_last_handle : strtolower(str_replace('CI_', '', $class)); @@ -156,7 +155,6 @@ class Controller extends CI_Base { // $obj->init_class() so that the class can get instantiated. // For backward compatibility we'll test for filenames that are // both uppercase and lower. - foreach (array(ucfirst($class), $class) as $filename) { for ($i = 1; $i < 3; $i++) diff --git a/system/libraries/Email.php b/system/libraries/Email.php index c9b9365ec..fd3fb8f17 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -15,8 +15,14 @@ // INITIALIZE THE CLASS --------------------------------------------------- +$config = array(); +if (file_exists(APPPATH.'config/email'.EXT)) +{ + include_once(APPPATH.'config/email'.EXT); +} + $obj =& get_instance(); -$obj->init_class('CI_Email'); +$obj->init_class('CI_Email', 'email', $config); // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From e5bb936f808bfd39a6ba8cbe1fc2ddbcf9bf502f Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 27 Sep 2006 00:31:22 +0000 Subject: --- system/libraries/Controller.php | 20 ++++++++++++++++---- system/libraries/Xmlrpcs.php | 20 ++++++-------------- 2 files changed, 22 insertions(+), 18 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 23c050e18..56b4d6f90 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -468,10 +468,22 @@ class Controller extends CI_Base { */ function _ci_init_dbextra($class) { - $map = array('dbutil' => 'DB_utility', 'dbexport' => 'DB_export'); - require_once(BASEPATH.'database/'.$map[$class].EXT); - - $this->init_class('CI_'.$map[$class], $class); + if ( ! $this->_ci_is_loaded('db')) + { + $this->_init_database(); + } + + if ($class == 'dbutil') + { + require_once(BASEPATH.'database/DB_utility'.EXT); + require_once(BASEPATH.'database/drivers/'.$this->db->dbdriver.'/'.$this->db->dbdriver.'_utility'.EXT); + $this->init_class('CI_DB_'.$this->db->dbdriver.'_utility', 'dbutil'); + } + elseif ($class == 'dbexport') + { + require_once(BASEPATH.'database/DB_export'.EXT); + $this->init_class('CI_DB_export', 'dbexport'); + } } // -------------------------------------------------------------------- diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index a95764a98..f41437342 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -18,13 +18,15 @@ if ( ! function_exists('xml_parser_create')) show_error('Your PHP installation does not support XML'); } +if ( ! class_exists('CI_Xmlrpc')) +{ + show_error('You must load the Xmlrpc class before loading the Xmlrpcs class in order to create a server.'); +} // INITIALIZE THE CLASS --------------------------------------------------- -require_once(BASEPATH.'libraries/Xmlrpc'.EXT); - -// The initialization code is at the bottom of this file. It seems to -// cause an error to have it at the top +$obj =& get_instance(); +$obj->init_class('CI_Xmlrpcs'); // ------------------------------------------------------------------------ @@ -503,14 +505,4 @@ class CI_Xmlrpcs extends CI_Xmlrpc } // END XML_RPC_Server class - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Xmlrpc'); -$obj->init_class('CI_Xmlrpcs'); - -// ------------------------------------------------------------------------ - - ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 17a890df20b56c8d82812f365f27bc590be009f3 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 27 Sep 2006 20:42:42 +0000 Subject: --- system/libraries/Router.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index d7740f5f3..34a2512a6 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -65,7 +65,9 @@ class CI_Router { */ function _set_route_mapping() { - // Are query strings enabled? If so we're done... + + // Are query strings enabled in the config file? + // If so, we're done since segment based URIs are not used with query strings. if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) { $this->set_class($_GET[$this->config->item('controller_trigger')]); @@ -78,15 +80,26 @@ class CI_Router { return; } - // Load the routes.php file and set the default controller + // Load the routes.php file. @include_once(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']); + // Fetch the complete URI string + $this->uri_string = $this->_get_uri_string(); + + // If the URI contains only a slash we'll kill it + if ($this->uri_string == '/') + { + $this->uri_string = ''; + } + // Is there a URI string? If not, the default controller specified in the "routes" file will be shown. - if (($this->uri_string = $this->_get_uri_string()) == '') + if ($this->uri_string == '') { if ($this->default_controller === FALSE) { @@ -107,6 +120,7 @@ class CI_Router { $this->uri_string = preg_replace("|".preg_quote($this->config->item('url_suffix'))."$|", "", $this->uri_string); } + // Explode the URI Segments. The individual segments will // be stored in the $this->segments array. foreach(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val) -- cgit v1.2.3-24-g4f1b From 33de9a144aad28763405f8ae2d5c59df5e929b4f Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 28 Sep 2006 06:50:16 +0000 Subject: --- system/libraries/Benchmark.php | 9 --- system/libraries/Calendar.php | 5 -- system/libraries/Controller.php | 165 ++++++++++++++++++++++++---------------- system/libraries/Email.php | 11 --- system/libraries/Encrypt.php | 5 -- system/libraries/Hooks.php | 2 +- system/libraries/Image_lib.php | 11 --- system/libraries/Input.php | 2 +- system/libraries/Loader.php | 2 +- system/libraries/Output.php | 4 +- system/libraries/Pagination.php | 11 --- system/libraries/Parser.php | 5 -- system/libraries/Router.php | 21 +---- system/libraries/Session.php | 5 -- system/libraries/Trackback.php | 5 -- system/libraries/URI.php | 2 +- system/libraries/Unit_test.php | 5 -- system/libraries/Upload.php | 11 --- system/libraries/Validation.php | 5 -- system/libraries/Xmlrpc.php | 4 - system/libraries/Xmlrpcs.php | 5 -- 21 files changed, 109 insertions(+), 186 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index 9dd9d4ac4..d8dd903e7 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -31,15 +31,6 @@ class CI_Benchmark { var $marker = array(); - /** - * Constructor - * - * @access public - */ - function CI_Benchmark() - { - } - // END CI_Benchmark() // -------------------------------------------------------------------- diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index bde98113a..8c7d95aa5 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -13,11 +13,6 @@ * @filesource */ -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Calendar'); - // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 56b4d6f90..aa7b87b00 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -32,8 +32,6 @@ class Controller extends CI_Base { var $_ci_models = array(); var $_ci_scaffolding = FALSE; var $_ci_scaff_table = FALSE; - var $_ci_last_handle = NULL; - var $_ci_last_params = NULL; /** * Constructor @@ -68,48 +66,6 @@ class Controller extends CI_Base { // -------------------------------------------------------------------- - /** - * Initialization Handler - * - * Designed to be called from the class files themselves. - * See: http://www.codeigniter.com/user_guide/general/creating_libraries.html - * - * @access public - * @param string class name - * @param string variable name - * @param mixed any additional parameters - * @return void - */ - function init_class($class, $varname = '', $params = NULL) - { - // First figure out what variable we're going to assign the class to - if ($varname == '') - { - $varname = ( ! is_null($this->_ci_last_handle)) ? $this->_ci_last_handle : strtolower(str_replace('CI_', '', $class)); - } - - // Are there any parameters? - if ($params === NULL AND $this->_ci_last_params !== NULL) - { - $params = $this->_ci_last_params; - } - - // Instantiate the class - if ( ! is_null($params)) - { - $this->$varname = new $class($params); - } - else - { - $this->$varname = new $class; - } - - $this->_ci_last_params = NULL; - $this->_ci_last_handle = NULL; - } - - // -------------------------------------------------------------------- - /** * Initialization Handler * @@ -120,15 +76,21 @@ class Controller extends CI_Base { * @param mixed any additional parameters * @return void */ - function _ci_init_class($class, $params = NULL) + function _ci_load_class($class, $params = NULL) { // Prep the class name $class = strtolower(str_replace(EXT, '', $class)); - - // These are used by $this->init_class() above. - // They lets us dynamically set the object name and pass parameters - $this->_ci_last_handle = $class; - $this->_ci_last_params = $params; + + // Is this a class extension request? + if (substr($class, 0, 3) == 'my_') + { + $class = preg_replace("/my_(.+)/", "\\1", $class); + $extend = TRUE; + } + else + { + $extend = FALSE; + } // Does THIS file (Controller.php) contain an initialization // function that maps to the requested class? @@ -150,30 +112,101 @@ class Controller extends CI_Base { return TRUE; } - // Lets search for the requested library file and load it. - // We'll assume that the file we load contains a call to - // $obj->init_class() so that the class can get instantiated. - // For backward compatibility we'll test for filenames that are - // both uppercase and lower. - foreach (array(ucfirst($class), $class) as $filename) + // Are we extending one of the base classes? + if ($extend == TRUE) { - for ($i = 1; $i < 3; $i++) + // Load the requested library from the main system/libraries folder + if (file_exists(BASEPATH.'libraries/'.ucfirst($class).EXT)) { - $path = ($i % 2) ? APPPATH : BASEPATH; + include_once(BASEPATH.'libraries/'.ucfirst($class).EXT); + } - if (file_exists($path.'libraries/'.$filename.EXT)) + // Now look for a matching library + foreach (array(ucfirst($class), $class) as $filename) + { + if (file_exists(APPPATH.'libraries/'.$filename.EXT)) { - include_once($path.'libraries/'.$filename.EXT); - return TRUE; + include_once(APPPATH.'libraries/'.$filename.EXT); + } + } + + return $this->_ci_init_class($filename, 'MY_', $params); + } + else + { + // Lets search for the requested library file and load it. + // For backward compatibility we'll test for filenames that are + // both uppercase and lower. + foreach (array(ucfirst($class), $class) as $filename) + { + for ($i = 1; $i < 3; $i++) + { + $path = ($i % 2) ? APPPATH : BASEPATH; + + if (file_exists($path.'libraries/'.$filename.EXT)) + { + include_once($path.'libraries/'.$filename.EXT); + return $this->_ci_init_class($filename, '', $params); + } } } - } // If we got this far we were unable to find the requested class log_message('error', "Unable to load the requested class: ".$class); show_error("Unable to load the class: ".$class); } + + // -------------------------------------------------------------------- + + /** + * Instantiates a class + * + * @access private + * @param string + * @param string + * @return null + */ + function _ci_init_class($class, $prefix = '', $config = NULL) + { + // Is there an associated config file for this class? + + if ($config == NULL) + { + if (file_exists(APPPATH.'config/'.$class.EXT)) + { + include_once(APPPATH.'config/'.$class.EXT); + } + } + + if ($prefix == '') + { + $name = ( ! class_exists($class)) ? 'CI_'.$class : $class; + } + else + { + $name = $prefix.ucfirst($class); + } + + $remap = array( + 'DB_export' => 'dbexport', + 'DB_utility' => 'dbutility', + 'Encryption' => 'encrypt', + 'Unit_test' => 'unit' + ); + + $varname = ( ! isset($remap[$class])) ? $class : $remap[$class]; + + // Instantiate the class + if ($config !== NULL) + { + $this->$varname = new $name($config); + } + else + { + $this->$varname = new $name; + } + } // -------------------------------------------------------------------- @@ -305,7 +338,7 @@ class Controller extends CI_Base { { if ( ! in_array($item, $exceptions)) { - $this->_ci_init_class($item); + $this->_ci_load_class($item); } else { @@ -334,10 +367,10 @@ class Controller extends CI_Base { foreach (array('Config', 'Input', 'Benchmark', 'URI', 'Output') as $val) { $class = strtolower($val); - $this->$class =& _load_class('CI_'.$val); + $this->$class =& _load_class($val); } - $this->lang =& _load_class('CI_Language'); + $this->lang =& _load_class('Language'); // In PHP 4 the Controller class is a child of CI_Loader. // In PHP 5 we run it as its own class. @@ -529,7 +562,7 @@ class Controller extends CI_Base { } $this->_ci_init_database("", FALSE, TRUE); - $this->_ci_init_class('pagination'); + $this->_ci_load_class('pagination'); require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); $this->scaff = new Scaffolding($this->_ci_scaff_table); $this->scaff->$method(); diff --git a/system/libraries/Email.php b/system/libraries/Email.php index fd3fb8f17..5b991d1fa 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -13,17 +13,6 @@ * @filesource */ -// INITIALIZE THE CLASS --------------------------------------------------- - -$config = array(); -if (file_exists(APPPATH.'config/email'.EXT)) -{ - include_once(APPPATH.'config/email'.EXT); -} - -$obj =& get_instance(); -$obj->init_class('CI_Email', 'email', $config); - // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 6a3ca17b0..abc769460 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -12,11 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Encrypt'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index 7ff0592ff..69ca1a9f1 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -41,7 +41,7 @@ class CI_Hooks { { log_message('debug', "Hooks Class Initialized"); - $CFG =& _load_class('CI_Config'); + $CFG =& _load_class('Config'); // If hooks are not enabled in the config file // there is nothing else to do diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 4962760eb..18e3253f7 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -13,17 +13,6 @@ * @filesource */ -// INITIALIZE THE CLASS --------------------------------------------------- - -$config = array(); -if (file_exists(APPPATH.'config/image_lib'.EXT)) -{ - include_once(APPPATH.'config/image_lib'.EXT); -} - -$obj =& get_instance(); -$obj->init_class('CI_Image_lib', '', $config); - // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Input.php b/system/libraries/Input.php index dbf939b18..ad7b0c571 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -42,7 +42,7 @@ class CI_Input { */ function CI_Input() { - $CFG =& _load_class('CI_Config'); + $CFG =& _load_class('Config'); $this->use_xss_clean = ($CFG->item('global_xss_filtering') === TRUE) ? TRUE : FALSE; $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 90d824049..fff9e78d3 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -71,7 +71,7 @@ class CI_Loader { return; $obj =& get_instance(); - $obj->_ci_init_class($class, $param); + $obj->_ci_load_class($class, $param); $obj->_ci_assign_to_models(); } diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 5a158245f..1c3f0d604 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -237,8 +237,8 @@ class CI_Output { */ function _display_cache(&$CFG, &$RTR) { - $CFG =& _load_class('CI_Config'); - $RTR =& _load_class('CI_Router'); + $CFG =& _load_class('Config'); + $RTR =& _load_class('Router'); $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index cd55d56e0..867d214fc 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -12,17 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$config = array(); -if (file_exists(APPPATH.'config/pagination'.EXT)) -{ - include_once(APPPATH.'config/pagination'.EXT); -} - -$obj =& get_instance(); -$obj->init_class('CI_Pagination', '', $config); // ------------------------------------------------------------------------ diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 76182271f..42e78b0ee 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -12,11 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Parser'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 34a2512a6..c056530a3 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -33,6 +33,7 @@ class CI_Router { var $segments = array(); var $rsegments = array(); var $routes = array(); + var $error_routes = array(); var $class = ''; var $method = 'index'; var $directory = ''; @@ -47,7 +48,7 @@ class CI_Router { */ function CI_Router() { - $this->config =& _load_class('CI_Config'); + $this->config =& _load_class('Config'); $this->_set_route_mapping(); log_message('debug', "Router Class Initialized"); } @@ -87,8 +88,8 @@ class CI_Router { // 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']); + // Fetch the complete URI string $this->uri_string = $this->_get_uri_string(); @@ -138,7 +139,6 @@ class CI_Router { // Re-index the segment array so that it starts with 1 rather than 0 $this->_reindex_segments(); } - // END _set_route_mapping() // -------------------------------------------------------------------- @@ -185,7 +185,6 @@ class CI_Router { // identical to $this->segments $this->rsegments = $segments; } - // END _compile_segments() // -------------------------------------------------------------------- @@ -240,7 +239,6 @@ class CI_Router { // Can't find the requested controller... show_404(); } - // END _validate_segments() // -------------------------------------------------------------------- /** @@ -280,7 +278,6 @@ class CI_Router { unset($this->rsegments[0]); } } - // END _reindex_segments() // -------------------------------------------------------------------- @@ -333,7 +330,6 @@ class CI_Router { return getenv($uri); } } - // END _get_uri_string() // -------------------------------------------------------------------- @@ -381,7 +377,6 @@ class CI_Router { return $parsed_uri; } - // END _parse_request_uri() // -------------------------------------------------------------------- @@ -403,7 +398,6 @@ class CI_Router { } return $str; } - // END _filter_uri() // -------------------------------------------------------------------- @@ -461,7 +455,6 @@ class CI_Router { // matching route so we'll set the site default route $this->_compile_segments($this->segments); } - // END set_method() // -------------------------------------------------------------------- @@ -476,7 +469,6 @@ class CI_Router { { $this->class = $class; } - // END set_class() // -------------------------------------------------------------------- @@ -490,7 +482,6 @@ class CI_Router { { return $this->class; } - // END fetch_class() // -------------------------------------------------------------------- @@ -505,7 +496,6 @@ class CI_Router { { $this->method = $method; } - // END set_method() // -------------------------------------------------------------------- @@ -519,7 +509,6 @@ class CI_Router { { return $this->method; } - // END fetch_method() // -------------------------------------------------------------------- @@ -534,7 +523,6 @@ class CI_Router { { $this->directory = $dir.'/'; } - // END set_directory() // -------------------------------------------------------------------- @@ -548,7 +536,6 @@ class CI_Router { { return $this->directory; } - // END fetch_directory() } // END Router Class diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 76acbfea9..28e469da7 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -12,11 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Session'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index 9b6138453..8b6cce16d 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -12,11 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->trackback =& new CI_Trackback(); // ------------------------------------------------------------------------ diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 89ca42e44..80b112660 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -42,7 +42,7 @@ class CI_URI { */ function CI_URI() { - $this->router =& _load_class('CI_Router'); + $this->router =& _load_class('Router'); log_message('debug', "URI Class Initialized"); } diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 04c3c199b..b2f4bf8cd 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -13,11 +13,6 @@ * @filesource */ -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Unit_test'); - // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 3a6a6fc34..091c6c30d 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -12,17 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$config = array(); -if (file_exists(APPPATH.'config/upload'.EXT)) -{ - include_once(APPPATH.'config/upload'.EXT); -} - -$obj =& get_instance(); -$obj->init_class('CI_Upload', '', $config); // ------------------------------------------------------------------------ diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 34cacd5d8..80ee6a533 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -12,11 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Validation'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 24f79f2ba..f90785430 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -18,10 +18,6 @@ if ( ! function_exists('xml_parser_create')) show_error('Your PHP installation does not support XML'); } -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Xmlrpc'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index f41437342..b47104857 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -23,11 +23,6 @@ if ( ! class_exists('CI_Xmlrpc')) show_error('You must load the Xmlrpc class before loading the Xmlrpcs class in order to create a server.'); } -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Xmlrpcs'); - // ------------------------------------------------------------------------ /** -- cgit v1.2.3-24-g4f1b From 4ce59da7905eca21a6cc3be04adfbcab672a9969 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 28 Sep 2006 07:45:59 +0000 Subject: --- system/libraries/Controller.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index aa7b87b00..f00a7262b 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -219,6 +219,20 @@ class Controller extends CI_Base { */ function _ci_init_model($model, $name = '', $db_conn = FALSE) { + // Is the model in a sub-folder? + // If so, parse out the filename and path. + if (strpos($model, '/') === FALSE) + { + $path = ''; + } + else + { + $x = explode('/', $model); + $model = end($x); + unset($x[count($x)-1]); + $path = implode('/', $x).'/'; + } + if ($name == '') { $name = $model; @@ -237,11 +251,11 @@ class Controller extends CI_Base { $model = strtolower($model); - if ( ! file_exists(APPPATH.'models/'.$model.EXT)) + if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT)) { show_error('Unable to locate the model you have specified: '.$model); } - + if ($db_conn !== FALSE) { if ($db_conn === TRUE) @@ -255,7 +269,7 @@ class Controller extends CI_Base { require_once(BASEPATH.'libraries/Model'.EXT); } - require_once(APPPATH.'models/'.$model.EXT); + require_once(APPPATH.'models/'.$path.$model.EXT); $model = ucfirst($model); $this->$name = new $model(); -- cgit v1.2.3-24-g4f1b From e721cc7c81af84dcabce2992fa693ce36b605a19 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 28 Sep 2006 16:47:05 +0000 Subject: --- system/libraries/Unit_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index b2f4bf8cd..d3e151328 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -57,8 +57,8 @@ class CI_Unit_test { if ($this->active == FALSE) return; - if (in_array($expected, array('is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'))) - { + if ($expected !== 0 AND in_array($expected, array('is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'))) + { $expected = str_replace('is_float', 'is_double', $expected); $result = ($expected($test)) ? TRUE : FALSE; $extype = str_replace(array('true', 'false'), 'bool', str_replace('is_', '', $expected)); -- cgit v1.2.3-24-g4f1b From ee54c112bfb488f833fa032758b817e1bb2c1d7d Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 28 Sep 2006 17:13:38 +0000 Subject: --- system/libraries/Calendar.php | 4 ++-- system/libraries/Config.php | 2 +- system/libraries/Controller.php | 6 +++--- system/libraries/Email.php | 6 +++--- system/libraries/Image_lib.php | 2 +- system/libraries/Language.php | 2 +- system/libraries/Unit_test.php | 2 +- system/libraries/Upload.php | 4 ++-- system/libraries/Validation.php | 6 +++--- system/libraries/Xmlrpc.php | 2 +- 10 files changed, 18 insertions(+), 18 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 8c7d95aa5..8cf151703 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -48,7 +48,7 @@ class CI_Calendar { function CI_Calendar() { $this->obj =& get_instance(); - if ( ! in_array('calendar_lang'.EXT, $this->obj->lang->is_loaded)) + if ( ! in_array('calendar_lang'.EXT, $this->obj->lang->is_loaded, TRUE)) { $this->obj->lang->load('calendar'); } @@ -458,7 +458,7 @@ class CI_Calendar { } else { - if (in_array($val, $today)) + if (in_array($val, $today, TRUE)) { $this->temp[$val] = $this->temp[str_replace('_today', '', $val)]; } diff --git a/system/libraries/Config.php b/system/libraries/Config.php index 108c94ab7..26770cc4f 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -63,7 +63,7 @@ class CI_Config { { $file = ($file == '') ? 'config' : str_replace(EXT, '', $file); - if (in_array($file, $this->is_loaded)) + if (in_array($file, $this->is_loaded, TRUE)) { return TRUE; } diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index f00a7262b..ff914d131 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -239,7 +239,7 @@ class Controller extends CI_Base { } $obj =& get_instance(); - if (in_array($name, $obj->_ci_models)) + if (in_array($name, $obj->_ci_models, TRUE)) { return; } @@ -350,7 +350,7 @@ class Controller extends CI_Base { foreach ($autoload['libraries'] as $item) { - if ( ! in_array($item, $exceptions)) + if ( ! in_array($item, $exceptions, TRUE)) { $this->_ci_load_class($item); } @@ -566,7 +566,7 @@ class Controller extends CI_Base { if (class_exists('Scaffolding')) return; - if ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'))) + if ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) { $method = 'view'; } diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 5b991d1fa..55edd6216 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -467,7 +467,7 @@ class CI_Email { */ function set_protocol($protocol = 'mail') { - $this->protocol = ( ! in_array($protocol, $this->_protocols)) ? 'mail' : strtolower($protocol); + $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol); } // END set_protocol() @@ -564,7 +564,7 @@ class CI_Email { function _get_protocol($return = true) { $this->protocol = strtolower($this->protocol); - $this->protocol = ( ! in_array($this->protocol, $this->_protocols)) ? 'mail' : $this->protocol; + $this->protocol = ( ! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol; if ($return == true) return $this->protocol; @@ -584,7 +584,7 @@ class CI_Email { { $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '7bit' : $this->_encoding; - if ( ! in_array($this->charset, $this->_base_charsets)) + if ( ! in_array($this->charset, $this->_base_charsets, TRUE)) $this->_encoding = "8bit"; if ($return == true) diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 18e3253f7..ca1d7478b 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -398,7 +398,7 @@ class CI_Image_lib { // Allowed rotation values $degs = array(90, 180, 270, 'vrt', 'hor'); - if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs)) + if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs, TRUE)) { $this->set_error('imglib_rotation_angle_required'); return FALSE; diff --git a/system/libraries/Language.php b/system/libraries/Language.php index 41dab46f4..dabfd4145 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -54,7 +54,7 @@ class CI_Language { { $langfile = str_replace(EXT, '', str_replace('_lang.', '', $langfile)).'_lang'.EXT; - if (in_array($langfile, $this->is_loaded)) + if (in_array($langfile, $this->is_loaded, TRUE)) { return; } diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index d3e151328..78b92edb2 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -57,7 +57,7 @@ class CI_Unit_test { if ($this->active == FALSE) return; - if ($expected !== 0 AND in_array($expected, array('is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'))) + if (in_array($expected, array('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; diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 091c6c30d..37fccdfd8 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -454,7 +454,7 @@ class CI_Upload { ); - return (in_array($this->file_type, $img_mimes)) ? TRUE : FALSE; + return (in_array($this->file_type, $img_mimes, TRUE)) ? TRUE : FALSE; } // -------------------------------------------------------------------- @@ -479,7 +479,7 @@ class CI_Upload { if (is_array($mime)) { - if (in_array($this->file_type, $mime)) + if (in_array($this->file_type, $mime, TRUE)) { return TRUE; } diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 80ee6a533..7db67a3e1 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -187,7 +187,7 @@ class CI_Validation { $ex = explode('|', $rules); // Is the field required? If not, if the field is blank we'll move on to the next text - if ( ! in_array('required', $ex) AND strpos($rules, 'callback_') === FALSE) + if ( ! in_array('required', $ex, TRUE) AND strpos($rules, 'callback_') === FALSE) { if ( ! isset($_POST[$field]) OR $_POST[$field] == '') { @@ -206,7 +206,7 @@ class CI_Validation { */ if ( ! isset($_POST[$field])) { - if (in_array('isset', $ex) OR in_array('required', $ex)) + if (in_array('isset', $ex, TRUE) OR in_array('required', $ex)) { if ( ! isset($this->_error_messages['isset'])) { @@ -268,7 +268,7 @@ class CI_Validation { $result = $this->obj->$rule($_POST[$field], $param); // If the field isn't required and we just processed a callback we'll move on... - if ( ! in_array('required', $ex) AND $result !== FALSE) + if ( ! in_array('required', $ex, TRUE) AND $result !== FALSE) { continue 2; } diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index f90785430..4cb16f74e 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -854,7 +854,7 @@ class XML_RPC_Message extends CI_Xmlrpc else { // not top level element: see if parent is OK - if (!in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name])) + if (!in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name], TRUE)) { $this->xh[$the_parser]['isf'] = 2; $this->xh[$the_parser]['isf_reason'] = "XML-RPC element $name cannot be child of ".$this->xh[$the_parser]['stack'][0]; -- cgit v1.2.3-24-g4f1b From 4a2ed69c3af500ca51bddcc9b6c54bebb2bfeae8 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 29 Sep 2006 01:14:52 +0000 Subject: --- system/libraries/Controller.php | 1 - 1 file changed, 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index ff914d131..be66b19b7 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -191,7 +191,6 @@ class Controller extends CI_Base { $remap = array( 'DB_export' => 'dbexport', 'DB_utility' => 'dbutility', - 'Encryption' => 'encrypt', 'Unit_test' => 'unit' ); -- cgit v1.2.3-24-g4f1b From 3ed8c51254a5b26d951fa675802fcf69adf9638e Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 29 Sep 2006 23:26:28 +0000 Subject: --- system/libraries/Controller.php | 12 +++--------- system/libraries/Encrypt.php | 35 ++++++++++++++++++++--------------- system/libraries/Loader.php | 14 -------------- 3 files changed, 23 insertions(+), 38 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index be66b19b7..51f455023 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -189,8 +189,6 @@ class Controller extends CI_Base { } $remap = array( - 'DB_export' => 'dbexport', - 'DB_utility' => 'dbutility', 'Unit_test' => 'unit' ); @@ -516,19 +514,15 @@ class Controller extends CI_Base { { if ( ! $this->_ci_is_loaded('db')) { - $this->_init_database(); + $this->_ci_init_database(); } if ($class == 'dbutil') { require_once(BASEPATH.'database/DB_utility'.EXT); require_once(BASEPATH.'database/drivers/'.$this->db->dbdriver.'/'.$this->db->dbdriver.'_utility'.EXT); - $this->init_class('CI_DB_'.$this->db->dbdriver.'_utility', 'dbutil'); - } - elseif ($class == 'dbexport') - { - require_once(BASEPATH.'database/DB_export'.EXT); - $this->init_class('CI_DB_export', 'dbexport'); + $class = 'CI_DB_'.$this->db->dbdriver.'_utility'; + $this->dbutil = new $class(); } } diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index abc769460..537b1ab20 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -27,6 +27,7 @@ * @link http://www.codeigniter.com/user_guide/libraries/encryption.html */ class CI_Encrypt { + var $encryption_key = ''; var $_hash_type = 'sha1'; var $_mcrypt_exists = FALSE; var $_mcrypt_cipher; @@ -43,7 +44,6 @@ class CI_Encrypt { $this->_mcrypt_exists = ( ! function_exists('mcrypt_encrypt')) ? FALSE : TRUE; log_message('debug', "Encrypt Class Initialized"); } - // END CI_Encrypt() // -------------------------------------------------------------------- @@ -61,6 +61,11 @@ class CI_Encrypt { { if ($key == '') { + if ($this->encryption_key != '') + { + return $this->encryption_key; + } + $obj =& get_instance(); $key = $obj->config->item('encryption_key'); @@ -72,7 +77,20 @@ class CI_Encrypt { return md5($key); } - // END get_key() + + // -------------------------------------------------------------------- + + /** + * Set the encryption key + * + * @access public + * @param string + * @return void + */ + function set_key($key = '') + { + $this->encryption_key = $key; + } // -------------------------------------------------------------------- @@ -103,7 +121,6 @@ class CI_Encrypt { } return base64_encode($enc); } - // END encode() // -------------------------------------------------------------------- @@ -134,7 +151,6 @@ class CI_Encrypt { return $this->_xor_decode($dec, $key); } - // END decode() // -------------------------------------------------------------------- @@ -167,7 +183,6 @@ class CI_Encrypt { return $this->_xor_merge($enc, $key); } - // END _xor_encode() // -------------------------------------------------------------------- @@ -194,7 +209,6 @@ class CI_Encrypt { return $dec; } - // END _xor_decode() // -------------------------------------------------------------------- @@ -219,7 +233,6 @@ class CI_Encrypt { return $str; } - // END _xor_merge() // -------------------------------------------------------------------- @@ -238,7 +251,6 @@ class CI_Encrypt { $init_vect = mcrypt_create_iv($init_size, MCRYPT_RAND); return mcrypt_encrypt($this->_mcrypt_cipher, $key, $data, $this->_mcrypt_mode, $init_vect); } - // END mcrypt_encode() // -------------------------------------------------------------------- @@ -257,7 +269,6 @@ class CI_Encrypt { $init_vect = mcrypt_create_iv($init_size, MCRYPT_RAND); return rtrim(mcrypt_decrypt($this->_mcrypt_cipher, $key, $data, $this->_mcrypt_mode, $init_vect), "\0"); } - // END mcrypt_decode() // -------------------------------------------------------------------- @@ -272,7 +283,6 @@ class CI_Encrypt { { $this->_mcrypt_cipher = $cypher; } - // END set_cypher() // -------------------------------------------------------------------- @@ -287,7 +297,6 @@ class CI_Encrypt { { $this->_mcrypt_mode = $mode; } - // END set_mode() // -------------------------------------------------------------------- @@ -309,7 +318,6 @@ class CI_Encrypt { $this->_mcrypt_mode = MCRYPT_MODE_ECB; } } - // END _get_mcrypt() // -------------------------------------------------------------------- @@ -324,7 +332,6 @@ class CI_Encrypt { { $this->_hash_type = ($type != 'sha1' AND $type != 'md5') ? 'sha1' : $type; } - // END set_hash() // -------------------------------------------------------------------- @@ -339,7 +346,6 @@ class CI_Encrypt { { return ($this->_hash_type == 'sha1') ? $this->sha1($str) : md5($str); } - // END hash() // -------------------------------------------------------------------- @@ -370,7 +376,6 @@ class CI_Encrypt { return sha1($str); } } - // END sha1() } diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index fff9e78d3..2534e6965 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -135,20 +135,6 @@ class CI_Loader { $obj =& get_instance(); $obj->_ci_init_dbextra('dbutil'); } - - // -------------------------------------------------------------------- - - /** - * Database Export Loader - * - * @access public - * @return object - */ - function dbexport() - { - $obj =& get_instance(); - $obj->_ci_init_dbextra('dbexport'); - } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From ae58a5de4fc040847c43209173dbc7f1193f6c53 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 30 Sep 2006 19:25:07 +0000 Subject: --- system/libraries/Zip.php | 154 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 system/libraries/Zip.php (limited to 'system/libraries') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php new file mode 100644 index 000000000..9cfe9593d --- /dev/null +++ b/system/libraries/Zip.php @@ -0,0 +1,154 @@ +cdata[] = $fd; + + $cd = "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" + .pack("V", 0) + .pack("V", 0) + .pack("V", 0) + .pack("v", strlen ($name)) + .pack("v", 0) + .pack("v", 0) + .pack("v", 0) + .pack("v", 0) + .pack("V", 16) + .pack("V", $this->offset) + .$name; + + $this->offset = strlen(implode('', $this->cdata)); + + $this->cdir[] = $cd; + } + + // -------------------------------------------------------------------- + + /** + * Add a File + * + * @access public + * @param string + * @return void + */ + function add_file($data, $name) + { + $name = str_replace("\\", "/", $name); + + $u_len = strlen($data); + $crc = crc32($data); + $data = gzcompress($data); + $data = substr(substr($data, 0,strlen ($data) - 4), 2); + $c_len = strlen($data); + + $fd = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" + .pack("V", $crc) + .pack("V", $c_len) + .pack("V", $u_len) + .pack("v", strlen($name)) + .pack("v", 0) + .$name + .$data + .pack("V", $crc) + .pack("V", $c_len) + .pack("V", $u_len); + + $this->zdata[] = $fd; + + $cd = "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" + .pack("V", $crc) + .pack("V", $c_len) + .pack("V", $u_len) + .pack("v", strlen ($name)) + .pack("v", 0) + .pack("v", 0) + .pack("v", 0) + .pack("v", 0) + .pack("V", 32 ) + .pack("V", $this->offset) + .$name; + + $this->offset = strlen(implode('', $this->zdata)); + + $this->cdir[] = $cd; + } + + // -------------------------------------------------------------------- + + /** + * Output the zip file + * + * @access public + * @return string + */ + function output_zipfile() + { + $data = implode("", $this->zdata); + $cdir = implode("", $this->cdir); + + return $data + .$cdir + ."\x50\x4b\x05\x06\x00\x00\x00\x00" + .pack("v", sizeof($this->cdir)) + .pack("v", sizeof($this->cdir)) + .pack("V", strlen($cdir)) + .pack("V", strlen($data)) + ."\x00\x00"; + } + +} +// END CLASS +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c8b7bdab0d17319c4f4c7860c7d41bb6efcf17c1 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 30 Sep 2006 19:26:08 +0000 Subject: --- system/libraries/Zip.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 9cfe9593d..1fd0e7059 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -21,7 +21,8 @@ * This class is based on a library aquired at Zend: * http://www.zend.com/codex.php?id=696&single=1 * - * I'm not sure this library is all that reliable, but it's the only + * I'm not sure this library is all that reliable, and the + * directory feature doesn't seem to work right, but it's the only * zip compressor I'm aware of -- Rick Ellis * * @package CodeIgniter -- cgit v1.2.3-24-g4f1b From 6ae57e09a1c9570a6d1f4b2410313715095a7e62 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 1 Oct 2006 07:59:45 +0000 Subject: --- system/libraries/Zip.php | 296 +++++++++++++++++++++++++++++++---------------- 1 file changed, 196 insertions(+), 100 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 1fd0e7059..aa264386d 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -21,9 +21,6 @@ * This class is based on a library aquired at Zend: * http://www.zend.com/codex.php?id=696&single=1 * - * I'm not sure this library is all that reliable, and the - * directory feature doesn't seem to work right, but it's the only - * zip compressor I'm aware of -- Rick Ellis * * @package CodeIgniter * @subpackage Libraries @@ -31,125 +28,224 @@ * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/general/encryption.html */ -class Zip { - - var $zdata = array(); - var $cdir = array(); - var $offset = 0; +class Zip { + + var $zipdata = array(); + var $directory = array(); + var $offset = 0; + var $zipfile = ''; /** - * Add a Directory + * Add Directory + * + * Lets you add a virtual directory into which you can place files. * * @access public - * @param string + * @param string the directory name * @return void - */ - function add_dir($name) - { - $name =str_replace ("\\", "/", $name); - - $fd = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" - .pack("V", 0) - .pack("V", 0) - .pack("V", 0) - .pack("v", strlen($name)) - .pack("v", 0) - .$name; - - $this->cdata[] = $fd; - - $cd = "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" - .pack("V", 0) - .pack("V", 0) - .pack("V", 0) - .pack("v", strlen ($name)) - .pack("v", 0) - .pack("v", 0) - .pack("v", 0) - .pack("v", 0) - .pack("V", 16) - .pack("V", $this->offset) - .$name; - - $this->offset = strlen(implode('', $this->cdata)); - - $this->cdir[] = $cd; - } + */ + function add_dir($dir) + { + $this->zipfile = ''; + + $dir = str_replace("\\", "/", $dir); + + $this->zipdata[] = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" + .pack('V', 0) + .pack('V', 0) + .pack('V', 0) + .pack('v', strlen($dir)) + .pack('v', 0) + .$dir + .pack('V', 0) + .pack('V', 0) + .pack('V', 0); + + $newoffset = strlen(implode('', $this->zipdata)); + + $record = "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" + .pack('V',0) + .pack('V',0) + .pack('V',0) + .pack('v', strlen($dir)) + .pack('v', 0) + .pack('v', 0) + .pack('v', 0) + .pack('v', 0) + .pack('V', 16) + .pack('V', $this->offset) + .$dir; + + $this->offset = $newoffset; + $this->directory[] = $record; + } // -------------------------------------------------------------------- /** - * Add a File + * Add File + * + * Lets you add files to the archive. If the path is included + * in the filename it will be placed within a directory. Make + * sure you use add_dir() first to create the folder. * * @access public - * @param string + * @param string the file name + * @param string the data to be encoded * @return void */ - function add_file($data, $name) - { - $name = str_replace("\\", "/", $name); - - $u_len = strlen($data); - $crc = crc32($data); - $data = gzcompress($data); - $data = substr(substr($data, 0,strlen ($data) - 4), 2); - $c_len = strlen($data); - - $fd = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" - .pack("V", $crc) - .pack("V", $c_len) - .pack("V", $u_len) - .pack("v", strlen($name)) - .pack("v", 0) - .$name - .$data - .pack("V", $crc) - .pack("V", $c_len) - .pack("V", $u_len); - - $this->zdata[] = $fd; - - $cd = "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" - .pack("V", $crc) - .pack("V", $c_len) - .pack("V", $u_len) - .pack("v", strlen ($name)) - .pack("v", 0) - .pack("v", 0) - .pack("v", 0) - .pack("v", 0) - .pack("V", 32 ) - .pack("V", $this->offset) - .$name; - - $this->offset = strlen(implode('', $this->zdata)); - - $this->cdir[] = $cd; - } + function add_file($filename, $data) + { + $this->zipfile = ''; + + $filename = str_replace("\\", "/", $filename); + + $oldlen = strlen($data); + $crc32 = crc32($data); + + $gzdata = gzcompress($data); + $gzdata = substr(substr($gzdata, 0, strlen($gzdata) - 4), 2); + $newlen = strlen($gzdata); + + $this->zipdata[] = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" + .pack('V', $crc32) + .pack('V', $newlen) + .pack('V', $oldlen) + .pack('v', strlen($filename)) + .pack('v', 0) + .$filename + .$gzdata + .pack('V', $crc32) + .pack('V', $newlen) + .pack('V', $oldlen); + + $newoffset = strlen(implode("", $this->zipdata)); + + $record = "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" + .pack('V', $crc32) + .pack('V', $newlen) + .pack('V', $oldlen) + .pack('v', strlen($filename)) + .pack('v', 0) + .pack('v', 0) + .pack('v', 0) + .pack('v', 0) + .pack('V', 32) + .pack('V', $this->offset); + + $this->offset = $newoffset; + $this->directory[] = $record.$filename; + } // -------------------------------------------------------------------- /** - * Output the zip file + * Read the content of a file * * @access public + * @param string the file path * @return string */ - function output_zipfile() - { - $data = implode("", $this->zdata); - $cdir = implode("", $this->cdir); + function read_file($filepath) + { + if ( ! file_exists($filepath)) + { + return FALSE; + } + + return file_get_contents($filepath); + } + + // -------------------------------------------------------------------- - return $data - .$cdir - ."\x50\x4b\x05\x06\x00\x00\x00\x00" - .pack("v", sizeof($this->cdir)) - .pack("v", sizeof($this->cdir)) - .pack("V", strlen($cdir)) - .pack("V", strlen($data)) - ."\x00\x00"; - } + /** + * Get the Zip file + * + * @access public + * @return binary string + */ + function get_zip() + { + if ($this->zipfile != '') + { + return $this->zipfile; + } + + $data = implode('', $this->zipdata); + $dir = implode('', $this->directory); + + $this->zipfile = $data.$dir."\x50\x4b\x05\x06\x00\x00\x00\x00" + .pack('v', sizeof($this->directory)) + .pack('v', sizeof($this->directory)) + .pack('V', strlen($dir)) + .pack('V', strlen($data)) + ."\x00\x00"; + + return $this->zipfile; + } + + // -------------------------------------------------------------------- + /** + * Write File + * + * Lets you write a file + * + * @access public + * @param string the file name + * @param string the data to be encoded + * @return bool + */ + function write_file($filename, $data) + { + if ( ! ($fp = fopen($filename, "wb"))) + { + return FALSE; + } + + flock($fp, LOCK_EX); + fwrite($fp, $data); + flock($fp, LOCK_UN); + fclose($fp); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Download + * + * + * @access public + * @param string the file name + * @param string the data to be encoded + * @return bool + */ + function download($filename, $data) + { + if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) + { + header('Content-Type: application/x-zip'); + header('Content-Disposition: inline; filename="'.$filename.'"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header("Content-Transfer-Encoding: binary"); + header('Pragma: public'); + header("Content-Length: ".strlen($data)); + } + else + { + header('Content-Type: application/x-zip'); + header('Content-Disposition: attachment; filename="'.$filename.'"'); + header("Content-Transfer-Encoding: binary"); + header('Expires: 0'); + header('Pragma: no-cache'); + header("Content-Length: ".strlen($data)); + } + + echo $data; + } + } -// END CLASS ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 5dc8042015dbd25329ed1e0df8d4d34ee08dc22a Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 1 Oct 2006 18:53:35 +0000 Subject: --- system/libraries/Unit.php | 331 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 331 insertions(+) create mode 100644 system/libraries/Unit.php (limited to 'system/libraries') diff --git a/system/libraries/Unit.php b/system/libraries/Unit.php new file mode 100644 index 000000000..0df78c253 --- /dev/null +++ b/system/libraries/Unit.php @@ -0,0 +1,331 @@ +active == FALSE) + return; + + if (in_array($expected, array('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; + $extype = str_replace(array('true', 'false'), 'bool', str_replace('is_', '', $expected)); + } + else + { + if ($this->strict == TRUE) + $result = ($test === $expected) ? TRUE : FALSE; + else + $result = ($test == $expected) ? TRUE : FALSE; + + $extype = gettype($expected); + } + + $back = $this->_backtrace(); + + $report[] = array ( + 'test_name' => $test_name, + 'test_datatype' => gettype($test), + 'res_datatype' => $extype, + 'result' => ($result === TRUE) ? 'passed' : 'failed', + 'file' => $back['file'], + 'line' => $back['line'] + ); + + $this->results[] = $report; + + return($this->report($this->result($report))); + } + + // -------------------------------------------------------------------- + + /** + * Generate a report + * + * Displays a table with the test data + * + * @access public + * @return string + */ + function report($result = array()) + { + if (count($result) == 0) + { + $result = $this->result(); + } + + $this->_parse_template(); + + $r = ''; + foreach ($result as $res) + { + $table = ''; + + foreach ($res as $key => $val) + { + $temp = $this->_template_rows; + $temp = str_replace('{item}', $key, $temp); + $temp = str_replace('{result}', $val, $temp); + $table .= $temp; + } + + $r .= str_replace('{rows}', $table, $this->_template); + } + + return $r; + } + + // -------------------------------------------------------------------- + + /** + * Use strict comparison + * + * Causes the evaluation to use === rather then == + * + * @access public + * @param bool + * @return null + */ + function use_strict($state = TRUE) + { + $this->strict = ($state == FALSE) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Make Unit testing active + * + * Enables/disables unit testing + * + * @access public + * @param bool + * @return null + */ + function active($state = TRUE) + { + $this->active = ($state == FALSE) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Result Array + * + * Returns the raw result data + * + * @access public + * @return array + */ + function result($results = array()) + { + $obj =& get_instance(); + $obj->load->language('unit_test'); + + if (count($results) == 0) + { + $results = $this->results; + } + + $retval = array(); + foreach ($results as $result) + { + $temp = array(); + foreach ($result as $key => $val) + { + if (is_array($val)) + { + foreach ($val as $k => $v) + { + if (FALSE !== ($line = $obj->lang->line(strtolower('ut_'.$v)))) + { + $v = $line; + } + $temp[$obj->lang->line('ut_'.$k)] = $v; + } + } + else + { + if (FALSE !== ($line = $obj->lang->line(strtolower('ut_'.$val)))) + { + $val = $line; + } + $temp[$obj->lang->line('ut_'.$key)] = $val; + } + } + + $retval[] = $temp; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Set the template + * + * This lets us set the template to be used to display results + * + * @access public + * @params string + * @return void + */ + function set_template($template) + { + $this->_template = $template; + } + + // -------------------------------------------------------------------- + + /** + * Generate a backtrace + * + * This lets us show file names and line numbers + * + * @access private + * @return array + */ + function _backtrace() + { + 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 + * + * @access private + * @return string + */ + function _default_template() + { + $this->_template = ' +

+ + {rows} +
'; + + $this->_template_rows = ' + + {item} + {result} + + '; + } + + // -------------------------------------------------------------------- + + /** + * Parse Template + * + * Harvests the data within the template {pseudo-variables} + * + * @access private + * @return void + */ + 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->_template_rows = $match['1']; + $this->_template = str_replace($match['0'], '{rows}', $this->_template); + } + +} +// END Unit_test Class + +/** + * Helper functions to test boolean true/false + * + * + * @access private + * @return bool + */ +function is_true($test) +{ + return (is_bool($test) AND $test === TRUE) ? TRUE : FALSE; +} +function is_false($test) +{ + return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 844cdfd5294c2e252c1fa2a110be02dcce8f48a8 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 1 Oct 2006 19:00:56 +0000 Subject: --- system/libraries/Unit_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 78b92edb2..0df78c253 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -26,7 +26,7 @@ * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/libraries/uri.html */ -class CI_Unit_test { +class CI_Unit { var $active = TRUE; var $results = array(); @@ -34,7 +34,7 @@ class CI_Unit_test { var $_template = NULL; var $_template_rows = NULL; - function CI_Unit_test() + function CI_Unit() { log_message('debug', "Unit Testing Class Initialized"); } -- cgit v1.2.3-24-g4f1b From 24dd7e71d2587c4290c85bc85e0e181b29ab0539 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 1 Oct 2006 19:02:29 +0000 Subject: --- system/libraries/Controller.php | 21 +-- system/libraries/Unit_test.php | 331 ---------------------------------------- system/libraries/Zip.php | 152 ++++++++++++------ 3 files changed, 117 insertions(+), 387 deletions(-) delete mode 100644 system/libraries/Unit_test.php (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 51f455023..c02074fca 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -80,6 +80,13 @@ class Controller extends CI_Base { { // Prep the class name $class = strtolower(str_replace(EXT, '', $class)); + + // Bug fix for backward compat. + // Kill this at some point in the future + if ($class == 'unit_test') + { + $class = 'unit'; + } // Is this a class extension request? if (substr($class, 0, 3) == 'my_') @@ -168,9 +175,8 @@ class Controller extends CI_Base { * @return null */ function _ci_init_class($class, $prefix = '', $config = NULL) - { + { // Is there an associated config file for this class? - if ($config == NULL) { if (file_exists(APPPATH.'config/'.$class.EXT)) @@ -185,22 +191,19 @@ class Controller extends CI_Base { } else { - $name = $prefix.ucfirst($class); + $name = $prefix.$class; } - - $remap = array( - 'Unit_test' => 'unit' - ); $varname = ( ! isset($remap[$class])) ? $class : $remap[$class]; - + $varname = strtolower($varname); + // Instantiate the class if ($config !== NULL) { $this->$varname = new $name($config); } else - { + { $this->$varname = new $name; } } diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php deleted file mode 100644 index 0df78c253..000000000 --- a/system/libraries/Unit_test.php +++ /dev/null @@ -1,331 +0,0 @@ -active == FALSE) - return; - - if (in_array($expected, array('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; - $extype = str_replace(array('true', 'false'), 'bool', str_replace('is_', '', $expected)); - } - else - { - if ($this->strict == TRUE) - $result = ($test === $expected) ? TRUE : FALSE; - else - $result = ($test == $expected) ? TRUE : FALSE; - - $extype = gettype($expected); - } - - $back = $this->_backtrace(); - - $report[] = array ( - 'test_name' => $test_name, - 'test_datatype' => gettype($test), - 'res_datatype' => $extype, - 'result' => ($result === TRUE) ? 'passed' : 'failed', - 'file' => $back['file'], - 'line' => $back['line'] - ); - - $this->results[] = $report; - - return($this->report($this->result($report))); - } - - // -------------------------------------------------------------------- - - /** - * Generate a report - * - * Displays a table with the test data - * - * @access public - * @return string - */ - function report($result = array()) - { - if (count($result) == 0) - { - $result = $this->result(); - } - - $this->_parse_template(); - - $r = ''; - foreach ($result as $res) - { - $table = ''; - - foreach ($res as $key => $val) - { - $temp = $this->_template_rows; - $temp = str_replace('{item}', $key, $temp); - $temp = str_replace('{result}', $val, $temp); - $table .= $temp; - } - - $r .= str_replace('{rows}', $table, $this->_template); - } - - return $r; - } - - // -------------------------------------------------------------------- - - /** - * Use strict comparison - * - * Causes the evaluation to use === rather then == - * - * @access public - * @param bool - * @return null - */ - function use_strict($state = TRUE) - { - $this->strict = ($state == FALSE) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Make Unit testing active - * - * Enables/disables unit testing - * - * @access public - * @param bool - * @return null - */ - function active($state = TRUE) - { - $this->active = ($state == FALSE) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Result Array - * - * Returns the raw result data - * - * @access public - * @return array - */ - function result($results = array()) - { - $obj =& get_instance(); - $obj->load->language('unit_test'); - - if (count($results) == 0) - { - $results = $this->results; - } - - $retval = array(); - foreach ($results as $result) - { - $temp = array(); - foreach ($result as $key => $val) - { - if (is_array($val)) - { - foreach ($val as $k => $v) - { - if (FALSE !== ($line = $obj->lang->line(strtolower('ut_'.$v)))) - { - $v = $line; - } - $temp[$obj->lang->line('ut_'.$k)] = $v; - } - } - else - { - if (FALSE !== ($line = $obj->lang->line(strtolower('ut_'.$val)))) - { - $val = $line; - } - $temp[$obj->lang->line('ut_'.$key)] = $val; - } - } - - $retval[] = $temp; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Set the template - * - * This lets us set the template to be used to display results - * - * @access public - * @params string - * @return void - */ - function set_template($template) - { - $this->_template = $template; - } - - // -------------------------------------------------------------------- - - /** - * Generate a backtrace - * - * This lets us show file names and line numbers - * - * @access private - * @return array - */ - function _backtrace() - { - 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 - * - * @access private - * @return string - */ - function _default_template() - { - $this->_template = ' -
- - {rows} -
'; - - $this->_template_rows = ' - - {item} - {result} - - '; - } - - // -------------------------------------------------------------------- - - /** - * Parse Template - * - * Harvests the data within the template {pseudo-variables} - * - * @access private - * @return void - */ - 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->_template_rows = $match['1']; - $this->_template = str_replace($match['0'], '{rows}', $this->_template); - } - -} -// END Unit_test Class - -/** - * Helper functions to test boolean true/false - * - * - * @access private - * @return bool - */ -function is_true($test) -{ - return (is_bool($test) AND $test === TRUE) ? TRUE : FALSE; -} -function is_false($test) -{ - return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; -} - -?> \ No newline at end of file diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index aa264386d..2ffed9fe2 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -18,9 +18,11 @@ /** * Zip Compression Class * - * This class is based on a library aquired at Zend: + * This class is based on a library I found at Zend: * http://www.zend.com/codex.php?id=696&single=1 * + * The original library is a little rough around the edges so I + * refactored it and added several additional methods -- Rick Ellis * * @package CodeIgniter * @subpackage Libraries @@ -28,12 +30,18 @@ * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/general/encryption.html */ -class Zip { - +class CI_Zip { + + var $zipfile = ''; var $zipdata = array(); var $directory = array(); var $offset = 0; - var $zipfile = ''; + + function CI_Zip() + { + log_message('debug', "Zip Compression Class Initialized"); + } + /** * Add Directory @@ -41,13 +49,33 @@ class Zip { * Lets you add a virtual directory into which you can place files. * * @access public + * @param mixed the directory name. Can be string or array + * @return void + */ + function add_dir($directory) + { + foreach ((array)$directory as $dir) + { + if ( ! preg_match("|.+/$|", $dir)) + { + $dir .= '/'; + } + + $this->_add_dir($dir); + } + } + + // -------------------------------------------------------------------- + + /** + * Add Directory + * + * @access private * @param string the directory name * @return void */ - function add_dir($dir) + function _add_dir($dir) { - $this->zipfile = ''; - $dir = str_replace("\\", "/", $dir); $this->zipdata[] = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" @@ -78,27 +106,50 @@ class Zip { $this->offset = $newoffset; $this->directory[] = $record; - } - + } + // -------------------------------------------------------------------- /** - * Add File + * Add Data to Zip * * Lets you add files to the archive. If the path is included * in the filename it will be placed within a directory. Make * sure you use add_dir() first to create the folder. * * @access public - * @param string the file name - * @param string the data to be encoded + * @param mixed + * @param string * @return void */ - function add_file($filename, $data) + function add_data($filepath, $data = NULL) { - $this->zipfile = ''; + if (is_array($filepath)) + { + foreach ($filepath as $path => $data) + { + $this->_add_data($path, $data); + } + } + else + { + $this->_add_data($filepath, $data); + } + } - $filename = str_replace("\\", "/", $filename); + // -------------------------------------------------------------------- + + /** + * Add Data to Zip + * + * @access private + * @param string the file name/path + * @param string the data to be encoded + * @return void + */ + function _add_data($filepath, $data) + { + $filepath = str_replace("\\", "/", $filepath); $oldlen = strlen($data); $crc32 = crc32($data); @@ -111,9 +162,9 @@ class Zip { .pack('V', $crc32) .pack('V', $newlen) .pack('V', $oldlen) - .pack('v', strlen($filename)) + .pack('v', strlen($filepath)) .pack('v', 0) - .$filename + .$filepath .$gzdata .pack('V', $crc32) .pack('V', $newlen) @@ -125,7 +176,7 @@ class Zip { .pack('V', $crc32) .pack('V', $newlen) .pack('V', $oldlen) - .pack('v', strlen($filename)) + .pack('v', strlen($filepath)) .pack('v', 0) .pack('v', 0) .pack('v', 0) @@ -134,26 +185,7 @@ class Zip { .pack('V', $this->offset); $this->offset = $newoffset; - $this->directory[] = $record.$filename; - } - - // -------------------------------------------------------------------- - - /** - * Read the content of a file - * - * @access public - * @param string the file path - * @return string - */ - function read_file($filepath) - { - if ( ! file_exists($filepath)) - { - return FALSE; - } - - return file_get_contents($filepath); + $this->directory[] = $record.$filepath; } // -------------------------------------------------------------------- @@ -166,11 +198,19 @@ class Zip { */ function get_zip() { + // We cache the zip data so multiple calls + // do not require recompiling if ($this->zipfile != '') { return $this->zipfile; } + // Is there any data to return? + if (count($this->zipdata) == 0) + { + return FALSE; + } + $data = implode('', $this->zipdata); $dir = implode('', $this->directory); @@ -180,7 +220,7 @@ class Zip { .pack('V', strlen($dir)) .pack('V', strlen($data)) ."\x00\x00"; - + return $this->zipfile; } @@ -196,15 +236,15 @@ class Zip { * @param string the data to be encoded * @return bool */ - function write_file($filename, $data) + function write_zip($filepath) { - if ( ! ($fp = fopen($filename, "wb"))) + if ( ! ($fp = fopen($filepath, "wb"))) { return FALSE; } flock($fp, LOCK_EX); - fwrite($fp, $data); + fwrite($fp, $this->get_zip()); flock($fp, LOCK_UN); fclose($fp); @@ -216,13 +256,12 @@ class Zip { /** * Download * - * * @access public * @param string the file name * @param string the data to be encoded * @return bool */ - function download($filename, $data) + function download($filename) { if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) { @@ -232,7 +271,7 @@ class Zip { header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header("Content-Transfer-Encoding: binary"); header('Pragma: public'); - header("Content-Length: ".strlen($data)); + header("Content-Length: ".strlen($this->get_zip())); } else { @@ -241,10 +280,29 @@ class Zip { header("Content-Transfer-Encoding: binary"); header('Expires: 0'); header('Pragma: no-cache'); - header("Content-Length: ".strlen($data)); + header("Content-Length: ".strlen($this->get_zip())); } - echo $data; + echo $this->get_zip(); + } + + // -------------------------------------------------------------------- + + /** + * Initialize Data + * + * Lets you clear current zip data. Useful if you need to create + * multiple zips with different data. + * + * @access public + * @return void + */ + function clear_data() + { + $this->zipfile = ''; + $this->zipdata = array(); + $this->directory = array(); + $this->offset = array(); } } -- cgit v1.2.3-24-g4f1b From 33dd95d7cb8ac2f6b8da447966a750bdb064fc48 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 1 Oct 2006 19:20:42 +0000 Subject: --- system/libraries/Zip.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 2ffed9fe2..a11699956 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -261,8 +261,13 @@ class CI_Zip { * @param string the data to be encoded * @return bool */ - function download($filename) + function download($filename = 'backup.zip') { + if ( ! preg_match("|.+?\.zip$|", $filename)) + { + $filename .= '.zip'; + } + if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) { header('Content-Type: application/x-zip'); -- cgit v1.2.3-24-g4f1b From 813d0acb42ea9e367115ffc7da5b6036ab36ed98 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 1 Oct 2006 20:36:39 +0000 Subject: --- system/libraries/Router.php | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index c056530a3..d62cf5090 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -291,13 +291,26 @@ class CI_Router { { if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') { - $path_info = getenv('PATH_INFO'); + // If the URL has a question mark then it's simplest to just + // build the URI string from the zero index of the $_GET array. + // This avoids having to deal with $_SERVER variables, which + // can be unreliable on some servers + if (is_array($_GET) AND count($_GET) == 1) + { + return current(array_keys($_GET)); + } + + // Is there a PATH_INFO variable? + // Note: some servers seem to have trouble with getenv() so we'll test it two ways + $path_info = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); + if ($path_info != '' AND $path_info != "/".SELF) { return $path_info; } else { + // OK, how about REQUEST_URI? $req_uri = $this->_parse_request_uri(); if ($req_uri != "") @@ -306,14 +319,24 @@ class CI_Router { } else { - $path_info = getenv('ORIG_PATH_INFO'); + // Hm... maybe the ORIG_PATH_INFO variable exists? + $path_info = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); if ($path_info != '' AND $path_info != "/".SELF) { return $path_info; } else { - return getenv('QUERY_STRING'); + // At this point we've exhauseted all our options. + // Hopefully QUERY_STRING exists. If not, there's nothing else we can try. + $query_string = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); + + if ($query_string != '') + { + return $query_string; + } + + return ''; } } } @@ -327,7 +350,7 @@ class CI_Router { return $this->_parse_request_uri(); } - return getenv($uri); + return (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); } } -- cgit v1.2.3-24-g4f1b From 0f8015fcdc4eb7a2bedc6a04548e588b39914c60 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 1 Oct 2006 22:08:34 +0000 Subject: --- system/libraries/Zip.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index a11699956..218388314 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -227,7 +227,7 @@ class CI_Zip { // -------------------------------------------------------------------- /** - * Write File + * Write File to the specified direcotry * * Lets you write a file * @@ -236,9 +236,9 @@ class CI_Zip { * @param string the data to be encoded * @return bool */ - function write_zip($filepath) + function archive($filepath) { - if ( ! ($fp = fopen($filepath, "wb"))) + if ( ! ($fp = @fopen($filepath, "wb"))) { return FALSE; } -- cgit v1.2.3-24-g4f1b From e26611f93bfb21f5e143cc91ce529f6db52cdd88 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 2 Oct 2006 21:59:12 +0000 Subject: --- system/libraries/Benchmark.php | 32 +++++++++++++++++++ system/libraries/Output.php | 70 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 97 insertions(+), 5 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index d8dd903e7..feedbf570 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -85,6 +85,38 @@ class CI_Benchmark { // -------------------------------------------------------------------- + /** + * Auto Profiler + * + * This function cycles through the entire array of mark points and + * matches any two points that are named identially (ending in "_start" + * and "_end" respectively). It then compiles the execution times for + * all points and returns it as an array + * + * @access public + * @return array + */ + function auto_profiler() + { + $marker_keys = array_reverse(array_keys($this->marker)); + + $times = array(); + foreach ($marker_keys as $val) + { + if (preg_match("/(.+?)_start/i", $val, $match)) + { + if (isset($this->marker[$match[1].'_end'])) + { + $times[$match[1]] = $this->elapsed_time($val, $match[1].'_end'); + } + } + } + + return $times; + } + + // -------------------------------------------------------------------- + /** * Memory Usage * diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 1c3f0d604..b5b7c9e97 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -31,6 +31,7 @@ class CI_Output { var $final_output; var $cache_expiration = 0; var $headers = array(); + var $enable_profiler = FALSE; function CI_Output() { @@ -89,6 +90,20 @@ class CI_Output { // -------------------------------------------------------------------- + /** + * Enable/disable Profiler + * + * @access public + * @param bool + * @return void + */ + function enable_profiler($val = TRUE) + { + $this->enable_profiler = (is_bool($val)) ? $val : TRUE; + } + + // -------------------------------------------------------------------- + /** * Set Cache * @@ -123,7 +138,7 @@ class CI_Output { */ function _display($output = '') { - // Note: We can't use $obj =& _get_instance() since this function + // Note: We can't use $obj =& get_instance() since this function // is sometimes called by the caching mechanism, which happens before // it's available. Instead we'll use globals... global $BM, $CFG; @@ -141,7 +156,7 @@ class CI_Output { // Parse out the elapsed time and memory usage, and // swap the pseudo-variables with the data - $elapsed = $BM->elapsed_time('code_igniter_start', 'code_igniter_end'); + $elapsed = $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end'); $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; $output = str_replace('{memory_usage}', $memory, $output); @@ -166,14 +181,28 @@ class CI_Output { { @header($header); } - } + } // Send the finalized output either directly // to the browser or to the user's _output() // function if it exists - if (function_exists('_get_instance') AND method_exists($obj, '_output')) + if (function_exists('get_instance')) { - $obj->_output($output); + $obj =& get_instance(); + + if ($this->enable_profiler == TRUE) + { + $output .= $this->_run_profiler(); + } + + if (method_exists($obj, '_output')) + { + $obj->_output($output); + } + else + { + echo $output; // Send it to the browser! + } } else { @@ -295,6 +324,37 @@ class CI_Output { return TRUE; } + // -------------------------------------------------------------------- + + /** + * Run the Auto-profiler + * + * @access private + * @return string + */ + function _run_profiler() + { + $obj =& get_instance(); + + $profile = $obj->benchmark->auto_profiler(); + + $output = ''; + if (count($profile) > 0) + { + $output .= "\n\n\n"; + + foreach ($profile as $key => $val) + { + $key = ucwords(str_replace(array('_', '-'), ' ', $key)); + $output .= "\n"; + } + + $output .= "
".$key."".$val."
\n"; + } + + return $output; + } + } // END Output Class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From e95cd263f6991d99e0103fe858f034b76be6d672 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 2 Oct 2006 23:17:20 +0000 Subject: --- system/libraries/Hooks.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index 69ca1a9f1..8767e10d0 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -40,7 +40,19 @@ class CI_Hooks { function CI_Hooks() { log_message('debug', "Hooks Class Initialized"); - + $this->_initialize(); + } + + // -------------------------------------------------------------------- + + /** + * Initialize the Hooks Preferences + * + * @access private + * @return void + */ + function _initialize() + { $CFG =& _load_class('Config'); // If hooks are not enabled in the config file @@ -63,8 +75,7 @@ class CI_Hooks { $this->hooks =& $hook; $this->enabled = TRUE; - } - // END CI_Hooks() + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 243f5cc45f23436a1ed3f2fc1ac5f0388dc3d4f5 Mon Sep 17 00:00:00 2001 From: derek Date: Tue, 3 Oct 2006 00:25:03 +0000 Subject: --- system/libraries/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 55edd6216..99de17414 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1548,7 +1548,7 @@ class CI_Email { */ function _get_hostname() { - return ($this->smtp_host != '') ? $this->smtp_host : $this->_get_ip(); + return (isset($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain'; } // END _get_hostname() -- cgit v1.2.3-24-g4f1b From d13ff07599e9ff114051f4823c4c0d13fd1c814d Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 3 Oct 2006 03:40:45 +0000 Subject: --- system/libraries/Profiler.php | 72 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 system/libraries/Profiler.php (limited to 'system/libraries') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php new file mode 100644 index 000000000..026bfac60 --- /dev/null +++ b/system/libraries/Profiler.php @@ -0,0 +1,72 @@ +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($obj->benchmark->marker[$match[1].'_end'])) + { + $times[$match[1]] = $obj->benchmark->elapsed_time($match[1].'_start', $key); + } + } + } + + return $times; + } + + // -------------------------------------------------------------------- + +} + +// END CI_Profiler class +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 90a7b9db21316122816e01d5e6459a4424940d1f Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 3 Oct 2006 04:48:39 +0000 Subject: --- system/libraries/Profiler.php | 130 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 122 insertions(+), 8 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 026bfac60..265aaf031 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -29,6 +29,13 @@ */ class CI_Profiler { + var $obj; + + function CI_Profiler() + { + $this->obj =& get_instance(); + $this->obj->load->language('profiler'); + } // -------------------------------------------------------------------- @@ -45,27 +52,134 @@ class CI_Profiler { */ function _compile_benchmarks() { - $obj =& get_instance(); - - $times = array(); - foreach ($obj->benchmark->marker as $key => $val) + $profile = array(); + foreach ($this->obj->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($obj->benchmark->marker[$match[1].'_end'])) + if (isset($this->obj->benchmark->marker[$match[1].'_end'])) { - $times[$match[1]] = $obj->benchmark->elapsed_time($match[1].'_start', $key); + $profile[$match[1]] = $this->obj->benchmark->elapsed_time($match[1].'_start', $key); } } } - - return $times; + + // 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 .= '
'; + $output .= "\n"; + $output .= '  '.$this->obj->lang->line('profiler_benchmarks').'  '; + $output .= "\n"; + $output .= "\n\n\n"; + + foreach ($profile as $key => $val) + { + $key = ucwords(str_replace(array('_', '-'), ' ', $key)); + $output .= "\n"; + } + + $output .= "
".$key."  ".$val."
\n"; + $output .= "
\n\n"; + + return $output; } // -------------------------------------------------------------------- + + function _compile_queries() + { + $output = "\n\n"; + $output .= '
'; + $output .= "\n"; + $output .= '  '.$this->obj->lang->line('profiler_queries').'  '; + $output .= "\n"; + + if ( ! class_exists('CI_DB_driver')) + { + $output .= "
".$this->obj->lang->line('profiler_no_db')."
"; + } + else + { + if (count($this->obj->db->queries) == 0) + { + $output .= "
".$this->obj->lang->line('profiler_no_queries')."
"; + } + else + { + foreach ($this->obj->db->queries as $val) + { + $output .= '
'; + $output .= $val; + $output .= "
\n"; + } + } + } + + $output .= "
\n\n"; + + return $output; + } + + // -------------------------------------------------------------------- + + function _compile_post() + { + $output = "\n\n"; + $output .= '
'; + $output .= "\n"; + $output .= '  '.$this->obj->lang->line('profiler_post_data').'  '; + $output .= "\n"; + + if (count($_POST) == 0) + { + $output .= "
".$this->obj->lang->line('profiler_no_post')."
"; + } + else + { + $output .= "\n\n\n"; + + foreach ($_POST as $key => $val) + { + if ( ! is_numeric($key)) + { + $key = "'".$key."'"; + } + + $output .= "\n"; + } + + $output .= "
$_POST[".$key."]  ".htmlspecialchars(stripslashes($val))."
\n"; + } + $output .= "
\n\n"; + + return $output; + } + + // -------------------------------------------------------------------- + + /** + * Run the Auto-profiler + * + * @access private + * @return string + */ + function run($output = '') + { + $output = '
'; + + $output .= $this->_compile_benchmarks(); + $output .= $this->_compile_post(); + $output .= $this->_compile_queries(); + + return $output; + } + } // END CI_Profiler class -- cgit v1.2.3-24-g4f1b From 1c5ef5e34a86c2d3aa0a2d7c61d143331802ae8d Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 3 Oct 2006 04:50:09 +0000 Subject: --- system/libraries/Profiler.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 265aaf031..807a7a83f 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -19,7 +19,10 @@ * Code Igniter Profiler Class * * This class enables you to display benchmark, query, and other data - * in order to help with debugging and optimization + * in order to help with debugging and optimization. + * + * Note: At some point it would be good to move all the HTML in this class + * into a set of template files in order to allow customization. * * @package CodeIgniter * @subpackage Libraries @@ -164,7 +167,7 @@ class CI_Profiler { // -------------------------------------------------------------------- /** - * Run the Auto-profiler + * Run the Profiler * * @access private * @return string -- cgit v1.2.3-24-g4f1b From 08f6020b0085842d4ae81949a0f4886c94158a55 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 3 Oct 2006 05:28:00 +0000 Subject: --- system/libraries/Benchmark.php | 35 ----------- system/libraries/Output.php | 131 +++++++++++++++++++++-------------------- system/libraries/Router.php | 5 ++ 3 files changed, 72 insertions(+), 99 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index feedbf570..d29e91798 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -48,7 +48,6 @@ class CI_Benchmark { { $this->marker[$name] = microtime(); } - // END mark() // -------------------------------------------------------------------- @@ -81,39 +80,6 @@ class CI_Benchmark { return number_format(($em + $es) - ($sm + $ss), $decimals); } - // END elapsed_time() - - // -------------------------------------------------------------------- - - /** - * Auto Profiler - * - * This function cycles through the entire array of mark points and - * matches any two points that are named identially (ending in "_start" - * and "_end" respectively). It then compiles the execution times for - * all points and returns it as an array - * - * @access public - * @return array - */ - function auto_profiler() - { - $marker_keys = array_reverse(array_keys($this->marker)); - - $times = array(); - foreach ($marker_keys as $val) - { - if (preg_match("/(.+?)_start/i", $val, $match)) - { - if (isset($this->marker[$match[1].'_end'])) - { - $times[$match[1]] = $this->elapsed_time($val, $match[1].'_end'); - } - } - } - - return $times; - } // -------------------------------------------------------------------- @@ -132,7 +98,6 @@ class CI_Benchmark { { return '{memory_usage}'; } - // END memory_usage() } diff --git a/system/libraries/Output.php b/system/libraries/Output.php index b5b7c9e97..4ab5dd23c 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -29,9 +29,10 @@ class CI_Output { var $final_output; - var $cache_expiration = 0; - var $headers = array(); - var $enable_profiler = FALSE; + var $cache_expiration = 0; + var $headers = array(); + var $enable_profiler = FALSE; + function CI_Output() { @@ -121,46 +122,52 @@ class CI_Output { /** * Display Output * - * All "view" data is automatically put into this variable - * by the controller class: + * All "view" data is automatically put into this variable by the controller class: * * $this->final_output * - * This function simply echos the variable out. It also does the following: - * - * Stops the benchmark timer so the page rendering speed can be shown. - * - * Determines if the "memory_get_usage' function is available so that - * the memory usage can be shown. + * This function sends the finalized output data to the browser along + * with any server headers and profile data. It also stops the + * benchmark timer so the page rendering speed and memory usage can be shown. * * @access public - * @return void + * @return mixed */ function _display($output = '') { - // Note: We can't use $obj =& get_instance() since this function - // is sometimes called by the caching mechanism, which happens before - // it's available. Instead we'll use globals... + // Note: We use globals because we can't use $obj =& get_instance() + // since this function is sometimes called by the caching mechanism, + // which happens before the CI super object is available. global $BM, $CFG; - + + // -------------------------------------------------------------------- + + // Set the output data if ($output == '') { $output =& $this->final_output; } + // -------------------------------------------------------------------- + // Do we need to write a cache file? if ($this->cache_expiration > 0) { $this->_write_cache($output); } + + // -------------------------------------------------------------------- - // Parse out the elapsed time and memory usage, and - // swap the pseudo-variables with the data + // 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'); + $output = str_replace('{elapsed_time}', $elapsed, $output); + $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; - $output = str_replace('{memory_usage}', $memory, $output); - $output = str_replace('{elapsed_time}', $elapsed, $output); + + // -------------------------------------------------------------------- // Is compression requested? if ($CFG->item('compress_output') === TRUE) @@ -173,6 +180,8 @@ class CI_Output { } } } + + // -------------------------------------------------------------------- // Are there any server headers to send? if (count($this->headers) > 0) @@ -182,30 +191,54 @@ class CI_Output { @header($header); } } + + // -------------------------------------------------------------------- - // Send the finalized output either directly - // to the browser or to the user's _output() - // function if it exists - if (function_exists('get_instance')) + // Does the get_instance() function exist? + // If not we know we are dealing with a cache file so we'll + // simply echo out the data and exit. + if ( ! function_exists('get_instance')) { - $obj =& get_instance(); - - if ($this->enable_profiler == TRUE) - { - $output .= $this->_run_profiler(); - } + echo $output; + log_message('debug', "Final output sent to browser"); + log_message('debug', "Total execution time: ".$elapsed); + } + + // -------------------------------------------------------------------- + + // Grab the super object. We'll need it in a moment... + $obj =& get_instance(); - if (method_exists($obj, '_output')) + // Do we need to generate profile data? + // If so, load the Profile class and run it. + if ($this->enable_profiler == TRUE) + { + $obj->load->library('profiler'); + + // If the output data contains closing and tags + // we will remove them and add them back after we insert the profile data + if (preg_match("|.*?|is", $output)) { - $obj->_output($output); + $output = preg_replace("|.*?|is", '', $output); + $output .= $obj->profiler->run(); + $output .= ''; } else { - echo $output; // Send it to the browser! + $output .= $obj->profiler->run(); } } + + // -------------------------------------------------------------------- + + // Does the controller contain a function named _output()? + // If so send the output there. Otherwise, echo it. + if (method_exists($obj, '_output')) + { + $obj->_output($output); + } else - { + { echo $output; // Send it to the browser! } @@ -324,36 +357,6 @@ class CI_Output { return TRUE; } - // -------------------------------------------------------------------- - - /** - * Run the Auto-profiler - * - * @access private - * @return string - */ - function _run_profiler() - { - $obj =& get_instance(); - - $profile = $obj->benchmark->auto_profiler(); - - $output = ''; - if (count($profile) > 0) - { - $output .= "\n\n\n"; - - foreach ($profile as $key => $val) - { - $key = ucwords(str_replace(array('_', '-'), ' ', $key)); - $output .= "\n"; - } - - $output .= "
".$key."".$val."
\n"; - } - - return $output; - } } // END Output Class diff --git a/system/libraries/Router.php b/system/libraries/Router.php index d62cf5090..7a4fd3899 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -530,6 +530,11 @@ class CI_Router { */ function fetch_method() { + if ($this->method == $this->fetch_class()) + { + return 'index'; + } + return $this->method; } -- cgit v1.2.3-24-g4f1b From 07ad666409b60610a1e5b07368506f9f0ca45b22 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 3 Oct 2006 06:12:52 +0000 Subject: --- system/libraries/Profiler.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 807a7a83f..6626190b1 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -174,7 +174,9 @@ class CI_Profiler { */ function run($output = '') { - $output = '
'; + $obj =& get_instance(); + + $output = '
'; $output .= $this->_compile_benchmarks(); $output .= $this->_compile_post(); -- cgit v1.2.3-24-g4f1b From 2fcd16b467436a13c8a84a4add4e8d113fe1be02 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 3 Oct 2006 16:41:54 +0000 Subject: --- system/libraries/Input.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index ad7b0c571..41d77a97a 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -230,10 +230,23 @@ class CI_Input { return FALSE; } else - { + { if ($xss_clean === TRUE) { - return $this->xss_clean($_COOKIE[$index]); + if (is_array($_COOKIE[$index])) + { + $cookie = array(); + foreach($_COOKIE[$index] as $key => $val) + { + $cookie[$key] = $this->xss_clean($val); + } + + return $cookie; + } + else + { + return $this->xss_clean($_COOKIE[$index]); + } } else { -- cgit v1.2.3-24-g4f1b From a813a46adc7eefa9ec3835e07f3b57ab5d870d27 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 3 Oct 2006 19:17:41 +0000 Subject: --- system/libraries/Profiler.php | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 6626190b1..9da73b03e 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -74,20 +74,20 @@ class CI_Profiler { // be modified. We also might want to make this data available to be logged $output = "\n\n"; - $output .= '
'; + $output .= '
'; $output .= "\n"; $output .= '  '.$this->obj->lang->line('profiler_benchmarks').'  '; $output .= "\n"; - $output .= "\n\n\n"; + $output .= "\n\n
\n"; foreach ($profile as $key => $val) { $key = ucwords(str_replace(array('_', '-'), ' ', $key)); - $output .= "\n"; + $output .= "\n"; } $output .= "
".$key."  ".$val."
".$key."  ".$val."
\n"; - $output .= "
\n\n"; + $output .= "
"; return $output; } @@ -98,7 +98,7 @@ class CI_Profiler { function _compile_queries() { $output = "\n\n"; - $output .= '
'; + $output .= '
'; $output .= "\n"; $output .= '  '.$this->obj->lang->line('profiler_queries').'  '; $output .= "\n"; @@ -117,14 +117,14 @@ class CI_Profiler { { foreach ($this->obj->db->queries as $val) { - $output .= '
'; + $output .= '
'; $output .= $val; $output .= "
\n"; } } } - $output .= "
\n\n"; + $output .= "
"; return $output; } @@ -132,9 +132,9 @@ class CI_Profiler { // -------------------------------------------------------------------- function _compile_post() - { + { $output = "\n\n"; - $output .= '
'; + $output .= '
'; $output .= "\n"; $output .= '  '.$this->obj->lang->line('profiler_post_data').'  '; $output .= "\n"; @@ -145,7 +145,7 @@ class CI_Profiler { } else { - $output .= "\n\n\n"; + $output .= "\n\n
\n"; foreach ($_POST as $key => $val) { @@ -154,12 +154,12 @@ class CI_Profiler { $key = "'".$key."'"; } - $output .= "\n"; + $output .= "\n"; } $output .= "
$_POST[".$key."]  ".htmlspecialchars(stripslashes($val))."
$_POST[".$key."]  ".htmlspecialchars(stripslashes($val))."
\n"; } - $output .= "
\n\n"; + $output .= "
"; return $output; } @@ -177,11 +177,14 @@ class CI_Profiler { $obj =& get_instance(); $output = '
'; + $output .= "
"; $output .= $this->_compile_benchmarks(); $output .= $this->_compile_post(); $output .= $this->_compile_queries(); + $output .= '
'; + return $output; } -- cgit v1.2.3-24-g4f1b From 04ea44e4327be7ae3a9dfb55bfd77e9ec8c7c92d Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 3 Oct 2006 19:17:59 +0000 Subject: --- system/libraries/Input.php | 116 ++++++++++++++++++++------------------------- 1 file changed, 51 insertions(+), 65 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 41d77a97a..98c2cbd55 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -42,14 +42,13 @@ class CI_Input { */ function CI_Input() { + log_message('debug', "Input Class Initialized"); + $CFG =& _load_class('Config'); $this->use_xss_clean = ($CFG->item('global_xss_filtering') === TRUE) ? TRUE : FALSE; - $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; - - log_message('debug', "Input Class Initialized"); + $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; $this->_sanitize_globals(); } - // END CI_Input() // -------------------------------------------------------------------- @@ -81,11 +80,11 @@ class CI_Input { foreach ($global as $key => $val) { unset($$key); - } + } } } - // Is $_GET data allowed? + // Is $_GET data allowed? If not we'll set the $_GET to an empty array if ($this->allow_get_array == FALSE) { $_GET = array(); @@ -95,33 +94,22 @@ class CI_Input { if (is_array($_POST) AND count($_POST) > 0) { foreach($_POST as $key => $val) - { - if (is_array($val)) - { - foreach($val as $k => $v) - { - $_POST[$this->_clean_input_keys($key)][$this->_clean_input_keys($k)] = $this->_clean_input_data($v); - } - } - else - { - $_POST[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); - } - } + { + $_POST[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); + } } // Clean $_COOKIE Data if (is_array($_COOKIE) AND count($_COOKIE) > 0) { foreach($_COOKIE as $key => $val) - { + { $_COOKIE[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); - } + } } log_message('debug', "Global POST and COOKIE data sanitized"); } - // END _sanitize_globals() // -------------------------------------------------------------------- @@ -142,7 +130,7 @@ class CI_Input { $new_array = array(); foreach ($str as $key => $val) { - $new_array[$key] = $this->_clean_input_data($val); + $new_array[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); } return $new_array; } @@ -152,9 +140,9 @@ class CI_Input { $str = $this->xss_clean($str); } + // Standardize newlines return preg_replace("/\015\012|\015|\012/", "\n", $str); } - // END _clean_input_data() // -------------------------------------------------------------------- @@ -170,7 +158,7 @@ class CI_Input { * @return string */ function _clean_input_keys($str) - { + { if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str)) { exit('Disallowed Key Characters: '.$str); @@ -183,7 +171,6 @@ class CI_Input { return $str; } - // END _clean_input_keys() // -------------------------------------------------------------------- @@ -200,19 +187,24 @@ class CI_Input { { return FALSE; } - else + + if ($xss_clean === TRUE) { - if ($xss_clean === TRUE) + if (is_array($_POST[$index])) { - return $this->xss_clean($_POST[$index]); + foreach($_POST[$index] as $key => $val) + { + $_POST[$index][$key] = $this->xss_clean($val); + } } else { - return $_POST[$index]; + return $this->xss_clean($_POST[$index]); } } + + return $_POST[$index]; } - // END post() // -------------------------------------------------------------------- @@ -229,32 +221,29 @@ class CI_Input { { return FALSE; } - else - { - if ($xss_clean === TRUE) + + if ($xss_clean === TRUE) + { + if (is_array($_COOKIE[$index])) { - if (is_array($_COOKIE[$index])) - { - $cookie = array(); - foreach($_COOKIE[$index] as $key => $val) - { - $cookie[$key] = $this->xss_clean($val); - } - - return $cookie; - } - else + $cookie = array(); + foreach($_COOKIE[$index] as $key => $val) { - return $this->xss_clean($_COOKIE[$index]); + $cookie[$key] = $this->xss_clean($val); } + + return $cookie; } else { - return $_COOKIE[$index]; + return $this->xss_clean($_COOKIE[$index]); } } + else + { + return $_COOKIE[$index]; + } } - // END cookie() // -------------------------------------------------------------------- @@ -297,7 +286,6 @@ class CI_Input { return $this->ip_address; } - // END ip_address() // -------------------------------------------------------------------- @@ -312,7 +300,6 @@ class CI_Input { { return ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) ? FALSE : TRUE; } - // END valid_ip() // -------------------------------------------------------------------- @@ -333,7 +320,6 @@ class CI_Input { return $this->user_agent; } - // END user_agent() // -------------------------------------------------------------------- @@ -403,8 +389,8 @@ class CI_Input { * */ $str = preg_replace("/%u0([a-z0-9]{3})/i", "&#x\\1;", $str); - $str = preg_replace("/%([a-z0-9]{2})/i", "&#x\\1;", $str); - + $str = preg_replace("/%([a-z0-9]{2})/i", "&#x\\1;", $str); + /* * Convert character entities to ASCII * @@ -414,8 +400,8 @@ class CI_Input { * */ - if (preg_match_all("/<(.+?)>/si", $str, $matches)) - { + if (preg_match_all("/<(.+?)>/si", $str, $matches)) + { for ($i = 0; $i < count($matches['0']); $i++) { $str = str_replace($matches['1'][$i], @@ -532,12 +518,12 @@ class CI_Input { $str = preg_replace("#".$key."#i", $val, $str); } - + log_message('debug', "XSS Filtering completed"); return $str; } - // END xss_clean() + // -------------------------------------------------------------------- /** * HTML Entities Decode @@ -555,14 +541,14 @@ class CI_Input { * @return string */ /* ------------------------------------------------- - /* Replacement for html_entity_decode() - /* -------------------------------------------------*/ - - /* - NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the - character set, and the PHP developers said they were not back porting the - fix to versions other than PHP 5.x. - */ + /* Replacement for html_entity_decode() + /* -------------------------------------------------*/ + + /* + NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the + character set, and the PHP developers said they were not back porting the + fix to versions other than PHP 5.x. + */ function _html_entity_decode($str, $charset='ISO-8859-1') { if (stristr($str, '&') === FALSE) return $str; -- cgit v1.2.3-24-g4f1b From 6871d95930a148722f2b99fa80ef6dd44f86f078 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 4 Oct 2006 00:36:18 +0000 Subject: --- system/libraries/Controller.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index c02074fca..6a3ea9962 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -430,6 +430,7 @@ class Controller extends CI_Base { * @access private * @param mixed database connection values * @param bool whether to return the object for multiple connections + * @param bool whether to load the active record class * @return void */ function _ci_init_database($params = '', $return = FALSE, $active_record = FALSE) @@ -439,7 +440,7 @@ class Controller extends CI_Base { return; } - // Load the DB config file if needed + // Load the DB config file if needed. We'll test for a DSN string if (is_string($params) AND strpos($params, '://') === FALSE) { include(APPPATH.'config/database'.EXT); -- cgit v1.2.3-24-g4f1b From b87cf23b9a4a4611cacf6316a7c437af54ebde52 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 4 Oct 2006 07:46:05 +0000 Subject: --- system/libraries/Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 6a3ea9962..2a4c19522 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -504,7 +504,7 @@ class Controller extends CI_Base { $obj =& get_instance(); $obj->db =& $DB; } - + // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From c5f7fa3f8fea283b51ee6cd80b36b2112b2e81db Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 6 Oct 2006 02:10:23 +0000 Subject: --- system/libraries/Validation.php | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 7db67a3e1..ff5970837 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -65,18 +65,25 @@ class CI_Validation { function set_fields($data = '', $field = '') { if ($data == '') - return; - - if ( ! is_array($data)) { - if ($field == '') - return; - - $data = array($data => $field); + if (count($this->_fields) == 0) + { + return FALSE; + } } - - $this->_fields = $data; - + else + { + if ( ! is_array($data)) + { + $data = array($data => $field); + } + + if (count($data) > 0) + { + $this->_fields = $data; + } + } + foreach($this->_fields as $key => $val) { $this->$key = ( ! isset($_POST[$key]) OR is_array($_POST[$key])) ? '' : $this->prep_for_form($_POST[$key]); -- cgit v1.2.3-24-g4f1b From fd2750b8f85b4f204e536d255742e18018c3f1f2 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 6 Oct 2006 17:29:12 +0000 Subject: --- system/libraries/Controller.php | 97 ++--------------------------------------- system/libraries/Loader.php | 54 +++++++++-------------- 2 files changed, 24 insertions(+), 127 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 2a4c19522..b09be6c57 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -434,101 +434,10 @@ class Controller extends CI_Base { * @return void */ function _ci_init_database($params = '', $return = FALSE, $active_record = FALSE) - { - if ($this->_ci_is_loaded('db') == TRUE AND $return == FALSE AND $active_record == FALSE) - { - return; - } - - // Load the DB config file if needed. We'll test for a DSN string - if (is_string($params) AND strpos($params, '://') === FALSE) - { - include(APPPATH.'config/database'.EXT); - - $group = ($params == '') ? $active_group : $params; - - if ( ! isset($db[$group])) - { - show_error('You have specified an invalid database connection group: '.$group); - } - - $params = $db[$group]; - } - - // No DB specified yet? Beat them senseless... - if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '') - { - show_error('You have not selected a database type to connect to.'); - } - - // Load the DB classes. Note: Since the active record class is optional - // 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 == TRUE) - { - $params['active_r'] = TRUE; - } - - require_once(BASEPATH.'database/DB_driver'.EXT); - - if ( ! isset($params['active_r']) OR $params['active_r'] == TRUE) - { - require_once(BASEPATH.'database/DB_active_rec'.EXT); - - if ( ! class_exists('CI_DB')) - { - eval('class CI_DB extends CI_DB_active_record { }'); - } - } - else - { - if ( ! class_exists('CI_DB')) - { - 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 = new $driver($params); - - if ($return === TRUE) - { - return $DB; - } - - $obj =& get_instance(); - $obj->db =& $DB; - } - - // -------------------------------------------------------------------- - - /** - * Initialize Database Ancillary Classes - * - * @access private - * @param str class name - * @return void - */ - function _ci_init_dbextra($class) { - if ( ! $this->_ci_is_loaded('db')) - { - $this->_ci_init_database(); - } - - if ($class == 'dbutil') - { - require_once(BASEPATH.'database/DB_utility'.EXT); - require_once(BASEPATH.'database/drivers/'.$this->db->dbdriver.'/'.$this->db->dbdriver.'_utility'.EXT); - $class = 'CI_DB_'.$this->db->dbdriver.'_utility'; - $this->dbutil = new $class(); - } - } + require_once(BASEPATH.'database/DB'.EXT); + return DB($params, $return, $active_record); + } // -------------------------------------------------------------------- diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 2534e6965..6809054e5 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -110,7 +110,9 @@ class CI_Loader { function database($db = '', $return = FALSE, $active_record = FALSE) { $obj =& get_instance(); - + + return DB($params, $return, $active_record); + if ($return === TRUE) { return $obj->_ci_init_database($db, TRUE, $active_record); @@ -124,20 +126,6 @@ class CI_Loader { // -------------------------------------------------------------------- - /** - * Database Utiliy Loader - * - * @access public - * @return object - */ - function dbutil() - { - $obj =& get_instance(); - $obj->_ci_init_dbextra('dbutil'); - } - - // -------------------------------------------------------------------- - /** * Scaffolding Loader * @@ -336,7 +324,24 @@ class CI_Loader { log_message('debug', 'Plugins loaded: '.implode(', ', $plugins)); } + + // -------------------------------------------------------------------- + /** + * Load Plugins + * + * This is simply an alias to the above function in case the + * user has written the plural form of this function. + * + * @access public + * @param array + * @return void + */ + function plugins($plugins = array()) + { + $this->plugin($plugins); + } + // -------------------------------------------------------------------- /** @@ -380,24 +385,7 @@ class CI_Loader { log_message('debug', 'Scripts loaded: '.implode(', ', $scripts)); } - - // -------------------------------------------------------------------- - - /** - * Load Plugins - * - * This is simply an alias to the above function in case the - * user has written the plural form of this function. - * - * @access public - * @param array - * @return void - */ - function plugins($plugins = array()) - { - $this->plugin($plugins); - } - + // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From 8f0a8f693307a6d04b8a50aa11f81041c961adf6 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 7 Oct 2006 01:17:25 +0000 Subject: --- system/libraries/Benchmark.php | 7 + system/libraries/Controller.php | 439 ++-------------------------------------- system/libraries/Loader.php | 357 ++++++++++++++++++++++++++------ system/libraries/Profiler.php | 2 +- 4 files changed, 328 insertions(+), 477 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index d29e91798..c20a54269 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -71,9 +71,16 @@ class CI_Benchmark { { return '{elapsed_time}'; } + + if ( ! isset($this->marker[$point1])) + { + return ''; + } if ( ! isset($this->marker[$point2])) + { $this->marker[$point2] = microtime(); + } list($sm, $ss) = explode(' ', $this->marker[$point1]); list($em, $es) = explode(' ', $this->marker[$point2]); diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index b09be6c57..88b49a9e6 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -29,355 +29,39 @@ */ class Controller extends CI_Base { - var $_ci_models = array(); var $_ci_scaffolding = FALSE; var $_ci_scaff_table = FALSE; /** * Constructor * - * Loads the base classes needed to run CI, and runs the "autoload" - * routine which loads the systems specified in the "autoload" config file. + * Calls the initialize() function */ function Controller() { parent::CI_Base(); - // Assign all the class objects that were instantiated by the - // front controller to local class variables so that CI can be - // run as one big super object. - $this->_ci_assign_core(); - - // Load everything specified in the autoload.php file - $this->load->_ci_autoloader($this->_ci_autoload()); - - // This allows anything loaded using $this->load (viwes, files, etc.) - // to become accessible from within the Controller class functions. - foreach (get_object_vars($this) as $key => $var) - { - if (is_object($var)) - { - $this->load->$key =& $this->$key; - } - } + $this->_ci_initialize(); log_message('debug', "Controller Class Initialized"); } - + // -------------------------------------------------------------------- /** - * Initialization Handler + * Initialize * - * This function loads the requested class. - * - * @access private - * @param string the item that is being loaded - * @param mixed any additional parameters - * @return void - */ - function _ci_load_class($class, $params = NULL) - { - // Prep the class name - $class = strtolower(str_replace(EXT, '', $class)); - - // Bug fix for backward compat. - // Kill this at some point in the future - if ($class == 'unit_test') - { - $class = 'unit'; - } - - // Is this a class extension request? - if (substr($class, 0, 3) == 'my_') - { - $class = preg_replace("/my_(.+)/", "\\1", $class); - $extend = TRUE; - } - else - { - $extend = FALSE; - } - - // Does THIS file (Controller.php) contain an initialization - // function that maps to the requested class? - - $method = '_ci_init_'.$class; - - if (method_exists($this, $method)) - { - if (is_null($params)) - { - $this->$method(); - } - else - { - $this->$method($params); - } - - // We're done... - return TRUE; - } - - // Are we extending one of the base classes? - if ($extend == TRUE) - { - // Load the requested library from the main system/libraries folder - if (file_exists(BASEPATH.'libraries/'.ucfirst($class).EXT)) - { - include_once(BASEPATH.'libraries/'.ucfirst($class).EXT); - } - - // Now look for a matching library - foreach (array(ucfirst($class), $class) as $filename) - { - if (file_exists(APPPATH.'libraries/'.$filename.EXT)) - { - include_once(APPPATH.'libraries/'.$filename.EXT); - } - } - - return $this->_ci_init_class($filename, 'MY_', $params); - } - else - { - // Lets search for the requested library file and load it. - // For backward compatibility we'll test for filenames that are - // both uppercase and lower. - foreach (array(ucfirst($class), $class) as $filename) - { - for ($i = 1; $i < 3; $i++) - { - $path = ($i % 2) ? APPPATH : BASEPATH; - - if (file_exists($path.'libraries/'.$filename.EXT)) - { - include_once($path.'libraries/'.$filename.EXT); - return $this->_ci_init_class($filename, '', $params); - } - } - } - } - - // If we got this far we were unable to find the requested class - log_message('error', "Unable to load the requested class: ".$class); - show_error("Unable to load the class: ".$class); - } - - // -------------------------------------------------------------------- - - /** - * Instantiates a class - * - * @access private - * @param string - * @param string - * @return null - */ - function _ci_init_class($class, $prefix = '', $config = NULL) - { - // Is there an associated config file for this class? - if ($config == NULL) - { - if (file_exists(APPPATH.'config/'.$class.EXT)) - { - include_once(APPPATH.'config/'.$class.EXT); - } - } - - if ($prefix == '') - { - $name = ( ! class_exists($class)) ? 'CI_'.$class : $class; - } - else - { - $name = $prefix.$class; - } - - $varname = ( ! isset($remap[$class])) ? $class : $remap[$class]; - $varname = strtolower($varname); - - // Instantiate the class - if ($config !== NULL) - { - $this->$varname = new $name($config); - } - else - { - $this->$varname = new $name; - } - } - - // -------------------------------------------------------------------- - - /** - * Loads and instantiates the requested model class - * - * @access private - * @param string - * @return array - */ - function _ci_init_model($model, $name = '', $db_conn = FALSE) - { - // Is the model in a sub-folder? - // If so, parse out the filename and path. - if (strpos($model, '/') === FALSE) - { - $path = ''; - } - else - { - $x = explode('/', $model); - $model = end($x); - unset($x[count($x)-1]); - $path = implode('/', $x).'/'; - } - - if ($name == '') - { - $name = $model; - } - - $obj =& get_instance(); - if (in_array($name, $obj->_ci_models, TRUE)) - { - return; - } - - if (isset($this->$name)) - { - show_error('The model name you are loading is the name of a resource that is already being used: '.$name); - } - - $model = strtolower($model); - - if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT)) - { - show_error('Unable to locate the model you have specified: '.$model); - } - - if ($db_conn !== FALSE) - { - if ($db_conn === TRUE) - $db_conn = ''; - - $this->_ci_init_database($db_conn, FALSE, TRUE); - } - - if ( ! class_exists('Model')) - { - require_once(BASEPATH.'libraries/Model'.EXT); - } - - require_once(APPPATH.'models/'.$path.$model.EXT); - - $model = ucfirst($model); - $this->$name = new $model(); - $this->_ci_models[] = $name; - $this->_ci_assign_to_models(); - } - - // -------------------------------------------------------------------- - - /** - * Assign to Models - * - * Makes sure that anything loaded by the loader class (libraries, plugins, etc.) - * will be available to modles, if any exist. - * - * @access public - * @param object - * @return array - */ - function _ci_assign_to_models() - { - $obj =& get_instance(); - if (count($obj->_ci_models) == 0) - { - return; - } - foreach ($obj->_ci_models as $model) - { - $obj->$model->_assign_libraries(); - } - } - - // -------------------------------------------------------------------- - - /** - * Auto-initialize Core Classes - * - * This initializes the core systems that are specified in the - * libraries/autoload.php file, as well as the systems specified in - * the $autoload class array above. - * - * It returns the "autoload" array so we can pass it to the Loader - * class since it needs to autoload plugins and helper files - * - * The config/autoload.php file contains an array that permits - * sub-systems to be loaded automatically. - * - * @access private - * @return array - */ - function _ci_autoload() - { - include_once(APPPATH.'config/autoload'.EXT); - - if ( ! isset($autoload)) - { - return FALSE; - } - - if (count($autoload['config']) > 0) - { - foreach ($autoload['config'] as $key => $val) - { - $this->config->load($val); - } - } - unset($autoload['config']); - - // A little tweak to remain backward compatible - // The $autoload['core'] item was deprecated - if ( ! isset($autoload['libraries'])) - { - $autoload['libraries'] = $autoload['core']; - - } - - $exceptions = array('dbutil', 'dbexport'); - - foreach ($autoload['libraries'] as $item) - { - if ( ! in_array($item, $exceptions, TRUE)) - { - $this->_ci_load_class($item); - } - else - { - $this->_ci_init_dbextra($item); - } - } - unset($autoload['libraries']); - - return $autoload; - } - - // -------------------------------------------------------------------- - - /** - * Assign the core classes to the global $CI object - * - * By assigning all the classes instantiated by the front controller - * local class variables we enable everything to be accessible using - * $this->class->function() + * Assigns all the bases classes loaded by the front controller to + * variables in this class. Also calls the autoload routine. * * @access private * @return void - */ - function _ci_assign_core() + */ + function _ci_initialize() { + // Assign all the class objects that were instantiated by the + // front controller to local class variables so that CI can be + // run as one big super object. foreach (array('Config', 'Input', 'Benchmark', 'URI', 'Output') as $val) { $class = strtolower($val); @@ -392,101 +76,22 @@ class Controller extends CI_Base { { $this->load = new CI_Loader(); } - } - - // -------------------------------------------------------------------- - /** - * Initialize Scaffolding - * - * This initializing function works a bit different than the - * others. It doesn't load the class. Instead, it simply - * sets a flag indicating that scaffolding is allowed to be - * used. The actual scaffolding function below is - * called by the front controller based on whether the - * second segment of the URL matches the "secret" scaffolding - * word stored in the application/config/routes.php - * - * @access private - * @param string the table to scaffold - * @return void - */ - function _ci_init_scaffolding($table = FALSE) - { - if ($table === FALSE) - { - show_error('You must include the name of the table you would like access when you initialize scaffolding'); - } - $this->_ci_scaffolding = TRUE; - $this->_ci_scaff_table = $table; - } - - // -------------------------------------------------------------------- - - /** - * Initialize Database - * - * @access private - * @param mixed database connection values - * @param bool whether to return the object for multiple connections - * @param bool whether to load the active record class - * @return void - */ - function _ci_init_database($params = '', $return = FALSE, $active_record = FALSE) - { - require_once(BASEPATH.'database/DB'.EXT); - return DB($params, $return, $active_record); - } - - // -------------------------------------------------------------------- - - /** - * Returns TRUE if a class is loaded, FALSE if not - * - * @access public - * @param string the class name - * @return bool - */ - function _ci_is_loaded($class) - { - return ( ! isset($this->$class) OR ! is_object($this->$class)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- + // Load everything specified in the autoload.php file + $this->load->_ci_autoloader(); - /** - * Scaffolding - * - * Initializes the scaffolding. - * - * @access private - * @return void - */ - function _ci_scaffolding() - { - if ($this->_ci_scaffolding === FALSE OR $this->_ci_scaff_table === FALSE) - { - show_404('Scaffolding unavailable'); - } - - if (class_exists('Scaffolding')) return; - - if ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) - { - $method = 'view'; - } - else + // This allows anything loaded using $this->load (viwes, files, etc.) + // to become accessible from within the Controller class functions. + foreach (get_object_vars($this) as $key => $var) { - $method = $this->uri->segment(3); - } - - $this->_ci_init_database("", FALSE, TRUE); - $this->_ci_load_class('pagination'); - require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); - $this->scaff = new Scaffolding($this->_ci_scaff_table); - $this->scaff->$method(); + if (is_object($var)) + { + $this->load->$key =& $this->$key; + } + } } + } // END _Controller class diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 6809054e5..f823d95e8 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -28,6 +28,7 @@ */ class CI_Loader { + var $CI; var $ob_level; var $cached_vars = array(); var $helpers = array(); @@ -35,6 +36,7 @@ class CI_Loader { var $scripts = array(); var $languages = array(); var $view_path = ''; + var $models = array(); /** * Constructor @@ -46,6 +48,8 @@ class CI_Loader { */ function CI_Loader() { + $this->CI =& get_instance(); + $this->view_path = APPPATH.'views/'; $this->ob_level = ob_get_level(); @@ -70,9 +74,8 @@ class CI_Loader { if ($class == '') return; - $obj =& get_instance(); - $obj->_ci_load_class($class, $param); - $obj->_ci_assign_to_models(); + $this->_ci_load_class($class, $param); + $this->_ci_assign_to_models(); } // -------------------------------------------------------------------- @@ -92,8 +95,61 @@ class CI_Loader { if ($model == '') return; - $obj =& get_instance(); - $obj->_ci_init_model($model, $name, $db_conn); + // Is the model in a sub-folder? + // If so, parse out the filename and path. + if (strpos($model, '/') === FALSE) + { + $path = ''; + } + else + { + $x = explode('/', $model); + $model = end($x); + unset($x[count($x)-1]); + $path = implode('/', $x).'/'; + } + + if ($name == '') + { + $name = $model; + } + + if (in_array($name, $this->models, TRUE)) + { + return; + } + + if (isset($this->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); + + if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT)) + { + show_error('Unable to locate the model you have specified: '.$model); + } + + if ($db_conn !== FALSE) + { + if ($db_conn === TRUE) + $db_conn = ''; + + $this->CI->load->database($db_conn, FALSE, TRUE); + } + + if ( ! class_exists('Model')) + { + require_once(BASEPATH.'libraries/Model'.EXT); + } + + require_once(APPPATH.'models/'.$path.$model.EXT); + + $model = ucfirst($model); + $this->CI->$name = new $model(); + $this->models[] = $name; + $this->_ci_assign_to_models(); } // -------------------------------------------------------------------- @@ -107,43 +163,21 @@ class CI_Loader { * @param bool whether to enable active record (this allows us to override the config setting) * @return object */ - function database($db = '', $return = FALSE, $active_record = FALSE) + function database($params = '', $return = FALSE, $active_record = FALSE) { - $obj =& get_instance(); - - return DB($params, $return, $active_record); + require_once(BASEPATH.'database/DB'.EXT); if ($return === TRUE) { - return $obj->_ci_init_database($db, TRUE, $active_record); + return DB($params, $return, $active_record); } else { - $obj->_ci_init_database($db, FALSE, $active_record); - $obj->_ci_assign_to_models(); + DB($params, $return, $active_record); + $this->_ci_assign_to_models(); } } - - // -------------------------------------------------------------------- - - /** - * Scaffolding Loader - * - * @access public - * @param string - * @return void - */ - function scaffolding($table = '') - { - if ($table == FALSE) - { - show_error('You must include the name of the table you would like access when you initialize scaffolding'); - } - $obj =& get_instance(); - $obj->_ci_init_scaffolding($table); - } - // -------------------------------------------------------------------- /** @@ -397,8 +431,7 @@ class CI_Loader { */ function language($file = '', $lang = '', $return = FALSE) { - $obj =& get_instance(); - return $obj->lang->load($file, $lang, $return); + return $this->CI->lang->load($file, $lang, $return); } // -------------------------------------------------------------------- @@ -412,31 +445,43 @@ class CI_Loader { */ function config($file = '') { - $obj =& get_instance(); - $obj->config->load($file); + $this->CI->config->load($file); } - + // -------------------------------------------------------------------- /** - * Set the Path to the "views" folder + * Scaffolding Loader * - * @access private + * This initializing function works a bit different than the + * others. It doesn't load the class. Instead, it simply + * sets a flag indicating that scaffolding is allowed to be + * used. The actual scaffolding function below is + * called by the front controller based on whether the + * second segment of the URL matches the "secret" scaffolding + * word stored in the application/config/routes.php + * + * @access public * @param string * @return void - */ - function _ci_set_view_path($path) - { - $this->view_path = $path; + */ + function scaffolding($table = '') + { + if ($table === FALSE) + { + show_error('You must include the name of the table you would like access when you initialize scaffolding'); + } + + $this->CI->_ci_scaffolding = TRUE; + $this->CI->_ci_scaff_table = $table; } - + // -------------------------------------------------------------------- - + /** * Loader * - * This function isn't called directly. It's called from - * the two functions above. It's used to load views and files + * This function is used to load views and files. * * @access private * @param array @@ -446,12 +491,11 @@ class CI_Loader { { // This allows anything loaded using $this->load (viwes, files, etc.) // to become accessible from within the Controller and Model functions. - $obj =& get_instance(); - foreach (get_object_vars($obj) as $key => $var) + foreach (get_object_vars($this->CI) as $key => $var) { if (is_object($var)) { - $this->$key =& $obj->$key; + $this->$key =& $this->CI->$key; } } @@ -535,10 +579,134 @@ class CI_Loader { } else { - $obj->output->set_output(ob_get_contents()); + $this->CI->output->set_output(ob_get_contents()); ob_end_clean(); } } + + // -------------------------------------------------------------------- + + /** + * Load class + * + * This function loads the requested class. + * + * @access private + * @param string the item that is being loaded + * @param mixed any additional parameters + * @return void + */ + function _ci_load_class($class, $params = NULL) + { + // Prep the class name + $class = strtolower(str_replace(EXT, '', $class)); + + // Bug fix for backward compat. + // Kill this at some point in the future + if ($class == 'unit_test') + { + $class = 'unit'; + } + + // Is this a class extension request? + if (substr($class, 0, 3) == 'my_') + { + $class = preg_replace("/my_(.+)/", "\\1", $class); + $extend = TRUE; + } + else + { + $extend = FALSE; + } + + // Are we extending one of the base classes? + if ($extend == TRUE) + { + // Load the requested library from the main system/libraries folder + if (file_exists(BASEPATH.'libraries/'.ucfirst($class).EXT)) + { + include_once(BASEPATH.'libraries/'.ucfirst($class).EXT); + } + + // Now look for a matching library + foreach (array(ucfirst($class), $class) as $filename) + { + if (file_exists(APPPATH.'libraries/'.$filename.EXT)) + { + include_once(APPPATH.'libraries/'.$filename.EXT); + } + } + + return $this->_ci_init_class($filename, 'MY_', $params); + } + else + { + // Lets search for the requested library file and load it. + // For backward compatibility we'll test for filenames that are + // both uppercase and lower. + foreach (array(ucfirst($class), $class) as $filename) + { + for ($i = 1; $i < 3; $i++) + { + $path = ($i % 2) ? APPPATH : BASEPATH; + + if (file_exists($path.'libraries/'.$filename.EXT)) + { + include_once($path.'libraries/'.$filename.EXT); + return $this->_ci_init_class($filename, '', $params); + } + } + } + } + + // If we got this far we were unable to find the requested class + log_message('error', "Unable to load the requested class: ".$class); + show_error("Unable to load the class: ".$class); + } + + // -------------------------------------------------------------------- + + /** + * Instantiates a class + * + * @access private + * @param string + * @param string + * @return null + */ + function _ci_init_class($class, $prefix = '', $config = NULL) + { + // Is there an associated config file for this class? + if ($config == NULL) + { + if (file_exists(APPPATH.'config/'.$class.EXT)) + { + include_once(APPPATH.'config/'.$class.EXT); + } + } + + if ($prefix == '') + { + $name = ( ! class_exists($class)) ? 'CI_'.$class : $class; + } + else + { + $name = $prefix.$class; + } + + $varname = ( ! isset($remap[$class])) ? $class : $remap[$class]; + $varname = strtolower($varname); + + // Instantiate the class + if ($config !== NULL) + { + $this->CI->$varname = new $name($config); + } + else + { + $this->CI->$varname = new $name; + } + } // -------------------------------------------------------------------- @@ -546,27 +714,97 @@ class CI_Loader { * Autoloader * * The config/autoload.php file contains an array that permits sub-systems, - * plugins, and helpers to be loaded automatically. + * libraries, plugins, and helpers to be loaded automatically. * * @access private * @param array * @return void */ - function _ci_autoloader($autoload) - { - if ($autoload === FALSE) + function _ci_autoloader() + { + include_once(APPPATH.'config/autoload'.EXT); + + if ( ! isset($autoload)) { - return; + return FALSE; } - + + // Load any custome config file + if (count($autoload['config']) > 0) + { + foreach ($autoload['config'] as $key => $val) + { + $this->CI->config->load($val); + } + } + + // Load plugins, helpers, and scripts foreach (array('helper', 'plugin', 'script') as $type) { - if (isset($autoload[$type])) + if (isset($autoload[$type]) AND count($autoload[$type]) > 0) { $this->$type($autoload[$type]); - } + } } + + // A little tweak to remain backward compatible + // The $autoload['core'] item was deprecated + if ( ! isset($autoload['libraries'])) + { + $autoload['libraries'] = $autoload['core']; + } + + // Load libraries + if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0) + { + if (in_array('database', $autoload['libraries'])) + { + $this->database(); + $autoload['libraries'] = array_diff($autoload['libraries'], array('database')); + } + + if (in_array('model', $autoload['libraries'])) + { + $this->model(); + $autoload['libraries'] = array_diff($autoload['libraries'], array('model')); + } + + if (in_array('scaffolding', $autoload['libraries'])) + { + $this->scaffolding(); + $autoload['libraries'] = array_diff($autoload['libraries'], array('scaffolding')); + } + + foreach ($autoload['libraries'] as $item) + { + $this->library($item); + } + } } + + // -------------------------------------------------------------------- + + /** + * Assign to Models + * + * Makes sure that anything loaded by the loader class (libraries, plugins, etc.) + * will be available to modles, if any exist. + * + * @access public + * @param object + * @return array + */ + function _ci_assign_to_models() + { + if (count($this->models) == 0) + { + return; + } + foreach ($this->models as $model) + { + $this->CI->$model->_assign_libraries(); + } + } // -------------------------------------------------------------------- @@ -583,6 +821,7 @@ class CI_Loader { { return (is_object($object)) ? get_object_vars($object) : $object; } + } ?> \ No newline at end of file diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 9da73b03e..6142267bb 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -62,7 +62,7 @@ class CI_Profiler { // up in the order that it was defined if (preg_match("/(.+?)_end/i", $key, $match)) { - if (isset($this->obj->benchmark->marker[$match[1].'_end'])) + if (isset($this->obj->benchmark->marker[$match[1].'_end']) AND isset($this->obj->benchmark->marker[$match[1].'_start'])) { $profile[$match[1]] = $this->obj->benchmark->elapsed_time($match[1].'_start', $key); } -- cgit v1.2.3-24-g4f1b From b3ab70bfdce29b570c853ae53e370e54ca39da93 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 7 Oct 2006 03:07:29 +0000 Subject: --- system/libraries/Calendar.php | 14 ++++---- system/libraries/Controller.php | 46 ++++++++++++++++++++------ system/libraries/Loader.php | 3 +- system/libraries/Profiler.php | 28 ++++++++-------- system/libraries/Session.php | 71 +++++++++++++++++++++-------------------- system/libraries/Validation.php | 17 +++++----- 6 files changed, 103 insertions(+), 76 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 8cf151703..3cbbbfe6d 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -28,8 +28,8 @@ */ class CI_Calendar { + var $CI; var $lang; - var $obj; var $local_time; var $template = ''; var $start_day = 'sunday'; @@ -47,10 +47,10 @@ class CI_Calendar { */ function CI_Calendar() { - $this->obj =& get_instance(); - if ( ! in_array('calendar_lang'.EXT, $this->obj->lang->is_loaded, TRUE)) + $this->CI =& get_instance(); + if ( ! in_array('calendar_lang'.EXT, $this->CI->lang->is_loaded, TRUE)) { - $this->obj->lang->load('calendar'); + $this->CI->lang->load('calendar'); } $this->local_time = time(); @@ -268,12 +268,12 @@ class CI_Calendar { $month = $month_names[$month]; - if ($this->obj->lang->line($month) === FALSE) + if ($this->CI->lang->line($month) === FALSE) { return ucfirst(str_replace('cal_', '', $month)); } - return $this->obj->lang->line($month); + return $this->CI->lang->line($month); } // END get_month_name() @@ -310,7 +310,7 @@ class CI_Calendar { $days = array(); foreach ($day_names as $val) { - $days[] = ($this->obj->lang->line('cal_'.$val) === FALSE) ? ucfirst($val) : $this->obj->lang->line('cal_'.$val); + $days[] = ($this->CI->lang->line('cal_'.$val) === FALSE) ? ucfirst($val) : $this->CI->lang->line('cal_'.$val); } return $days; diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 88b49a9e6..58bec841e 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -40,9 +40,7 @@ class Controller extends CI_Base { function Controller() { parent::CI_Base(); - $this->_ci_initialize(); - log_message('debug', "Controller Class Initialized"); } @@ -62,22 +60,28 @@ class Controller extends CI_Base { // Assign all the class objects that were instantiated by the // front controller to local class variables so that CI can be // run as one big super object. - foreach (array('Config', 'Input', 'Benchmark', 'URI', 'Output') as $val) + $classes = array( + 'config' => 'Config', + 'input' => 'Input', + 'benchmark' => 'Benchmark', + 'uri' => 'URI', + 'output' => 'Output', + 'lang' => 'Language' + ); + + foreach ($classes as $var => $class) { - $class = strtolower($val); - $this->$class =& _load_class($val); + $this->$var =& _load_class($class); } - $this->lang =& _load_class('Language'); - - // In PHP 4 the Controller class is a child of CI_Loader. - // In PHP 5 we run it as its own class. + + // In PHP 5 the Controller class is run as a discreet + // class. In PHP 4 it extends the Controller if (floor(phpversion()) >= 5) { $this->load = new CI_Loader(); } - // Load everything specified in the autoload.php file $this->load->_ci_autoloader(); @@ -92,6 +96,28 @@ class Controller extends CI_Base { } } + // -------------------------------------------------------------------- + + /** + * Run Scaffolding + * + * @access private + * @return voikd + */ + function _ci_scaffolding() + { + if ($this->_ci_scaffolding === FALSE OR $this->_ci_scaff_table === FALSE) + { + show_404('Scaffolding unavailable'); + } + + $method = ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) ? 'view' : $this->uri->segment(3); + + require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); + $scaff = new Scaffolding($this->_ci_scaff_table); + $scaff->$method(); + } + } // END _Controller class diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index f823d95e8..90dc0f140 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -31,12 +31,11 @@ class CI_Loader { var $CI; var $ob_level; var $cached_vars = array(); + var $models = array(); var $helpers = array(); var $plugins = array(); var $scripts = array(); - var $languages = array(); var $view_path = ''; - var $models = array(); /** * Constructor diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 6142267bb..d91f23193 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -32,12 +32,12 @@ */ class CI_Profiler { - var $obj; + var $CI; function CI_Profiler() { - $this->obj =& get_instance(); - $this->obj->load->language('profiler'); + $this->CI =& get_instance(); + $this->CI->load->language('profiler'); } // -------------------------------------------------------------------- @@ -56,15 +56,15 @@ class CI_Profiler { function _compile_benchmarks() { $profile = array(); - foreach ($this->obj->benchmark->marker as $key => $val) + 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->obj->benchmark->marker[$match[1].'_end']) AND isset($this->obj->benchmark->marker[$match[1].'_start'])) + if (isset($this->CI->benchmark->marker[$match[1].'_end']) AND isset($this->CI->benchmark->marker[$match[1].'_start'])) { - $profile[$match[1]] = $this->obj->benchmark->elapsed_time($match[1].'_start', $key); + $profile[$match[1]] = $this->CI->benchmark->elapsed_time($match[1].'_start', $key); } } } @@ -76,7 +76,7 @@ class CI_Profiler { $output = "\n\n"; $output .= '
'; $output .= "\n"; - $output .= '  '.$this->obj->lang->line('profiler_benchmarks').'  '; + $output .= '  '.$this->CI->lang->line('profiler_benchmarks').'  '; $output .= "\n"; $output .= "\n\n\n"; @@ -100,22 +100,22 @@ class CI_Profiler { $output = "\n\n"; $output .= '
'; $output .= "\n"; - $output .= '  '.$this->obj->lang->line('profiler_queries').'  '; + $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; $output .= "\n"; if ( ! class_exists('CI_DB_driver')) { - $output .= "
".$this->obj->lang->line('profiler_no_db')."
"; + $output .= "
".$this->CI->lang->line('profiler_no_db')."
"; } else { - if (count($this->obj->db->queries) == 0) + if (count($this->CI->db->queries) == 0) { - $output .= "
".$this->obj->lang->line('profiler_no_queries')."
"; + $output .= "
".$this->CI->lang->line('profiler_no_queries')."
"; } else { - foreach ($this->obj->db->queries as $val) + foreach ($this->CI->db->queries as $val) { $output .= '
'; $output .= $val; @@ -136,12 +136,12 @@ class CI_Profiler { $output = "\n\n"; $output .= '
'; $output .= "\n"; - $output .= '  '.$this->obj->lang->line('profiler_post_data').'  '; + $output .= '  '.$this->CI->lang->line('profiler_post_data').'  '; $output .= "\n"; if (count($_POST) == 0) { - $output .= "
".$this->obj->lang->line('profiler_no_post')."
"; + $output .= "
".$this->CI->lang->line('profiler_no_post')."
"; } else { diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 28e469da7..16f373fd0 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -26,6 +26,7 @@ */ class CI_Session { + var $CI; var $now; var $encryption = TRUE; var $use_database = FALSE; @@ -34,7 +35,7 @@ class CI_Session { var $sess_cookie = 'ci_session'; var $userdata = array(); var $gc_probability = 5; - var $object; + /** @@ -45,7 +46,7 @@ class CI_Session { */ function CI_Session() { - $this->object =& get_instance(); + $this->CI =& get_instance(); log_message('debug', "Session Class Initialized"); $this->sess_run(); @@ -73,7 +74,7 @@ class CI_Session { * "last_visit" times based on each user's locale. * */ - if (strtolower($this->object->config->item('time_reference')) == 'gmt') + if (strtolower($this->CI->config->item('time_reference')) == 'gmt') { $now = time(); $this->now = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); @@ -97,13 +98,13 @@ class CI_Session { * two years from now. * */ - $expiration = $this->object->config->item('sess_expiration'); + $expiration = $this->CI->config->item('sess_expiration'); if (is_numeric($expiration)) { if ($expiration > 0) { - $this->sess_length = $this->object->config->item('sess_expiration'); + $this->sess_length = $this->CI->config->item('sess_expiration'); } else { @@ -112,25 +113,25 @@ class CI_Session { } // Do we need encryption? - $this->encryption = $this->object->config->item('sess_encrypt_cookie'); + $this->encryption = $this->CI->config->item('sess_encrypt_cookie'); if ($this->encryption == TRUE) { - $this->object->load->library('encrypt'); + $this->CI->load->library('encrypt'); } // Are we using a database? - if ($this->object->config->item('sess_use_database') === TRUE AND $this->object->config->item('sess_table_name') != '') + if ($this->CI->config->item('sess_use_database') === TRUE AND $this->CI->config->item('sess_table_name') != '') { $this->use_database = TRUE; - $this->session_table = $this->object->config->item('sess_table_name'); - $this->object->load->database(); + $this->session_table = $this->CI->config->item('sess_table_name'); + $this->CI->load->database(); } // Set the cookie name - if ($this->object->config->item('sess_cookie_name') != FALSE) + if ($this->CI->config->item('sess_cookie_name') != FALSE) { - $this->sess_cookie = $this->object->config->item('cookie_prefix').$this->object->config->item('sess_cookie_name'); + $this->sess_cookie = $this->CI->config->item('cookie_prefix').$this->CI->config->item('sess_cookie_name'); } /* @@ -172,7 +173,7 @@ class CI_Session { function sess_read() { // Fetch the cookie - $session = $this->object->input->cookie($this->sess_cookie); + $session = $this->CI->input->cookie($this->sess_cookie); if ($session === FALSE) { @@ -183,7 +184,7 @@ class CI_Session { // Decrypt and unserialize the data if ($this->encryption == TRUE) { - $session = $this->object->encrypt->decode($session); + $session = $this->CI->encrypt->decode($session); } $session = @unserialize($this->strip_slashes($session)); @@ -202,14 +203,14 @@ class CI_Session { } // Does the IP Match? - if ($this->object->config->item('sess_match_ip') == TRUE AND $session['ip_address'] != $this->object->input->ip_address()) + if ($this->CI->config->item('sess_match_ip') == TRUE AND $session['ip_address'] != $this->CI->input->ip_address()) { $this->sess_destroy(); return FALSE; } // Does the User Agent Match? - if ($this->object->config->item('sess_match_useragent') == TRUE AND $session['user_agent'] != substr($this->object->input->user_agent(), 0, 50)) + if ($this->CI->config->item('sess_match_useragent') == TRUE AND $session['user_agent'] != substr($this->CI->input->user_agent(), 0, 50)) { $this->sess_destroy(); return FALSE; @@ -218,19 +219,19 @@ class CI_Session { // Is there a corresponding session in the DB? if ($this->use_database === TRUE) { - $this->object->db->where('session_id', $session['session_id']); + $this->CI->db->where('session_id', $session['session_id']); - if ($this->object->config->item('sess_match_ip') == TRUE) + if ($this->CI->config->item('sess_match_ip') == TRUE) { - $this->object->db->where('ip_address', $session['ip_address']); + $this->CI->db->where('ip_address', $session['ip_address']); } - if ($this->object->config->item('sess_match_useragent') == TRUE) + if ($this->CI->config->item('sess_match_useragent') == TRUE) { - $this->object->db->where('user_agent', $session['user_agent']); + $this->CI->db->where('user_agent', $session['user_agent']); } - $query = $this->object->db->get($this->session_table); + $query = $this->CI->db->get($this->session_table); if ($query->num_rows() == 0) { @@ -242,8 +243,8 @@ class CI_Session { $row = $query->row(); if (($row->last_activity + $this->sess_length) < $this->now) { - $this->object->db->where('session_id', $session['session_id']); - $this->object->db->delete($this->session_table); + $this->CI->db->where('session_id', $session['session_id']); + $this->CI->db->delete($this->session_table); $this->sess_destroy(); return FALSE; } @@ -272,15 +273,15 @@ class CI_Session { if ($this->encryption == TRUE) { - $cookie_data = $this->object->encrypt->encode($cookie_data); + $cookie_data = $this->CI->encrypt->encode($cookie_data); } setcookie( $this->sess_cookie, $cookie_data, $this->sess_length + $this->now, - $this->object->config->item('cookie_path'), - $this->object->config->item('cookie_domain'), + $this->CI->config->item('cookie_path'), + $this->CI->config->item('cookie_domain'), 0 ); } @@ -304,8 +305,8 @@ class CI_Session { $this->userdata = array( 'session_id' => md5(uniqid($sessid, TRUE)), - 'ip_address' => $this->object->input->ip_address(), - 'user_agent' => substr($this->object->input->user_agent(), 0, 50), + 'ip_address' => $this->CI->input->ip_address(), + 'user_agent' => substr($this->CI->input->user_agent(), 0, 50), 'last_activity' => $this->now ); @@ -313,7 +314,7 @@ class CI_Session { // Save the session in the DB if needed if ($this->use_database === TRUE) { - $this->object->db->query($this->object->db->insert_string($this->session_table, $this->userdata)); + $this->CI->db->query($this->CI->db->insert_string($this->session_table, $this->userdata)); } // Write the cookie @@ -342,7 +343,7 @@ class CI_Session { // Update the session in the DB if needed if ($this->use_database === TRUE) { - $this->object->db->query($this->object->db->update_string($this->session_table, array('last_activity' => $this->now), array('session_id' => $this->userdata['session_id']))); + $this->CI->db->query($this->CI->db->update_string($this->session_table, array('last_activity' => $this->now), array('session_id' => $this->userdata['session_id']))); } // Write the cookie @@ -364,8 +365,8 @@ class CI_Session { $this->sess_cookie, addslashes(serialize(array())), ($this->now - 31500000), - $this->object->config->item('cookie_path'), - $this->object->config->item('cookie_domain'), + $this->CI->config->item('cookie_path'), + $this->CI->config->item('cookie_domain'), 0 ); } @@ -389,8 +390,8 @@ class CI_Session { { $expire = $this->now - $this->sess_length; - $this->object->db->where("last_activity < {$expire}"); - $this->object->db->delete($this->session_table); + $this->CI->db->where("last_activity < {$expire}"); + $this->CI->db->delete($this->session_table); log_message('debug', 'Session garbage collection performed.'); } diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index ff5970837..5322be0e9 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -26,6 +26,7 @@ */ class CI_Validation { + var $CI; var $error_string = ''; var $_error_array = array(); var $_rules = array(); @@ -35,7 +36,7 @@ class CI_Validation { var $_safe_form_data = FALSE; var $_error_prefix = '

'; var $_error_suffix = '

'; - var $obj; + /** @@ -44,7 +45,7 @@ class CI_Validation { */ function CI_Validation() { - $this->obj =& get_instance(); + $this->CI =& get_instance(); log_message('debug', "Validation Class Initialized"); } @@ -185,7 +186,7 @@ class CI_Validation { } // Load the language file containing error messages - $this->obj->lang->load('validation'); + $this->CI->lang->load('validation'); // Cycle through the rules and test for errors foreach ($this->_rules as $field => $rules) @@ -217,7 +218,7 @@ class CI_Validation { { if ( ! isset($this->_error_messages['isset'])) { - if (FALSE === ($line = $this->obj->lang->line('isset'))) + if (FALSE === ($line = $this->CI->lang->line('isset'))) { $line = 'The field was not set'; } @@ -267,12 +268,12 @@ class CI_Validation { // Call the function that corresponds to the rule if ($callback === TRUE) { - if ( ! method_exists($this->obj, $rule)) + if ( ! method_exists($this->CI, $rule)) { continue; } - $result = $this->obj->$rule($_POST[$field], $param); + $result = $this->CI->$rule($_POST[$field], $param); // If the field isn't required and we just processed a callback we'll move on... if ( ! in_array('required', $ex, TRUE) AND $result !== FALSE) @@ -309,7 +310,7 @@ class CI_Validation { { if ( ! isset($this->_error_messages[$rule])) { - if (FALSE === ($line = $this->obj->lang->line($rule))) + if (FALSE === ($line = $this->CI->lang->line($rule))) { $line = 'Unable to access an error message corresponding to your field name.'; } @@ -698,7 +699,7 @@ class CI_Validation { */ function xss_clean($str) { - $_POST[$this->_current_field] = $this->obj->input->xss_clean($str); + $_POST[$this->_current_field] = $this->CI->input->xss_clean($str); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 88a8ad187b13b36d6120eae2344fe16c3a76219d Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 7 Oct 2006 03:16:32 +0000 Subject: --- system/libraries/Controller.php | 2 +- system/libraries/Email.php | 6 +++--- system/libraries/Encrypt.php | 4 ++-- system/libraries/Image_lib.php | 8 ++++---- system/libraries/Language.php | 4 ++-- system/libraries/Model.php | 8 ++++---- system/libraries/Output.php | 24 ++++++++++++------------ system/libraries/Pagination.php | 6 +++--- system/libraries/Parser.php | 6 +++--- system/libraries/Profiler.php | 4 +--- system/libraries/Unit.php | 12 ++++++------ system/libraries/Upload.php | 12 ++++++------ system/libraries/Xmlrpc.php | 12 ++++++------ system/libraries/Xmlrpcs.php | 4 ++-- 14 files changed, 55 insertions(+), 57 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 58bec841e..4b9e3e960 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -102,7 +102,7 @@ class Controller extends CI_Base { * Run Scaffolding * * @access private - * @return voikd + * @return void */ function _ci_scaffolding() { diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 99de17414..23f7fe456 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1629,10 +1629,10 @@ class CI_Email { */ function _set_error_message($msg, $val = '') { - $obj =& get_instance(); - $obj->lang->load('email'); + $CI =& get_instance(); + $CI->lang->load('email'); - if (FALSE === ($line = $obj->lang->line($msg))) + if (FALSE === ($line = $CI->lang->line($msg))) { $this->_debug_msg[] = str_replace('%s', $val, $msg)."
"; } diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 537b1ab20..2a1de6f37 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -66,8 +66,8 @@ class CI_Encrypt { return $this->encryption_key; } - $obj =& get_instance(); - $key = $obj->config->item('encryption_key'); + $CI =& get_instance(); + $key = $CI->config->item('encryption_key'); if ($key === FALSE) { diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index ca1d7478b..79b2f9c1c 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1503,22 +1503,22 @@ class CI_Image_lib { */ function set_error($msg) { - $obj =& get_instance(); - $obj->lang->load('imglib'); + $CI =& get_instance(); + $CI->lang->load('imglib'); if (is_array($msg)) { foreach ($msg as $val) { - $msg = ($obj->lang->line($val) == FALSE) ? $val : $obj->lang->line($val); + $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val); $this->error_msg[] = $msg; log_message('error', $msg); } } else { - $msg = ($obj->lang->line($msg) == FALSE) ? $msg : $obj->lang->line($msg); + $msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg); $this->error_msg[] = $msg; log_message('error', $msg); } diff --git a/system/libraries/Language.php b/system/libraries/Language.php index dabfd4145..00e2fb7e8 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -61,8 +61,8 @@ class CI_Language { if ($idiom == '') { - $obj =& get_instance(); - $deft_lang = $obj->config->item('language'); + $CI =& get_instance(); + $deft_lang = $CI->config->item('language'); $idiom = ($deft_lang == '') ? 'english' : $deft_lang; } diff --git a/system/libraries/Model.php b/system/libraries/Model.php index 55c995636..46f0367cb 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -49,18 +49,18 @@ class Model { */ function _assign_libraries($use_reference = TRUE) { - $obj =& get_instance(); - foreach (get_object_vars($obj) as $key => $var) + $CI =& get_instance(); + foreach (get_object_vars($CI) as $key => $var) { if (is_object($var) AND ! isset($this->$key)) { if ($use_reference === TRUE) { - $this->$key =& $obj->$key; + $this->$key =& $CI->$key; } else { - $this->$key = $obj->$key; + $this->$key = $CI->$key; } } } diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 4ab5dd23c..507beab59 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -135,7 +135,7 @@ class CI_Output { */ function _display($output = '') { - // Note: We use globals because we can't use $obj =& get_instance() + // 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. global $BM, $CFG; @@ -207,25 +207,25 @@ class CI_Output { // -------------------------------------------------------------------- // Grab the super object. We'll need it in a moment... - $obj =& get_instance(); + $CI =& get_instance(); // Do we need to generate profile data? // If so, load the Profile class and run it. if ($this->enable_profiler == TRUE) { - $obj->load->library('profiler'); + $CI->load->library('profiler'); // If the output data contains closing and tags // we will remove them and add them back after we insert the profile data if (preg_match("|.*?|is", $output)) { $output = preg_replace("|.*?|is", '', $output); - $output .= $obj->profiler->run(); + $output .= $CI->profiler->run(); $output .= ''; } else { - $output .= $obj->profiler->run(); + $output .= $CI->profiler->run(); } } @@ -233,9 +233,9 @@ class CI_Output { // Does the controller contain a function named _output()? // If so send the output there. Otherwise, echo it. - if (method_exists($obj, '_output')) + if (method_exists($CI, '_output')) { - $obj->_output($output); + $CI->_output($output); } else { @@ -256,8 +256,8 @@ class CI_Output { */ function _write_cache($output) { - $obj =& get_instance(); - $path = $obj->config->item('cache_path'); + $CI =& get_instance(); + $path = $CI->config->item('cache_path'); $cache_path = ($path == '') ? BASEPATH.'cache/' : $path; @@ -266,9 +266,9 @@ class CI_Output { return; } - $uri = $obj->config->item('base_url'). - $obj->config->item('index_page'). - $obj->uri->uri_string(); + $uri = $CI->config->item('base_url'). + $CI->config->item('index_page'). + $CI->uri->uri_string(); $cache_path .= md5($uri); diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 867d214fc..efbe6c27f 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -122,10 +122,10 @@ class CI_Pagination { } // Determine the current page number. - $obj =& get_instance(); - if ($obj->uri->segment($this->uri_segment) != 0) + $CI =& get_instance(); + if ($CI->uri->segment($this->uri_segment) != 0) { - $this->cur_page = $obj->uri->segment($this->uri_segment); + $this->cur_page = $CI->uri->segment($this->uri_segment); } if ( ! is_numeric($this->cur_page)) diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 42e78b0ee..a0c9dab9e 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -44,8 +44,8 @@ class CI_Parser { */ function parse($template, $data, $return = FALSE) { - $obj =& get_instance(); - $template = $obj->load->view($template, $data, TRUE); + $CI =& get_instance(); + $template = $CI->load->view($template, $data, TRUE); if ($template == '') { @@ -66,7 +66,7 @@ class CI_Parser { if ($return == FALSE) { - $obj->output->final_output = $template; + $CI->output->final_output = $template; } return $template; diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index d91f23193..3370c9113 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -173,9 +173,7 @@ class CI_Profiler { * @return string */ function run($output = '') - { - $obj =& get_instance(); - + { $output = '
'; $output .= "
"; diff --git a/system/libraries/Unit.php b/system/libraries/Unit.php index 0df78c253..6573f4269 100644 --- a/system/libraries/Unit.php +++ b/system/libraries/Unit.php @@ -171,8 +171,8 @@ class CI_Unit { */ function result($results = array()) { - $obj =& get_instance(); - $obj->load->language('unit_test'); + $CI =& get_instance(); + $CI->load->language('unit_test'); if (count($results) == 0) { @@ -189,20 +189,20 @@ class CI_Unit { { foreach ($val as $k => $v) { - if (FALSE !== ($line = $obj->lang->line(strtolower('ut_'.$v)))) + if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$v)))) { $v = $line; } - $temp[$obj->lang->line('ut_'.$k)] = $v; + $temp[$CI->lang->line('ut_'.$k)] = $v; } } else { - if (FALSE !== ($line = $obj->lang->line(strtolower('ut_'.$val)))) + if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$val)))) { $val = $line; } - $temp[$obj->lang->line('ut_'.$key)] = $val; + $temp[$CI->lang->line('ut_'.$key)] = $val; } } diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 37fccdfd8..13fa8acdf 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -684,8 +684,8 @@ class CI_Upload { $data = fread($fp, filesize($file)); - $obj =& get_instance(); - $data = $obj->input->xss_clean($data); + $CI =& get_instance(); + $data = $CI->input->xss_clean($data); fwrite($fp, $data); flock($fp, LOCK_UN); @@ -703,21 +703,21 @@ class CI_Upload { */ function set_error($msg) { - $obj =& get_instance(); - $obj->lang->load('upload'); + $CI =& get_instance(); + $CI->lang->load('upload'); if (is_array($msg)) { foreach ($msg as $val) { - $msg = ($obj->lang->line($val) == FALSE) ? $val : $obj->lang->line($val); + $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val); $this->error_msg[] = $msg; log_message('error', $msg); } } else { - $msg = ($obj->lang->line($msg) == FALSE) ? $msg : $obj->lang->line($msg); + $msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg); $this->error_msg[] = $msg; log_message('error', $msg); } diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 4cb16f74e..0a3dedae1 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -493,7 +493,7 @@ class XML_RPC_Response function decode($array=FALSE) { - $obj =& get_instance(); + $CI =& get_instance(); if ($array !== FALSE && is_array($array)) { @@ -505,7 +505,7 @@ class XML_RPC_Response } else { - $array[$key] = $obj->input->xss_clean($array[$key]); + $array[$key] = $CI->input->xss_clean($array[$key]); } } @@ -521,7 +521,7 @@ class XML_RPC_Response } else { - $result = $obj->input->xss_clean($result); + $result = $CI->input->xss_clean($result); } } @@ -1107,7 +1107,7 @@ class XML_RPC_Message extends CI_Xmlrpc function output_parameters($array=FALSE) { - $obj =& get_instance(); + $CI =& get_instance(); if ($array !== FALSE && is_array($array)) { @@ -1119,7 +1119,7 @@ class XML_RPC_Message extends CI_Xmlrpc } else { - $array[$key] = $obj->input->xss_clean($array[$key]); + $array[$key] = $CI->input->xss_clean($array[$key]); } } @@ -1139,7 +1139,7 @@ class XML_RPC_Message extends CI_Xmlrpc } else { - $parameters[] = $obj->input->xss_clean($a_param); + $parameters[] = $CI->input->xss_clean($a_param); } } } diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index b47104857..e4d3cffde 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -318,8 +318,8 @@ class CI_Xmlrpcs extends CI_Xmlrpc } else { - $obj =& get_instance(); - return $obj->$method_parts['1']($m); + $CI =& get_instance(); + return $CI->$method_parts['1']($m); //$class = new $method_parts['0']; //return $class->$method_parts['1']($m); //return call_user_func(array(&$method_parts['0'],$method_parts['1']), $m); -- cgit v1.2.3-24-g4f1b From df752b2448b597e6af1adb79d20681be9bad1a8e Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 8 Oct 2006 07:17:13 +0000 Subject: --- system/libraries/User_agent.php | 645 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 645 insertions(+) create mode 100644 system/libraries/User_agent.php (limited to 'system/libraries') diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php new file mode 100644 index 000000000..33e8451c6 --- /dev/null +++ b/system/libraries/User_agent.php @@ -0,0 +1,645 @@ + 'Windows Longhorn', + 'windows nt 5.2' => 'Windows 2003', + 'windows nt 5.0' => 'Windows 2000', + 'windows nt 5.1' => 'Windows XP', + 'windows nt 4.0' => 'Windows NT 4.0', + 'winnt4.0' => 'Windows NT 4.0', + 'winnt 4.0' => 'Windows NT', + 'winnt' => 'Windows NT', + 'windows 98' => 'Windows 98', + 'win98' => 'Windows 98', + 'windows 95' => 'Windows 95', + 'win95' => 'Windows 95', + 'windows' => 'Unknown Windows OS', + 'mac os x' => 'Mac OS X', + 'freebsd' => 'FreeBSD', + 'ppc' => 'Macintosh', + 'sunos' => 'Sun Solaris', + 'linux' => 'Linux', + 'debian' => 'Debian', + 'beos' => 'BeOS', + 'apachebench' => 'ApacheBench', + 'aix' => 'AIX', + 'irix' => 'Irix', + 'osf' => 'DEC OSF', + 'hp-ux' => 'HP-UX', + 'netbsd' => 'NetBSD', + 'bsdi' => 'BSDi', + 'openbsd' => 'OpenBSD', + 'gnu' => 'GNU/Linux', + 'unix' => 'Unknown Unix OS' + ); + + var $browsers = array( + 'Opera' => 'Opera', + 'MSIE' => 'Internet Explorer', + 'Internet Explorer' => 'Internet Explorer', + 'Shiira' => 'Shiira', + 'Firefox' => 'Firefox', + 'Camino' => 'Camino', + 'Mozilla' => 'Mozilla', + 'Safari' => 'Safari', + 'Konqueror' => 'Konqueror', + 'Lynx' => 'Lynx', + 'ANTFresco' => 'Fresco' + ); + + var $mobiles = array( + 'mobileexplorer' => 'Mobile Explorer', + 'openwave' => 'Open Wave', + 'opera mini' => 'Opera Mini', + 'operamini' => 'Opera Mini', + 'elaine' => 'Palm', + 'palmsource' => 'Palm', + 'digital paths' => 'Palm', + 'avantgo' => 'Avantgo', + 'xiino' => 'Xiino', + 'palmscape' => 'Palmscape', + 'nokia' => 'Nokia', + 'ericsson' => 'Ericsson', + 'blackBerry' => 'BlackBerry', + 'motorola' => 'Motorola' + ); + + var $robots = array( + + 'googlebot' => 'Googlebot', + 'msnbot' => 'MSNBot', + 'slurp' => 'Inktomi Slurp', + 'yahoo' => 'Yahoo', + 'askjeeves' => 'AskJeeves', + 'fastcrawler' => 'FastCrawler', + 'infoseek' => 'InfoSeek Robot 1.0', + 'lycos' => 'Lycos', + 'abcdatos' => 'ABCdatos BotLink', + 'Acme.Spider' => 'Acme.Spider', + 'ahoythehomepagefinder' => 'Ahoy! The Homepage Finder', + 'Alkaline' => 'Alkaline', + 'anthill' => 'Anthill', + 'appie' => 'Walhello appie', + 'arachnophilia' => 'Arachnophilia', + 'arale' => 'Arale', + 'araneo' => 'Araneo', + 'araybot' => 'AraybOt', + 'architext' => 'ArchitextSpider', + 'aretha' => 'Aretha', + 'ariadne' => 'ARIADNE', + 'arks' => 'arks', + 'aspider' => 'ASpider (Associative Spider)', + 'atn.txt' => 'ATN Worldwide', + 'atomz' => 'Atomz.com Search Robot', + 'auresys' => 'AURESYS', + 'backrub' => 'BackRub', + 'bbot' => 'BBot', + 'bigbrother' => 'Big Brother', + 'bjaaland' => 'Bjaaland', + 'blackwidow' => 'BlackWidow', + 'blindekuh' => 'Die Blinde Kuh', + 'Bloodhound' => 'Bloodhound', + 'borg-bot' => 'Borg-Bot', + 'boxseabot' => 'BoxSeaBot', + 'brightnet' => 'bright.net caching robot', + 'bspider' => 'BSpider', + 'cactvschemistryspider' => 'CACTVS Chemistry Spider', + 'calif' => 'Calif', + 'cassandra' => 'Cassandra', + 'cgireader' => 'Digimarc Marcspider/CGI', + 'checkbot' => 'Checkbot', + 'christcrawler' => 'ChristCrawler.com', + 'churl' => 'churl', + 'cienciaficcion' => 'cIeNcIaFiCcIoN.nEt', + 'cmc' => 'CMC/0.01', + 'Collective' => 'Collective', + 'combine' => 'Combine System', + 'confuzzledbot' => 'ConfuzzledBot', + 'coolbot' => 'CoolBot', + 'core' => 'Web Core / Roots', + 'cosmos' => 'XYLEME Robot', + 'cruiser' => 'Internet Cruiser Robot', + 'cusco' => 'Cusco', + 'cyberspyder' => 'CyberSpyder Link Test', + 'cydralspider' => 'CydralSpider', + 'desertrealm' => 'Desert Realm Spider', + 'deweb' => 'DeWeb(c) Katalog/Index', + 'dienstspider' => 'DienstSpider', + 'digger' => 'Digger', + 'diibot' => 'Digital Integrity Robot', + 'directhit' => 'Direct Hit Grabber', + 'dnabot' => 'DNAbot', + 'download_express' => 'DownLoad Express', + 'dragonbot' => 'DragonBot', + 'e-collector' => 'e-collector', + 'ebiness' => 'EbiNess', + 'eit' => 'EIT Link Verifier Robot', + 'elfinbot' => 'ELFINBOT', + 'emacs' => 'Emacs-w3 Search Engine', + 'emcspider' => 'ananzi', + 'esculapio' => 'esculapio', + 'esther' => 'Esther', + 'evliyacelebi' => 'Evliya Celebi', + 'nzexplorer' => 'nzexplorer', + 'fdse' => 'Fluid Dynamics Search Engine robot', + 'felix' => 'Felix IDE', + 'ferret' => 'Wild Ferret Web Hopper #1, #2, #3', + 'fetchrover' => 'FetchRover', + 'fido' => 'fido', + 'finnish' => 'Hämähäkki', + 'fireball' => 'KIT-Fireball', + 'fish' => 'Fish search', + 'fouineur' => 'Fouineur', + 'francoroute' => 'Robot Francoroute', + 'freecrawl' => 'Freecrawl', + 'funnelweb' => 'FunnelWeb', + 'gama' => 'gammaSpider, FocusedCrawler', + 'gazz' => 'gazz', + 'gcreep' => 'GCreep', + 'getbot' => 'GetBot', + 'geturl' => 'GetURL', + 'golem' => 'Golem', + 'grapnel' => 'Grapnel/0.01 Experiment', + 'griffon' => 'Griffon ', + 'gromit' => 'Gromit', + 'gulliver' => 'Northern Light Gulliver', + 'gulperbot' => 'Gulper Bot', + 'hambot' => 'HamBot', + 'harvest' => 'Harvest', + 'havindex' => 'havIndex', + 'hi' => 'HI (HTML Index) Search', + 'hometown' => 'Hometown Spider Pro', + 'wired-digital' => 'Wired Digital', + 'htdig' => 'ht://Dig', + 'htmlgobble' => 'HTMLgobble', + 'hyperdecontextualizer' => 'Hyper-Decontextualizer', + 'iajabot' => 'iajaBot', + 'ibm' => 'IBM_Planetwide', + 'iconoclast' => 'Popular Iconoclast', + 'Ilse' => 'Ingrid', + 'imagelock' => 'Imagelock ', + 'incywincy' => 'IncyWincy', + 'informant' => 'Informant', + 'infoseeksidewinder' => 'Infoseek Sidewinder', + 'infospider' => 'InfoSpiders', + 'inspectorwww' => 'Inspector Web', + 'intelliagent' => 'IntelliAgent', + 'irobot' => 'I, Robot', + 'iron33' => 'Iron33', + 'israelisearch' => 'Israeli-search', + 'javabee' => 'JavaBee', + 'JBot' => 'JBot Java Web Robot', + 'jcrawler' => 'JCrawler', + 'jobo' => 'JoBo Java Web Robot', + 'jobot' => 'Jobot', + 'joebot' => 'JoeBot', + 'jubii' => 'The Jubii Indexing Robot', + 'jumpstation' => 'JumpStation', + 'kapsi' => 'image.kapsi.net', + 'katipo' => 'Katipo', + 'kdd' => 'KDD-Explorer', + 'kilroy' => 'Kilroy', + 'ko_yappo_robot' => 'KO_Yappo_Robot', + 'labelgrabber.txt' => 'LabelGrabber', + 'larbin' => 'larbin', + 'legs' => 'legs', + 'linkidator' => 'Link Validator', + 'linkscan' => 'LinkScan', + 'linkwalker' => 'LinkWalker', + 'lockon' => 'Lockon', + 'logo_gif' => 'logo.gif Crawler', + 'magpie' => 'Magpie', + 'marvin' => 'marvin/infoseek', + 'mattie' => 'Mattie', + 'mediafox' => 'MediaFox', + 'merzscope' => 'MerzScope', + 'meshexplorer' => 'NEC-MeshExplorer', + 'MindCrawler' => 'MindCrawler', + 'mnogosearch' => 'mnoGoSearch search engine software', + 'moget' => 'moget', + 'momspider' => 'MOMspider', + 'monster' => 'Monster', + 'motor' => 'Motor', + 'muncher' => 'Muncher', + 'muninn' => 'Muninn', + 'muscatferret' => 'Muscat Ferret', + 'mwdsearch' => 'Mwd.Search', + 'myweb' => 'Internet Shinchakubin', + 'NDSpider' => 'NDSpider', + 'netcarta' => 'NetCarta WebMap Engine', + 'netmechanic' => 'NetMechanic', + 'netscoop' => 'NetScoop', + 'newscan-online' => 'newscan-online', + 'nhse' => 'NHSE Web Forager', + 'nomad' => 'Nomad', + 'northstar' => 'The NorthStar Robot', + 'objectssearch' => 'ObjectsSearch', + 'occam' => 'Occam', + 'octopus' => 'HKU WWW Octopus', + 'OntoSpider' => 'OntoSpider', + 'openfind' => 'Openfind data gatherer', + 'orb_search' => 'Orb Search', + 'packrat' => 'Pack Rat', + 'pageboy' => 'PageBoy', + 'parasite' => 'ParaSite', + 'patric' => 'Patric', + 'pegasus' => 'pegasus', + 'perignator' => 'The Peregrinator', + 'perlcrawler' => 'PerlCrawler 1.0', + 'phantom' => 'Phantom', + 'phpdig' => 'PhpDig', + 'pitkow' => 'html_analyzer', + 'pjspider' => 'Portal Juice Spider', + 'pka' => 'PGP Key Agent', + 'poppi' => 'Poppi', + 'portalb' => 'PortalB Spider', + 'psbot' => 'psbot', + 'Puu' => 'GetterroboPlus Puu', + 'python' => 'The Python Robot', + 'raven ' => 'Raven Search', + 'rbse' => 'RBSE Spider', + 'resumerobot' => 'Resume Robot', + 'rhcs' => 'RoadHouse Crawling System', + 'rixbot' => 'RixBot', + 'roadrunner' => 'Road Runner: The ImageScape Robot', + 'robbie' => 'Robbie the Robot', + 'robi' => 'ComputingSite Robi/1.0', + 'robocrawl' => 'RoboCrawl Spider', + 'robofox' => 'RoboFox', + 'robozilla' => 'Robozilla', + 'roverbot' => 'Roverbot', + 'rules' => 'RuLeS', + 'safetynetrobot' => 'SafetyNet Robot', + 'scooter' => 'Scooter', + 'search_au' => 'Search.Aus-AU.COM', + 'search-info' => 'Sleek', + 'searchprocess' => 'SearchProcess', + 'senrigan' => 'Senrigan', + 'sgscout' => 'SG-Scout', + 'shaggy' => 'ShagSeeker', + 'sift' => 'Sift', + 'simbot' => 'Simmany Robot Ver1.0', + 'site-valet' => 'Site Valet', + 'sitetech' => 'SiteTech-Rover', + 'skymob' => 'Skymob.com', + 'slcrawler' => 'SLCrawler', + 'smartspider' => 'Smart Spider', + 'snooper' => 'Snooper', + 'solbot' => 'Solbot', + 'speedy' => 'Speedy Spider', + 'spider_monkey' => 'spider_monkey', + 'spiderbot' => 'SpiderBot', + 'spiderline' => 'Spiderline Crawler', + 'spiderman' => 'SpiderMan', + 'spiderview' => 'SpiderView(tm)', + 'spry' => 'Spry Wizard Robot', + 'ssearcher' => 'Site Searcher', + 'suke' => 'Suke', + 'suntek' => 'suntek search engine', + 'sven' => 'Sven', + 'sygol' => 'Sygol ', + 'tach_bw' => 'TACH Black Widow', + 'tarantula' => 'Tarantula', + 'tarspider' => 'tarspider', + 'tcl' => 'Tcl W3 Robot', + 'techbot' => 'TechBOT', + 'templeton' => 'Templeton', + 'titin' => 'TitIn', + 'titan' => 'TITAN', + 'tkwww' => 'The TkWWW Robot', + 'tlspider' => 'TLSpider', + 'ucsd' => 'UCSD Crawl', + 'udmsearch' => 'UdmSearch', + 'ultraseek' => 'Ultraseek', + 'uptimebot' => 'UptimeBot', + 'urlck' => 'URL Check', + 'valkyrie' => 'Valkyrie', + 'verticrawl' => 'Verticrawl', + 'victoria' => 'Victoria', + 'visionsearch' => 'vision-search', + 'voidbot' => 'void-bot', + 'voyager' => 'Voyager', + 'vwbot' => 'VWbot', + 'w3index' => 'The NWI Robot', + 'w3m2' => 'W3M2', + 'wallpaper' => 'WallPaper (alias crawlpaper)', + 'wanderer' => 'the World Wide Web Wanderer', + 'wapspider' => 'w@pSpider by wap4.com', + 'webbandit' => 'WebBandit Web Spider', + 'webcatcher' => 'WebCatcher', + 'webcopy' => 'WebCopy', + 'webfetcher' => 'webfetcher', + 'webfoot' => 'The Webfoot Robot', + 'webinator' => 'Webinator', + 'weblayers' => 'weblayers', + 'weblinker' => 'WebLinker', + 'webmirror' => 'WebMirror', + 'webmoose' => 'The Web Moose', + 'webquest' => 'WebQuest', + 'webreader' => 'Digimarc MarcSpider', + 'webreaper' => 'WebReaper', + 'webs' => 'webs', + 'websnarf' => 'Websnarf', + 'webspider' => 'WebSpider', + 'webvac' => 'WebVac', + 'webwalk' => 'webwalk', + 'webwalker' => 'WebWalker', + 'webwatch' => 'WebWatch', + 'wget' => 'Wget', + 'whatuseek' => 'whatUseek Winona', + 'whowhere' => 'WhoWhere Robot', + 'wlm' => 'Weblog Monitor', + 'wmir' => 'w3mir', + 'wolp' => 'WebStolperer', + 'wombat' => 'The Web Wombat ', + 'worm' => 'The World Wide Web Worm', + 'wwwc' => 'WWWC Ver 0.2.5', + 'wz101' => 'WebZinger', + 'xget' => 'XGET', + ); + + + + /** + * Constructor + * + * Sets the User Agent and runs the compilation routine + * + * @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)) + { + $this->_compile_data(); + } + } + + // -------------------------------------------------------------------- + + /** + * 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() + { + foreach ($this->platforms as $key => $val) + { + if (preg_match("|$key|i", $this->agent)) + { + $this->platform = $val; + return TRUE; + } + } + + $this->platform = 'Unknown Platform'; + } + + // -------------------------------------------------------------------- + + /** + * Set the Browser + * + * @access private + * @return bool + */ + function _set_browser() + { + foreach ($this->browsers as $key => $val) + { + if (preg_match("|".$key.".*?([0-9\.]+)|i", $this->agent, $match)) + { + $this->is_browser = TRUE; + $this->version = $match[1]; + $this->browser = $val; + return TRUE; + } + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Set the Robot + * + * @access private + * @return bool + */ + function _set_robot() + { + foreach ($this->robots as $key => $val) + { + if (preg_match("|$key|i", $this->agent)) + { + $this->is_robot = TRUE; + $this->robot = $val; + return TRUE; + } + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Set the Mobile Devise + * + * @access private + * @return bool + */ + function _set_mobile() + { + foreach ($this->mobiles as $key => $val) + { + if (FALSE !== (strpos(strtolower($this->agent), $key))) + { + $this->is_mobile = TRUE; + $this->mobile = $val; + return TRUE; + } + } + + return FALSE; + } + + + // -------------------------------------------------------------------- + + /** + * 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; + } + + // -------------------------------------------------------------------- + + /** + * Get Platform + * + * @access public + * @return string + */ + function get_platform() + { + return $this->platform; + } + + // -------------------------------------------------------------------- + + /** + * Get Browser Name + * + * @access public + * @return string + */ + function get_browser() + { + return $this->browser; + } + + // -------------------------------------------------------------------- + + /** + * Get the Browser Version + * + * @access public + * @return string + */ + function get_version() + { + return $this->version; + } + + // -------------------------------------------------------------------- + + /** + * Get The Robot Name + * + * @access public + * @return string + */ + function get_robot() + { + return $this->robot; + } + // -------------------------------------------------------------------- + + /** + * Get the Mobile Devise + * + * @access public + * @return string + */ + function get_mobile() + { + return $this->mobile; + } + + +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 10c3f41cbe5bd3bb66fd106cc9fb171ffcc7364b Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 8 Oct 2006 07:21:12 +0000 Subject: --- system/libraries/Calendar.php | 11 ++----- system/libraries/Encrypt.php | 32 +++++++++++++++------ system/libraries/Image_lib.php | 1 + system/libraries/Input.php | 64 ++++++++++++++++++++++++++++++++--------- system/libraries/Loader.php | 45 ++++++++++++----------------- system/libraries/Log.php | 3 +- system/libraries/Pagination.php | 21 ++++++++------ system/libraries/Router.php | 4 +-- system/libraries/Unit.php | 2 +- system/libraries/Upload.php | 30 +++++++++---------- system/libraries/Validation.php | 14 +++++++++ system/libraries/Zip.php | 3 +- 12 files changed, 142 insertions(+), 88 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 3cbbbfe6d..23a6bf791 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -48,6 +48,7 @@ class CI_Calendar { function CI_Calendar() { $this->CI =& get_instance(); + if ( ! in_array('calendar_lang'.EXT, $this->CI->lang->is_loaded, TRUE)) { $this->CI->lang->load('calendar'); @@ -56,7 +57,6 @@ class CI_Calendar { $this->local_time = time(); log_message('debug', "Calendar Class Initialized"); } - // END CI_Calendar() // -------------------------------------------------------------------- @@ -79,7 +79,6 @@ class CI_Calendar { } } } - // END initialize() // -------------------------------------------------------------------- @@ -241,7 +240,6 @@ class CI_Calendar { return $out; } - // END generate() // -------------------------------------------------------------------- @@ -275,7 +273,6 @@ class CI_Calendar { return $this->CI->lang->line($month); } - // END get_month_name() // -------------------------------------------------------------------- @@ -315,7 +312,6 @@ class CI_Calendar { return $days; } - // END get_day_names() // -------------------------------------------------------------------- @@ -357,7 +353,6 @@ class CI_Calendar { return $date; } - // END adjust_date() // -------------------------------------------------------------------- @@ -378,6 +373,7 @@ class CI_Calendar { return 0; } + // Is the year a leap year? if ($month == 2) { if ($year % 400 == 0 OR ($year % 4 == 0 AND $year % 100 != 0)) @@ -388,7 +384,6 @@ class CI_Calendar { return $days_in_month[$month - 1]; } - // END get_total_days() // -------------------------------------------------------------------- @@ -426,7 +421,6 @@ class CI_Calendar { 'table_close' => '
' ); } - // END default_template() // -------------------------------------------------------------------- @@ -465,7 +459,6 @@ class CI_Calendar { } } } - // END parse_template() } diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 2a1de6f37..50b3fab39 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -27,6 +27,7 @@ * @link http://www.codeigniter.com/user_guide/libraries/encryption.html */ class CI_Encrypt { + var $encryption_key = ''; var $_hash_type = 'sha1'; var $_mcrypt_exists = FALSE; @@ -246,10 +247,9 @@ class CI_Encrypt { */ function mcrypt_encode($data, $key) { - $this->_get_mcrypt(); - $init_size = mcrypt_get_iv_size($this->_mcrypt_cipher, $this->_mcrypt_mode); + $init_size = mcrypt_get_iv_size($this->_get_cipher(), $this->_get_mode()); $init_vect = mcrypt_create_iv($init_size, MCRYPT_RAND); - return mcrypt_encrypt($this->_mcrypt_cipher, $key, $data, $this->_mcrypt_mode, $init_vect); + return mcrypt_encrypt($this->_get_cipher(), $key, $data, $this->_get_mode(), $init_vect); } // -------------------------------------------------------------------- @@ -264,10 +264,9 @@ class CI_Encrypt { */ function mcrypt_decode($data, $key) { - $this->_get_mcrypt(); - $init_size = mcrypt_get_iv_size($this->_mcrypt_cipher, $this->_mcrypt_mode); + $init_size = mcrypt_get_iv_size($this->_get_cipher(), $this->_get_mode()); $init_vect = mcrypt_create_iv($init_size, MCRYPT_RAND); - return rtrim(mcrypt_decrypt($this->_mcrypt_cipher, $key, $data, $this->_mcrypt_mode, $init_vect), "\0"); + return rtrim(mcrypt_decrypt($this->_get_cipher(), $key, $data, $this->_get_mode(), $init_vect), "\0"); } // -------------------------------------------------------------------- @@ -301,22 +300,37 @@ class CI_Encrypt { // -------------------------------------------------------------------- /** - * Get Mcrypt value + * Get Mcrypt Cypher Value * * @access private - * @param string * @return string */ - function _get_mcrypt() + function _get_cypher() { if ($this->_mcrypt_cipher == '') { $this->_mcrypt_cipher = MCRYPT_RIJNDAEL_256; } + + return $this->_mcrypt_cipher; + } + + // -------------------------------------------------------------------- + + /** + * Get Mcrypt MOde Value + * + * @access private + * @return string + */ + function _get_mode() + { if ($this->_mcrypt_mode == '') { $this->_mcrypt_mode = MCRYPT_MODE_ECB; } + + return $this->_mcrypt_mode; } // -------------------------------------------------------------------- diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 79b2f9c1c..16583c063 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -148,6 +148,7 @@ class CI_Image_lib { $this->set_error('imglib_source_image_required'); return FALSE; } + /* * Is getimagesize() Available? * diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 98c2cbd55..0d3c87b49 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -179,6 +179,7 @@ class CI_Input { * * @access public * @param string + * @param bool * @return string */ function post($index = '', $xss_clean = FALSE) @@ -213,6 +214,7 @@ class CI_Input { * * @access public * @param string + * @param bool * @return string */ function cookie($index = '', $xss_clean = FALSE) @@ -244,6 +246,31 @@ class CI_Input { return $_COOKIE[$index]; } } + + // -------------------------------------------------------------------- + + /** + * Fetch an item from the SERVER array + * + * @access public + * @param string + * @param bool + * @return string + */ + function server($index = '', $xss_clean = FALSE) + { + if ( ! isset($_SERVER[$index])) + { + return FALSE; + } + + if ($xss_clean === TRUE) + { + return $this->xss_clean($_SERVER[$index]); + } + + return $_SERVER[$index]; + } // -------------------------------------------------------------------- @@ -259,15 +286,28 @@ class CI_Input { { return $this->ip_address; } - - $cip = (isset($_SERVER['HTTP_CLIENT_IP']) AND $_SERVER['HTTP_CLIENT_IP'] != "") ? $_SERVER['HTTP_CLIENT_IP'] : FALSE; - $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_address = $cip; - elseif ($rip) $this->ip_address = $rip; - elseif ($cip) $this->ip_address = $cip; - elseif ($fip) $this->ip_address = $fip; + + if ($this->server('REMOTE_ADDR') AND $this->server('HTTP_CLIENT_IP')) + { + $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; + } + elseif ($this->server('REMOTE_ADDR')) + { + $this->ip_address = $_SERVER['REMOTE_ADDR']; + } + elseif ($this->server('HTTP_CLIENT_IP')) + { + $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; + } + elseif ($this->server('HTTP_X_FORWARDED_FOR')) + { + $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; + } + + if ($this->ip_address === FALSE) + { + return $this->ip_address = '0.0.0.0'; + } if (strstr($this->ip_address, ',')) { @@ -279,11 +319,7 @@ class CI_Input { { $this->ip_address = '0.0.0.0'; } - - unset($cip); - unset($rip); - unset($fip); - + return $this->ip_address; } diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 90dc0f140..05ee93959 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -611,16 +611,7 @@ class CI_Loader { if (substr($class, 0, 3) == 'my_') { $class = preg_replace("/my_(.+)/", "\\1", $class); - $extend = TRUE; - } - else - { - $extend = FALSE; - } - - // Are we extending one of the base classes? - if ($extend == TRUE) - { + // Load the requested library from the main system/libraries folder if (file_exists(BASEPATH.'libraries/'.ucfirst($class).EXT)) { @@ -638,22 +629,20 @@ class CI_Loader { return $this->_ci_init_class($filename, 'MY_', $params); } - else - { - // Lets search for the requested library file and load it. - // For backward compatibility we'll test for filenames that are - // both uppercase and lower. - foreach (array(ucfirst($class), $class) as $filename) + + // Lets search for the requested library file and load it. + // For backward compatibility we'll test for filenames that are + // both uppercase and lower. + foreach (array(ucfirst($class), $class) as $filename) + { + for ($i = 1; $i < 3; $i++) { - for ($i = 1; $i < 3; $i++) + $path = ($i % 2) ? APPPATH : BASEPATH; + + if (file_exists($path.'libraries/'.$filename.EXT)) { - $path = ($i % 2) ? APPPATH : BASEPATH; - - if (file_exists($path.'libraries/'.$filename.EXT)) - { - include_once($path.'libraries/'.$filename.EXT); - return $this->_ci_init_class($filename, '', $params); - } + include_once($path.'libraries/'.$filename.EXT); + return $this->_ci_init_class($filename, '', $params); } } } @@ -686,7 +675,7 @@ class CI_Loader { if ($prefix == '') { - $name = ( ! class_exists($class)) ? 'CI_'.$class : $class; + $name = (class_exists('CI_'.$class)) ? 'CI_'.$class : $class; } else { @@ -756,24 +745,28 @@ class CI_Loader { // Load libraries if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0) { + // Load the database driver. if (in_array('database', $autoload['libraries'])) { $this->database(); $autoload['libraries'] = array_diff($autoload['libraries'], array('database')); } + // Load the model class. if (in_array('model', $autoload['libraries'])) { $this->model(); $autoload['libraries'] = array_diff($autoload['libraries'], array('model')); } - + + // Load scaffolding if (in_array('scaffolding', $autoload['libraries'])) { $this->scaffolding(); $autoload['libraries'] = array_diff($autoload['libraries'], array('scaffolding')); } + // Load all other libraries foreach ($autoload['libraries'] as $item) { $this->library($item); diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 392742584..eff7cb7fc 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -61,7 +61,6 @@ class CI_Log { $this->_date_fmt = $config['log_date_format']; } } - // END CI_Log() // -------------------------------------------------------------------- @@ -113,7 +112,7 @@ class CI_Log { @chmod($filepath, 0666); return TRUE; } - // END write_log() + } // END Log Class ?> \ No newline at end of file diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index efbe6c27f..b29571eee 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -105,16 +105,21 @@ class CI_Pagination { { return ''; } - + // Calculate the total number of pages - $num_pages = intval($this->total_rows / $this->per_page); + $num_pages = ceil($this->total_rows / $this->per_page); + + /* + // Calculate the total number of pages + $num_pages = intval($this->total_rows / $this->per_page); + + // Use modulus to see if our division has a remainder. If so, add one to our page number. + if ($this->total_rows % $this->per_page) + { + $num_pages++; + } + */ - // Use modulus to see if our division has a remainder.If so, add one to our page number. - if ($this->total_rows % $this->per_page) - { - $num_pages++; - } - // Is there only one page? Hm... nothing more to do here then. if ($num_pages == 1) { diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 7a4fd3899..27e3c27cc 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -66,7 +66,6 @@ class CI_Router { */ function _set_route_mapping() { - // Are query strings enabled in the config file? // If so, we're done since segment based URIs are not used with query strings. if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) @@ -120,8 +119,7 @@ class CI_Router { { $this->uri_string = preg_replace("|".preg_quote($this->config->item('url_suffix'))."$|", "", $this->uri_string); } - - + // Explode the URI Segments. The individual segments will // be stored in the $this->segments array. foreach(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val) diff --git a/system/libraries/Unit.php b/system/libraries/Unit.php index 6573f4269..439424fbb 100644 --- a/system/libraries/Unit.php +++ b/system/libraries/Unit.php @@ -55,7 +55,7 @@ class CI_Unit { function run($test, $expected = TRUE, $test_name = 'undefined') { if ($this->active == FALSE) - return; + return FALSE; if (in_array($expected, array('is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'), TRUE)) { diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 13fa8acdf..5bb506cdb 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -248,20 +248,20 @@ class CI_Upload { function data() { return array ( - 'file_name' => $this->file_name, - 'file_type' => $this->file_type, - 'file_path' => $this->file_path, - 'full_path' => $this->file_path.$this->file_name, - 'raw_name' => str_replace($this->file_ext, '', $this->file_name), - 'orig_name' => $this->orig_name, - 'file_ext' => $this->file_ext, - 'file_size' => $this->file_size, - 'is_image' => $this->is_image(), - 'image_width' => $this->image_width, - 'image_height' => $this->image_height, - 'image_type' => $this->image_type, - 'image_size_str' => $this->image_size_str, - ); + 'file_name' => $this->file_name, + 'file_type' => $this->file_type, + 'file_path' => $this->file_path, + 'full_path' => $this->file_path.$this->file_name, + 'raw_name' => str_replace($this->file_ext, '', $this->file_name), + 'orig_name' => $this->orig_name, + 'file_ext' => $this->file_ext, + 'file_size' => $this->file_size, + 'is_image' => $this->is_image(), + 'image_width' => $this->image_width, + 'image_height' => $this->image_height, + 'image_type' => $this->image_type, + 'image_size_str' => $this->image_size_str, + ); } // -------------------------------------------------------------------- @@ -554,7 +554,7 @@ class CI_Upload { // -------------------------------------------------------------------- /** - * VAlidate Upload Path + * Validate Upload Path * * Verifies that it is a valid upload path with proper permissions. * diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 5322be0e9..07ca35a33 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -478,7 +478,21 @@ class CI_Validation { { return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; } + + // -------------------------------------------------------------------- + /** + * Validate IP Address + * + * @access public + * @param string + * @return string + */ + function valid_ip($ip) + { + return ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) ? FALSE : TRUE; + } + // -------------------------------------------------------------------- /** diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 218388314..e13c713fe 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -41,7 +41,8 @@ class CI_Zip { { log_message('debug', "Zip Compression Class Initialized"); } - + + // -------------------------------------------------------------------- /** * Add Directory -- cgit v1.2.3-24-g4f1b From 2f8ae02bb689c8280d42bd22837eaa820f8819a8 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 9 Oct 2006 03:25:43 +0000 Subject: --- system/libraries/Table.php | 325 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 325 insertions(+) create mode 100644 system/libraries/Table.php (limited to 'system/libraries') diff --git a/system/libraries/Table.php b/system/libraries/Table.php new file mode 100644 index 000000000..935a7d8a6 --- /dev/null +++ b/system/libraries/Table.php @@ -0,0 +1,325 @@ +template = $template; + } + + // -------------------------------------------------------------------- + + /** + * Add a table heading + * + * Can be passed as an array or discreet params + * + * @access public + * @param mixed + * @return void + */ + function add_heading() + { + $args = func_get_args(); + $this->heading = (is_array($args[0])) ? $args[0] : $args; + } + + // -------------------------------------------------------------------- + + /** + * Add a table row + * + * Can be passed as an array or discreet params + * + * @access public + * @param mixed + * @return void + */ + function add_row() + { + $args = func_get_args(); + $this->rows[] = (is_array($args[0])) ? $args[0] : $args; + } + + // -------------------------------------------------------------------- + + /** + * Generate the table + * + * @access public + * @param mixed + * @return string + */ + function generate($table_data = NULL) + { + // The table data can optionally be passed to this function + // either as a database result object or an array + if ( ! is_null($table_data)) + { + if (is_object($table_data)) + { + $this->_set_from_object($table_data); + } + elseif (is_array($table_data)) + { + $this->_set_from_array($table_data); + } + } + + // 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 templata date + $this->_compile_template(); + + + // Build the table! + + $out = $this->template['table_open']; + $out .= $this->newline; + + // Is there a table heading to display? + if (count($this->heading) > 0) + { + $out .= $this->template['heading_row_start']; + $out .= $this->newline; + + foreach($this->heading as $heading) + { + $out .= $this->template['heading_cell_start']; + $out .= $heading; + $out .= $this->template['heading_cell_end']; + } + + $out .= $this->template['heading_row_end']; + $out .= $this->newline; + } + + // Build the table rows + if (count($this->rows) > 0) + { + $i = 1; + foreach($this->rows as $row) + { + if ( ! is_array($row)) + { + break; + } + + // We use modulus to alternate the row colors + $alt = (fmod($i++, 2)) ? '' : 'alt_'; + + $out .= $this->template['row_'.$alt.'start']; + $out .= $this->newline; + + foreach($row as $cells) + { + $out .= $this->template['cell_'.$alt.'start']; + $out .= $cells; + $out .= $this->template['cell_'.$alt.'end']; + } + + $out .= $this->template['row_'.$alt.'end']; + $out .= $this->newline; + } + } + + $out .= $this->template['table_close']; + + return $out; + } + + // -------------------------------------------------------------------- + + /** + * Set table data from a database result object + * + * @access public + * @param object + * @return void + */ + function _set_from_object($query) + { + if ( ! is_object($query)) + { + return FALSE; + } + + // First generate the headings from the table column names + if (count($this->heading) == 0) + { + if ( ! method_exists($query, 'field_names')) + { + return FALSE; + } + + $this->heading = $query->field_names(); + } + + // Next blast through the result array and build out the rows + foreach ($query->result_array() as $row) + { + $this->rows[] = $row; + } + } + + // -------------------------------------------------------------------- + + /** + * Set table data from an array + * + * @access public + * @param array + * @return void + */ + function _set_from_array($data) + { + if ( ! is_array($data) OR count($data) == 0) + { + return FALSE; + } + + $i = 0; + foreach ($data as $row) + { + if ( ! is_array($row)) + { + $this->rows[] = $data; + break; + } + + // 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) + { + $this->heading = $row; + } + else + { + $this->rows[] = $row; + } + + $i++; + } + } + + // -------------------------------------------------------------------- + + /** + * Compile Template + * + * @access private + * @return void + */ + function _compile_template() + { + if ($this->template == NULL) + { + $this->template = $this->_default_template(); + return; + } + + $this->temp = $this->_default_template(); + foreach (array('table_open','heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end', 'row_start', 'row_end', 'cell_start', 'cell_end', 'row_alt_start', 'row_alt_end', 'cell_alt_start', 'cell_alt_end', 'table_close') as $val) + { + if ( ! isset($this->template[$val])) + { + $this->template[$val] = $this->temp[$val]; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Default Template + * + * @access private + * @return void + */ + function _default_template() + { + return array ( + 'table_open' => '', + + 'heading_row_start' => '', + 'heading_row_end' => '', + 'heading_cell_start' => '', + + 'row_start' => '', + 'row_end' => '', + 'cell_start' => '', + + 'row_alt_start' => '', + 'row_alt_end' => '', + 'cell_alt_start' => '', + + 'table_close' => '
', + 'heading_cell_end' => '
', + 'cell_end' => '
', + 'cell_alt_end' => '
' + ); + } + + + + + + + +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 6c9f736650bd9eafb2c44bb844f13de259d5efb6 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 9 Oct 2006 03:33:48 +0000 Subject: --- system/libraries/Calendar.php | 42 +++++----- system/libraries/User_agent.php | 178 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 189 insertions(+), 31 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 23a6bf791..048934b82 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -398,27 +398,27 @@ class CI_Calendar { function default_template() { return array ( - 'table_open' => '', - '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_end_today' => '', - 'cal_row_end' => '', - 'table_close' => '
<<{heading}>>
{week_day}
', - 'cal_cell_start_today' => '', - 'cal_cell_content' => '{day}', - 'cal_cell_content_today' => '{day}', - 'cal_cell_no_content' => '{day}', - 'cal_cell_no_content_today' => '{day}', - 'cal_cell_blank' => ' ', - 'cal_cell_end' => '
' + 'table_open' => '', + '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_end_today' => '', + 'cal_row_end' => '', + 'table_close' => '
<<{heading}>>
{week_day}
', + 'cal_cell_start_today' => '', + 'cal_cell_content' => '{day}', + 'cal_cell_content_today' => '{day}', + 'cal_cell_no_content' => '{day}', + 'cal_cell_no_content_today' => '{day}', + 'cal_cell_blank' => ' ', + 'cal_cell_end' => '
' ); } diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 33e8451c6..8c63924b9 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -33,6 +33,9 @@ class CI_User_agent { var $is_browser = FALSE; var $is_robot = FALSE; var $is_mobile = FALSE; + + var $languages = array(); + var $charsets = array(); var $platform = ''; var $browser = ''; @@ -40,7 +43,6 @@ class CI_User_agent { var $moble = ''; var $robot = ''; - var $platforms = array ( 'windows nt 6.0' => 'Windows Longhorn', 'windows nt 5.2' => 'Windows 2003', @@ -55,12 +57,13 @@ class CI_User_agent { 'windows 95' => 'Windows 95', 'win95' => 'Windows 95', 'windows' => 'Unknown Windows OS', - 'mac os x' => 'Mac OS X', + 'os x' => 'Mac OS X', + 'ppc mac' => 'Power PC Mac', 'freebsd' => 'FreeBSD', 'ppc' => 'Macintosh', - 'sunos' => 'Sun Solaris', 'linux' => 'Linux', 'debian' => 'Debian', + 'sunos' => 'Sun Solaris', 'beos' => 'BeOS', 'apachebench' => 'ApacheBench', 'aix' => 'AIX', @@ -80,12 +83,21 @@ class CI_User_agent { 'Internet Explorer' => 'Internet Explorer', 'Shiira' => 'Shiira', 'Firefox' => 'Firefox', + 'Chimera' => 'Chimera', + 'Phoenix' => 'Phoenix', + 'Firebird' => 'Firebird', 'Camino' => 'Camino', + 'Netscape' => 'Netscape', + 'OmniWeb' => 'OmniWeb', 'Mozilla' => 'Mozilla', 'Safari' => 'Safari', 'Konqueror' => 'Konqueror', + 'icab' => 'iCab', 'Lynx' => 'Lynx', - 'ANTFresco' => 'Fresco' + 'Links' => 'Links', + 'hotjava' => 'HotJava', + 'amaya' => 'Amaya', + 'IBrowse' => 'IBrowse' ); var $mobiles = array( @@ -488,7 +500,7 @@ class CI_User_agent { return FALSE; } - + // -------------------------------------------------------------------- /** @@ -535,6 +547,51 @@ class CI_User_agent { 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=.+)/i', '', $_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', '', $_SERVER['HTTP_ACCEPT_CHARSET']); + + $this->charsets = explode(',', $charsets); + } + + if (count($this->charsets) == 0) + { + $this->charsets = array('Undefined'); + } + } // -------------------------------------------------------------------- @@ -577,13 +634,39 @@ class CI_User_agent { // -------------------------------------------------------------------- + /** + * 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() + { + return $this->agent; + } + + // -------------------------------------------------------------------- + /** * Get Platform * * @access public * @return string */ - function get_platform() + function platform() { return $this->platform; } @@ -596,7 +679,7 @@ class CI_User_agent { * @access public * @return string */ - function get_browser() + function browser() { return $this->browser; } @@ -609,7 +692,7 @@ class CI_User_agent { * @access public * @return string */ - function get_version() + function version() { return $this->version; } @@ -622,7 +705,7 @@ class CI_User_agent { * @access public * @return string */ - function get_robot() + function robot() { return $this->robot; } @@ -634,11 +717,86 @@ class CI_User_agent { * @access public * @return string */ - function get_mobile() + function mobile() { return $this->mobile; } + // -------------------------------------------------------------------- + + /** + * Get the referrer + * + * @access public + * @return bool + */ + function referrer() + { + return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : $_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; + } + } -- cgit v1.2.3-24-g4f1b From a1931ad87e8145f08dbf381ceab5bf88457b1a83 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 9 Oct 2006 04:17:38 +0000 Subject: --- system/libraries/Table.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 935a7d8a6..4771295a5 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -61,7 +61,7 @@ class CI_Table { // -------------------------------------------------------------------- /** - * Add a table heading + * Set the table heading * * Can be passed as an array or discreet params * @@ -69,7 +69,7 @@ class CI_Table { * @param mixed * @return void */ - function add_heading() + function set_heading() { $args = func_get_args(); $this->heading = (is_array($args[0])) ? $args[0] : $args; @@ -313,12 +313,7 @@ class CI_Table { 'table_close' => '' ); } - - - - - - + } -- cgit v1.2.3-24-g4f1b From 3822194cde4614137a54eecb1e1fcc86672e84a1 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 9 Oct 2006 17:34:19 +0000 Subject: --- system/libraries/User_agent.php | 500 ++++++++-------------------------------- 1 file changed, 96 insertions(+), 404 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 8c63924b9..21162388a 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -43,375 +43,6 @@ class CI_User_agent { var $moble = ''; var $robot = ''; - var $platforms = array ( - 'windows nt 6.0' => 'Windows Longhorn', - 'windows nt 5.2' => 'Windows 2003', - 'windows nt 5.0' => 'Windows 2000', - 'windows nt 5.1' => 'Windows XP', - 'windows nt 4.0' => 'Windows NT 4.0', - 'winnt4.0' => 'Windows NT 4.0', - 'winnt 4.0' => 'Windows NT', - 'winnt' => 'Windows NT', - 'windows 98' => 'Windows 98', - 'win98' => 'Windows 98', - 'windows 95' => 'Windows 95', - 'win95' => 'Windows 95', - 'windows' => 'Unknown Windows OS', - 'os x' => 'Mac OS X', - 'ppc mac' => 'Power PC Mac', - 'freebsd' => 'FreeBSD', - 'ppc' => 'Macintosh', - 'linux' => 'Linux', - 'debian' => 'Debian', - 'sunos' => 'Sun Solaris', - 'beos' => 'BeOS', - 'apachebench' => 'ApacheBench', - 'aix' => 'AIX', - 'irix' => 'Irix', - 'osf' => 'DEC OSF', - 'hp-ux' => 'HP-UX', - 'netbsd' => 'NetBSD', - 'bsdi' => 'BSDi', - 'openbsd' => 'OpenBSD', - 'gnu' => 'GNU/Linux', - 'unix' => 'Unknown Unix OS' - ); - - var $browsers = array( - 'Opera' => 'Opera', - 'MSIE' => 'Internet Explorer', - 'Internet Explorer' => 'Internet Explorer', - 'Shiira' => 'Shiira', - 'Firefox' => 'Firefox', - 'Chimera' => 'Chimera', - 'Phoenix' => 'Phoenix', - 'Firebird' => 'Firebird', - 'Camino' => 'Camino', - 'Netscape' => 'Netscape', - 'OmniWeb' => 'OmniWeb', - 'Mozilla' => 'Mozilla', - 'Safari' => 'Safari', - 'Konqueror' => 'Konqueror', - 'icab' => 'iCab', - 'Lynx' => 'Lynx', - 'Links' => 'Links', - 'hotjava' => 'HotJava', - 'amaya' => 'Amaya', - 'IBrowse' => 'IBrowse' - ); - - var $mobiles = array( - 'mobileexplorer' => 'Mobile Explorer', - 'openwave' => 'Open Wave', - 'opera mini' => 'Opera Mini', - 'operamini' => 'Opera Mini', - 'elaine' => 'Palm', - 'palmsource' => 'Palm', - 'digital paths' => 'Palm', - 'avantgo' => 'Avantgo', - 'xiino' => 'Xiino', - 'palmscape' => 'Palmscape', - 'nokia' => 'Nokia', - 'ericsson' => 'Ericsson', - 'blackBerry' => 'BlackBerry', - 'motorola' => 'Motorola' - ); - - var $robots = array( - - 'googlebot' => 'Googlebot', - 'msnbot' => 'MSNBot', - 'slurp' => 'Inktomi Slurp', - 'yahoo' => 'Yahoo', - 'askjeeves' => 'AskJeeves', - 'fastcrawler' => 'FastCrawler', - 'infoseek' => 'InfoSeek Robot 1.0', - 'lycos' => 'Lycos', - 'abcdatos' => 'ABCdatos BotLink', - 'Acme.Spider' => 'Acme.Spider', - 'ahoythehomepagefinder' => 'Ahoy! The Homepage Finder', - 'Alkaline' => 'Alkaline', - 'anthill' => 'Anthill', - 'appie' => 'Walhello appie', - 'arachnophilia' => 'Arachnophilia', - 'arale' => 'Arale', - 'araneo' => 'Araneo', - 'araybot' => 'AraybOt', - 'architext' => 'ArchitextSpider', - 'aretha' => 'Aretha', - 'ariadne' => 'ARIADNE', - 'arks' => 'arks', - 'aspider' => 'ASpider (Associative Spider)', - 'atn.txt' => 'ATN Worldwide', - 'atomz' => 'Atomz.com Search Robot', - 'auresys' => 'AURESYS', - 'backrub' => 'BackRub', - 'bbot' => 'BBot', - 'bigbrother' => 'Big Brother', - 'bjaaland' => 'Bjaaland', - 'blackwidow' => 'BlackWidow', - 'blindekuh' => 'Die Blinde Kuh', - 'Bloodhound' => 'Bloodhound', - 'borg-bot' => 'Borg-Bot', - 'boxseabot' => 'BoxSeaBot', - 'brightnet' => 'bright.net caching robot', - 'bspider' => 'BSpider', - 'cactvschemistryspider' => 'CACTVS Chemistry Spider', - 'calif' => 'Calif', - 'cassandra' => 'Cassandra', - 'cgireader' => 'Digimarc Marcspider/CGI', - 'checkbot' => 'Checkbot', - 'christcrawler' => 'ChristCrawler.com', - 'churl' => 'churl', - 'cienciaficcion' => 'cIeNcIaFiCcIoN.nEt', - 'cmc' => 'CMC/0.01', - 'Collective' => 'Collective', - 'combine' => 'Combine System', - 'confuzzledbot' => 'ConfuzzledBot', - 'coolbot' => 'CoolBot', - 'core' => 'Web Core / Roots', - 'cosmos' => 'XYLEME Robot', - 'cruiser' => 'Internet Cruiser Robot', - 'cusco' => 'Cusco', - 'cyberspyder' => 'CyberSpyder Link Test', - 'cydralspider' => 'CydralSpider', - 'desertrealm' => 'Desert Realm Spider', - 'deweb' => 'DeWeb(c) Katalog/Index', - 'dienstspider' => 'DienstSpider', - 'digger' => 'Digger', - 'diibot' => 'Digital Integrity Robot', - 'directhit' => 'Direct Hit Grabber', - 'dnabot' => 'DNAbot', - 'download_express' => 'DownLoad Express', - 'dragonbot' => 'DragonBot', - 'e-collector' => 'e-collector', - 'ebiness' => 'EbiNess', - 'eit' => 'EIT Link Verifier Robot', - 'elfinbot' => 'ELFINBOT', - 'emacs' => 'Emacs-w3 Search Engine', - 'emcspider' => 'ananzi', - 'esculapio' => 'esculapio', - 'esther' => 'Esther', - 'evliyacelebi' => 'Evliya Celebi', - 'nzexplorer' => 'nzexplorer', - 'fdse' => 'Fluid Dynamics Search Engine robot', - 'felix' => 'Felix IDE', - 'ferret' => 'Wild Ferret Web Hopper #1, #2, #3', - 'fetchrover' => 'FetchRover', - 'fido' => 'fido', - 'finnish' => 'Hämähäkki', - 'fireball' => 'KIT-Fireball', - 'fish' => 'Fish search', - 'fouineur' => 'Fouineur', - 'francoroute' => 'Robot Francoroute', - 'freecrawl' => 'Freecrawl', - 'funnelweb' => 'FunnelWeb', - 'gama' => 'gammaSpider, FocusedCrawler', - 'gazz' => 'gazz', - 'gcreep' => 'GCreep', - 'getbot' => 'GetBot', - 'geturl' => 'GetURL', - 'golem' => 'Golem', - 'grapnel' => 'Grapnel/0.01 Experiment', - 'griffon' => 'Griffon ', - 'gromit' => 'Gromit', - 'gulliver' => 'Northern Light Gulliver', - 'gulperbot' => 'Gulper Bot', - 'hambot' => 'HamBot', - 'harvest' => 'Harvest', - 'havindex' => 'havIndex', - 'hi' => 'HI (HTML Index) Search', - 'hometown' => 'Hometown Spider Pro', - 'wired-digital' => 'Wired Digital', - 'htdig' => 'ht://Dig', - 'htmlgobble' => 'HTMLgobble', - 'hyperdecontextualizer' => 'Hyper-Decontextualizer', - 'iajabot' => 'iajaBot', - 'ibm' => 'IBM_Planetwide', - 'iconoclast' => 'Popular Iconoclast', - 'Ilse' => 'Ingrid', - 'imagelock' => 'Imagelock ', - 'incywincy' => 'IncyWincy', - 'informant' => 'Informant', - 'infoseeksidewinder' => 'Infoseek Sidewinder', - 'infospider' => 'InfoSpiders', - 'inspectorwww' => 'Inspector Web', - 'intelliagent' => 'IntelliAgent', - 'irobot' => 'I, Robot', - 'iron33' => 'Iron33', - 'israelisearch' => 'Israeli-search', - 'javabee' => 'JavaBee', - 'JBot' => 'JBot Java Web Robot', - 'jcrawler' => 'JCrawler', - 'jobo' => 'JoBo Java Web Robot', - 'jobot' => 'Jobot', - 'joebot' => 'JoeBot', - 'jubii' => 'The Jubii Indexing Robot', - 'jumpstation' => 'JumpStation', - 'kapsi' => 'image.kapsi.net', - 'katipo' => 'Katipo', - 'kdd' => 'KDD-Explorer', - 'kilroy' => 'Kilroy', - 'ko_yappo_robot' => 'KO_Yappo_Robot', - 'labelgrabber.txt' => 'LabelGrabber', - 'larbin' => 'larbin', - 'legs' => 'legs', - 'linkidator' => 'Link Validator', - 'linkscan' => 'LinkScan', - 'linkwalker' => 'LinkWalker', - 'lockon' => 'Lockon', - 'logo_gif' => 'logo.gif Crawler', - 'magpie' => 'Magpie', - 'marvin' => 'marvin/infoseek', - 'mattie' => 'Mattie', - 'mediafox' => 'MediaFox', - 'merzscope' => 'MerzScope', - 'meshexplorer' => 'NEC-MeshExplorer', - 'MindCrawler' => 'MindCrawler', - 'mnogosearch' => 'mnoGoSearch search engine software', - 'moget' => 'moget', - 'momspider' => 'MOMspider', - 'monster' => 'Monster', - 'motor' => 'Motor', - 'muncher' => 'Muncher', - 'muninn' => 'Muninn', - 'muscatferret' => 'Muscat Ferret', - 'mwdsearch' => 'Mwd.Search', - 'myweb' => 'Internet Shinchakubin', - 'NDSpider' => 'NDSpider', - 'netcarta' => 'NetCarta WebMap Engine', - 'netmechanic' => 'NetMechanic', - 'netscoop' => 'NetScoop', - 'newscan-online' => 'newscan-online', - 'nhse' => 'NHSE Web Forager', - 'nomad' => 'Nomad', - 'northstar' => 'The NorthStar Robot', - 'objectssearch' => 'ObjectsSearch', - 'occam' => 'Occam', - 'octopus' => 'HKU WWW Octopus', - 'OntoSpider' => 'OntoSpider', - 'openfind' => 'Openfind data gatherer', - 'orb_search' => 'Orb Search', - 'packrat' => 'Pack Rat', - 'pageboy' => 'PageBoy', - 'parasite' => 'ParaSite', - 'patric' => 'Patric', - 'pegasus' => 'pegasus', - 'perignator' => 'The Peregrinator', - 'perlcrawler' => 'PerlCrawler 1.0', - 'phantom' => 'Phantom', - 'phpdig' => 'PhpDig', - 'pitkow' => 'html_analyzer', - 'pjspider' => 'Portal Juice Spider', - 'pka' => 'PGP Key Agent', - 'poppi' => 'Poppi', - 'portalb' => 'PortalB Spider', - 'psbot' => 'psbot', - 'Puu' => 'GetterroboPlus Puu', - 'python' => 'The Python Robot', - 'raven ' => 'Raven Search', - 'rbse' => 'RBSE Spider', - 'resumerobot' => 'Resume Robot', - 'rhcs' => 'RoadHouse Crawling System', - 'rixbot' => 'RixBot', - 'roadrunner' => 'Road Runner: The ImageScape Robot', - 'robbie' => 'Robbie the Robot', - 'robi' => 'ComputingSite Robi/1.0', - 'robocrawl' => 'RoboCrawl Spider', - 'robofox' => 'RoboFox', - 'robozilla' => 'Robozilla', - 'roverbot' => 'Roverbot', - 'rules' => 'RuLeS', - 'safetynetrobot' => 'SafetyNet Robot', - 'scooter' => 'Scooter', - 'search_au' => 'Search.Aus-AU.COM', - 'search-info' => 'Sleek', - 'searchprocess' => 'SearchProcess', - 'senrigan' => 'Senrigan', - 'sgscout' => 'SG-Scout', - 'shaggy' => 'ShagSeeker', - 'sift' => 'Sift', - 'simbot' => 'Simmany Robot Ver1.0', - 'site-valet' => 'Site Valet', - 'sitetech' => 'SiteTech-Rover', - 'skymob' => 'Skymob.com', - 'slcrawler' => 'SLCrawler', - 'smartspider' => 'Smart Spider', - 'snooper' => 'Snooper', - 'solbot' => 'Solbot', - 'speedy' => 'Speedy Spider', - 'spider_monkey' => 'spider_monkey', - 'spiderbot' => 'SpiderBot', - 'spiderline' => 'Spiderline Crawler', - 'spiderman' => 'SpiderMan', - 'spiderview' => 'SpiderView(tm)', - 'spry' => 'Spry Wizard Robot', - 'ssearcher' => 'Site Searcher', - 'suke' => 'Suke', - 'suntek' => 'suntek search engine', - 'sven' => 'Sven', - 'sygol' => 'Sygol ', - 'tach_bw' => 'TACH Black Widow', - 'tarantula' => 'Tarantula', - 'tarspider' => 'tarspider', - 'tcl' => 'Tcl W3 Robot', - 'techbot' => 'TechBOT', - 'templeton' => 'Templeton', - 'titin' => 'TitIn', - 'titan' => 'TITAN', - 'tkwww' => 'The TkWWW Robot', - 'tlspider' => 'TLSpider', - 'ucsd' => 'UCSD Crawl', - 'udmsearch' => 'UdmSearch', - 'ultraseek' => 'Ultraseek', - 'uptimebot' => 'UptimeBot', - 'urlck' => 'URL Check', - 'valkyrie' => 'Valkyrie', - 'verticrawl' => 'Verticrawl', - 'victoria' => 'Victoria', - 'visionsearch' => 'vision-search', - 'voidbot' => 'void-bot', - 'voyager' => 'Voyager', - 'vwbot' => 'VWbot', - 'w3index' => 'The NWI Robot', - 'w3m2' => 'W3M2', - 'wallpaper' => 'WallPaper (alias crawlpaper)', - 'wanderer' => 'the World Wide Web Wanderer', - 'wapspider' => 'w@pSpider by wap4.com', - 'webbandit' => 'WebBandit Web Spider', - 'webcatcher' => 'WebCatcher', - 'webcopy' => 'WebCopy', - 'webfetcher' => 'webfetcher', - 'webfoot' => 'The Webfoot Robot', - 'webinator' => 'Webinator', - 'weblayers' => 'weblayers', - 'weblinker' => 'WebLinker', - 'webmirror' => 'WebMirror', - 'webmoose' => 'The Web Moose', - 'webquest' => 'WebQuest', - 'webreader' => 'Digimarc MarcSpider', - 'webreaper' => 'WebReaper', - 'webs' => 'webs', - 'websnarf' => 'Websnarf', - 'webspider' => 'WebSpider', - 'webvac' => 'WebVac', - 'webwalk' => 'webwalk', - 'webwalker' => 'WebWalker', - 'webwatch' => 'WebWatch', - 'wget' => 'Wget', - 'whatuseek' => 'whatUseek Winona', - 'whowhere' => 'WhoWhere Robot', - 'wlm' => 'Weblog Monitor', - 'wmir' => 'w3mir', - 'wolp' => 'WebStolperer', - 'wombat' => 'The Web Wombat ', - 'worm' => 'The World Wide Web Worm', - 'wwwc' => 'WWWC Ver 0.2.5', - 'wz101' => 'WebZinger', - 'xget' => 'XGET', - ); - - /** * Constructor @@ -430,8 +61,61 @@ class CI_User_agent { if ( ! is_null($this->agent)) { - $this->_compile_data(); + if ($this->_load_agent_file()) + { + $this->_compile_data(); + } + } + } + + + // -------------------------------------------------------------------- + + /** + * Compile the User Agent Data + * + * @access private + * @return bool + */ + function _load_agent_file() + { + if ( ! @include(APPPATH.'config/user_agent'.EXT)) + { + return FALSE; + } + + $return = FALSE; + + if (isset($platforms)) + { + $this->platforms = $platforms; + unset($platforms); + $return = TRUE; + } + + if (isset($browsers)) + { + $this->browsers = $browsers; + unset($browsers); + $return = TRUE; + } + + if (isset($mobiles)) + { + $this->browsers = $mobiles; + unset($mobiles); + $return = TRUE; } + + if (isset($robots)) + { + $this->robots = $robots; + unset($robots); + $return = TRUE; + } + + + return $return; } // -------------------------------------------------------------------- @@ -465,15 +149,17 @@ class CI_User_agent { */ function _set_platform() { - foreach ($this->platforms as $key => $val) + if (is_array($this->platforms) AND count($this->platforms) > 0) { - if (preg_match("|$key|i", $this->agent)) + foreach ($this->platforms as $key => $val) { - $this->platform = $val; - return TRUE; + if (preg_match("|".preg_quote($key)."|i", $this->agent)) + { + $this->platform = $val; + return TRUE; + } } } - $this->platform = 'Unknown Platform'; } @@ -487,17 +173,19 @@ class CI_User_agent { */ function _set_browser() { - foreach ($this->browsers as $key => $val) - { - if (preg_match("|".$key.".*?([0-9\.]+)|i", $this->agent, $match)) - { - $this->is_browser = TRUE; - $this->version = $match[1]; - $this->browser = $val; - return TRUE; + 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; + $this->version = $match[1]; + $this->browser = $val; + return TRUE; + } } } - return FALSE; } @@ -511,39 +199,43 @@ class CI_User_agent { */ function _set_robot() { - foreach ($this->robots as $key => $val) - { - if (preg_match("|$key|i", $this->agent)) + if (is_array($this->robots) AND count($this->robots) > 0) + { + foreach ($this->robots as $key => $val) { - $this->is_robot = TRUE; - $this->robot = $val; - return TRUE; + if (preg_match("|".preg_quote($key)."|i", $this->agent)) + { + $this->is_robot = TRUE; + $this->robot = $val; + return TRUE; + } } } - return FALSE; } // -------------------------------------------------------------------- /** - * Set the Mobile Devise + * Set the Mobile Device * * @access private * @return bool */ function _set_mobile() { - foreach ($this->mobiles as $key => $val) - { - if (FALSE !== (strpos(strtolower($this->agent), $key))) + if (is_array($this->mobiles) AND count($this->mobiles) > 0) + { + foreach ($this->mobiles as $key => $val) { - $this->is_mobile = TRUE; - $this->mobile = $val; - return TRUE; + if (FALSE !== (strpos(strtolower($this->agent), $key))) + { + $this->is_mobile = TRUE; + $this->mobile = $val; + return TRUE; + } } - } - + } return FALSE; } @@ -559,7 +251,7 @@ class CI_User_agent { { if ((count($this->languages) == 0) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) AND $_SERVER['HTTP_ACCEPT_LANGUAGE'] != '') { - $languages = preg_replace('/(;q=.+)/i', '', $_SERVER['HTTP_ACCEPT_LANGUAGE']); + $languages = preg_replace('/(;q=.+)/i', '', trim($_SERVER['HTTP_ACCEPT_LANGUAGE'])); $this->languages = explode(',', $languages); } @@ -582,7 +274,7 @@ class CI_User_agent { { if ((count($this->charsets) == 0) AND isset($_SERVER['HTTP_ACCEPT_CHARSET']) AND $_SERVER['HTTP_ACCEPT_CHARSET'] != '') { - $charsets = preg_replace('/(;q=.+)/i', '', $_SERVER['HTTP_ACCEPT_CHARSET']); + $charsets = preg_replace('/(;q=.+)/i', '', trim($_SERVER['HTTP_ACCEPT_CHARSET'])); $this->charsets = explode(',', $charsets); } @@ -712,7 +404,7 @@ class CI_User_agent { // -------------------------------------------------------------------- /** - * Get the Mobile Devise + * Get the Mobile Device * * @access public * @return string @@ -732,7 +424,7 @@ class CI_User_agent { */ function referrer() { - return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : $_SERVER['HTTP_REFERER']; + return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 2f0bac87c73febde8019e7cbab541905bcb0e5dd Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 9 Oct 2006 17:36:45 +0000 Subject: --- system/libraries/Loader.php | 29 +++++++++++++---------------- system/libraries/User_agent.php | 3 +-- 2 files changed, 14 insertions(+), 18 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 05ee93959..452e39dfa 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -65,15 +65,15 @@ class CI_Loader { * * @access public * @param string the name of the class - * @param mixed any initialization parameters + * @param sring the optional class variable name to assign the library to * @return void */ - function library($class, $param = NULL) + function library($class, $varname = NULL) { if ($class == '') return; - $this->_ci_load_class($class, $param); + $this->_ci_load_class($class, $varname); $this->_ci_assign_to_models(); } @@ -595,7 +595,7 @@ class CI_Loader { * @param mixed any additional parameters * @return void */ - function _ci_load_class($class, $params = NULL) + function _ci_load_class($class, $varname = NULL) { // Prep the class name $class = strtolower(str_replace(EXT, '', $class)); @@ -627,7 +627,7 @@ class CI_Loader { } } - return $this->_ci_init_class($filename, 'MY_', $params); + return $this->_ci_init_class($filename, 'MY_', $varname); } // Lets search for the requested library file and load it. @@ -642,7 +642,7 @@ class CI_Loader { if (file_exists($path.'libraries/'.$filename.EXT)) { include_once($path.'libraries/'.$filename.EXT); - return $this->_ci_init_class($filename, '', $params); + return $this->_ci_init_class($filename, '', $varname); } } } @@ -662,15 +662,12 @@ class CI_Loader { * @param string * @return null */ - function _ci_init_class($class, $prefix = '', $config = NULL) + function _ci_init_class($class, $prefix = '', $varname = NULL) { // Is there an associated config file for this class? - if ($config == NULL) + if (file_exists(APPPATH.'config/'.$class.EXT)) { - if (file_exists(APPPATH.'config/'.$class.EXT)) - { - include_once(APPPATH.'config/'.$class.EXT); - } + include_once(APPPATH.'config/'.$class.EXT); } if ($prefix == '') @@ -682,17 +679,17 @@ class CI_Loader { $name = $prefix.$class; } - $varname = ( ! isset($remap[$class])) ? $class : $remap[$class]; - $varname = strtolower($varname); + $classvar = ( ! is_null($varname)) ? $varname : strtolower($class); + // Instantiate the class if ($config !== NULL) { - $this->CI->$varname = new $name($config); + $this->CI->$classvar = new $name($config); } else { - $this->CI->$varname = new $name; + $this->CI->$classvar = new $name; } } diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 21162388a..39e12327f 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -113,8 +113,7 @@ class CI_User_agent { unset($robots); $return = TRUE; } - - + return $return; } -- cgit v1.2.3-24-g4f1b From b1fddc051af66a0a41a709862dd84d06139e2325 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 9 Oct 2006 21:29:07 +0000 Subject: --- system/libraries/Loader.php | 16 +++++++++++++--- system/libraries/User_agent.php | 15 ++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 452e39dfa..dc588bb0c 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -30,12 +30,13 @@ class CI_Loader { var $CI; var $ob_level; + var $view_path = ''; var $cached_vars = array(); var $models = array(); var $helpers = array(); var $plugins = array(); var $scripts = array(); - var $view_path = ''; + var $varmap = array('unit_test' => 'unit', 'user_agent' => 'agent'); /** * Constructor @@ -665,6 +666,7 @@ class CI_Loader { function _ci_init_class($class, $prefix = '', $varname = NULL) { // Is there an associated config file for this class? + $config = NULL; if (file_exists(APPPATH.'config/'.$class.EXT)) { include_once(APPPATH.'config/'.$class.EXT); @@ -678,9 +680,17 @@ class CI_Loader { { $name = $prefix.$class; } - - $classvar = ( ! is_null($varname)) ? $varname : strtolower($class); + // Set the variable name we will assign the class to + if ( ! is_null($varname)) + { + $classvar = $varname; + } + else + { + $class = strtolower($class); + $classvar = ( ! isset($this->varmap[$class])) ? $class : $this->varmap[$class]; + } // Instantiate the class if ($config !== NULL) diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 39e12327f..11c2baa68 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -37,12 +37,16 @@ class CI_User_agent { 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 $moble = ''; var $robot = ''; - /** * Constructor @@ -66,8 +70,9 @@ class CI_User_agent { $this->_compile_data(); } } + + log_message('debug', "Table Class Initialized"); } - // -------------------------------------------------------------------- @@ -79,7 +84,7 @@ class CI_User_agent { */ function _load_agent_file() { - if ( ! @include(APPPATH.'config/user_agent'.EXT)) + if ( ! @include(APPPATH.'config/user_agents'.EXT)) { return FALSE; } @@ -102,7 +107,7 @@ class CI_User_agent { if (isset($mobiles)) { - $this->browsers = $mobiles; + $this->mobiles = $mobiles; unset($mobiles); $return = TRUE; } @@ -344,7 +349,7 @@ class CI_User_agent { * @access public * @return string */ - function agent() + function agent_string() { return $this->agent; } -- cgit v1.2.3-24-g4f1b From daaa0c8403a80d325d3ce2b85c5be62067a3854b Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 9 Oct 2006 21:39:12 +0000 Subject: --- system/libraries/Unit_test.php | 331 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 331 insertions(+) create mode 100644 system/libraries/Unit_test.php (limited to 'system/libraries') diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php new file mode 100644 index 000000000..415162388 --- /dev/null +++ b/system/libraries/Unit_test.php @@ -0,0 +1,331 @@ +active == FALSE) + return FALSE; + + if (in_array($expected, array('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; + $extype = str_replace(array('true', 'false'), 'bool', str_replace('is_', '', $expected)); + } + else + { + if ($this->strict == TRUE) + $result = ($test === $expected) ? TRUE : FALSE; + else + $result = ($test == $expected) ? TRUE : FALSE; + + $extype = gettype($expected); + } + + $back = $this->_backtrace(); + + $report[] = array ( + 'test_name' => $test_name, + 'test_datatype' => gettype($test), + 'res_datatype' => $extype, + 'result' => ($result === TRUE) ? 'passed' : 'failed', + 'file' => $back['file'], + 'line' => $back['line'] + ); + + $this->results[] = $report; + + return($this->report($this->result($report))); + } + + // -------------------------------------------------------------------- + + /** + * Generate a report + * + * Displays a table with the test data + * + * @access public + * @return string + */ + function report($result = array()) + { + if (count($result) == 0) + { + $result = $this->result(); + } + + $this->_parse_template(); + + $r = ''; + foreach ($result as $res) + { + $table = ''; + + foreach ($res as $key => $val) + { + $temp = $this->_template_rows; + $temp = str_replace('{item}', $key, $temp); + $temp = str_replace('{result}', $val, $temp); + $table .= $temp; + } + + $r .= str_replace('{rows}', $table, $this->_template); + } + + return $r; + } + + // -------------------------------------------------------------------- + + /** + * Use strict comparison + * + * Causes the evaluation to use === rather then == + * + * @access public + * @param bool + * @return null + */ + function use_strict($state = TRUE) + { + $this->strict = ($state == FALSE) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Make Unit testing active + * + * Enables/disables unit testing + * + * @access public + * @param bool + * @return null + */ + function active($state = TRUE) + { + $this->active = ($state == FALSE) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Result Array + * + * Returns the raw result data + * + * @access public + * @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) + { + $temp = array(); + foreach ($result as $key => $val) + { + if (is_array($val)) + { + foreach ($val as $k => $v) + { + if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$v)))) + { + $v = $line; + } + $temp[$CI->lang->line('ut_'.$k)] = $v; + } + } + else + { + 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 + * + * This lets us set the template to be used to display results + * + * @access public + * @params string + * @return void + */ + function set_template($template) + { + $this->_template = $template; + } + + // -------------------------------------------------------------------- + + /** + * Generate a backtrace + * + * This lets us show file names and line numbers + * + * @access private + * @return array + */ + function _backtrace() + { + 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 + * + * @access private + * @return string + */ + function _default_template() + { + $this->_template = ' +
+ + {rows} +
'; + + $this->_template_rows = ' + + {item} + {result} + + '; + } + + // -------------------------------------------------------------------- + + /** + * Parse Template + * + * Harvests the data within the template {pseudo-variables} + * + * @access private + * @return void + */ + 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->_template_rows = $match['1']; + $this->_template = str_replace($match['0'], '{rows}', $this->_template); + } + +} +// END Unit_test Class + +/** + * Helper functions to test boolean true/false + * + * + * @access private + * @return bool + */ +function is_true($test) +{ + return (is_bool($test) AND $test === TRUE) ? TRUE : FALSE; +} +function is_false($test) +{ + return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 8d3f977d2c1d4dc01a72c0add3b14ffc73a54762 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 9 Oct 2006 21:39:48 +0000 Subject: --- system/libraries/Loader.php | 7 - system/libraries/Unit.php | 331 -------------------------------------------- 2 files changed, 338 deletions(-) delete mode 100644 system/libraries/Unit.php (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index dc588bb0c..ca4c4feba 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -601,13 +601,6 @@ class CI_Loader { // Prep the class name $class = strtolower(str_replace(EXT, '', $class)); - // Bug fix for backward compat. - // Kill this at some point in the future - if ($class == 'unit_test') - { - $class = 'unit'; - } - // Is this a class extension request? if (substr($class, 0, 3) == 'my_') { diff --git a/system/libraries/Unit.php b/system/libraries/Unit.php deleted file mode 100644 index 439424fbb..000000000 --- a/system/libraries/Unit.php +++ /dev/null @@ -1,331 +0,0 @@ -active == FALSE) - return FALSE; - - if (in_array($expected, array('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; - $extype = str_replace(array('true', 'false'), 'bool', str_replace('is_', '', $expected)); - } - else - { - if ($this->strict == TRUE) - $result = ($test === $expected) ? TRUE : FALSE; - else - $result = ($test == $expected) ? TRUE : FALSE; - - $extype = gettype($expected); - } - - $back = $this->_backtrace(); - - $report[] = array ( - 'test_name' => $test_name, - 'test_datatype' => gettype($test), - 'res_datatype' => $extype, - 'result' => ($result === TRUE) ? 'passed' : 'failed', - 'file' => $back['file'], - 'line' => $back['line'] - ); - - $this->results[] = $report; - - return($this->report($this->result($report))); - } - - // -------------------------------------------------------------------- - - /** - * Generate a report - * - * Displays a table with the test data - * - * @access public - * @return string - */ - function report($result = array()) - { - if (count($result) == 0) - { - $result = $this->result(); - } - - $this->_parse_template(); - - $r = ''; - foreach ($result as $res) - { - $table = ''; - - foreach ($res as $key => $val) - { - $temp = $this->_template_rows; - $temp = str_replace('{item}', $key, $temp); - $temp = str_replace('{result}', $val, $temp); - $table .= $temp; - } - - $r .= str_replace('{rows}', $table, $this->_template); - } - - return $r; - } - - // -------------------------------------------------------------------- - - /** - * Use strict comparison - * - * Causes the evaluation to use === rather then == - * - * @access public - * @param bool - * @return null - */ - function use_strict($state = TRUE) - { - $this->strict = ($state == FALSE) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Make Unit testing active - * - * Enables/disables unit testing - * - * @access public - * @param bool - * @return null - */ - function active($state = TRUE) - { - $this->active = ($state == FALSE) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Result Array - * - * Returns the raw result data - * - * @access public - * @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) - { - $temp = array(); - foreach ($result as $key => $val) - { - if (is_array($val)) - { - foreach ($val as $k => $v) - { - if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$v)))) - { - $v = $line; - } - $temp[$CI->lang->line('ut_'.$k)] = $v; - } - } - else - { - 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 - * - * This lets us set the template to be used to display results - * - * @access public - * @params string - * @return void - */ - function set_template($template) - { - $this->_template = $template; - } - - // -------------------------------------------------------------------- - - /** - * Generate a backtrace - * - * This lets us show file names and line numbers - * - * @access private - * @return array - */ - function _backtrace() - { - 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 - * - * @access private - * @return string - */ - function _default_template() - { - $this->_template = ' -
- - {rows} -
'; - - $this->_template_rows = ' - - {item} - {result} - - '; - } - - // -------------------------------------------------------------------- - - /** - * Parse Template - * - * Harvests the data within the template {pseudo-variables} - * - * @access private - * @return void - */ - 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->_template_rows = $match['1']; - $this->_template = str_replace($match['0'], '{rows}', $this->_template); - } - -} -// END Unit_test Class - -/** - * Helper functions to test boolean true/false - * - * - * @access private - * @return bool - */ -function is_true($test) -{ - return (is_bool($test) AND $test === TRUE) ? TRUE : FALSE; -} -function is_false($test) -{ - return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; -} - -?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From cf49390d3d699d878eb6e151745e80285465ddb9 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 10 Oct 2006 07:12:31 +0000 Subject: --- system/libraries/Controller.php | 17 +--- system/libraries/Loader.php | 219 +++++++++++++++++++++++++++++----------- system/libraries/Model.php | 4 +- 3 files changed, 165 insertions(+), 75 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 4b9e3e960..c80097a17 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -80,20 +80,13 @@ class Controller extends CI_Base { if (floor(phpversion()) >= 5) { $this->load = new CI_Loader(); + $this->load->_ci_use_instance = TRUE; + $this->load->_ci_autoloader(); } - - // Load everything specified in the autoload.php file - $this->load->_ci_autoloader(); - - // This allows anything loaded using $this->load (viwes, files, etc.) - // to become accessible from within the Controller class functions. - foreach (get_object_vars($this) as $key => $var) + else { - if (is_object($var)) - { - $this->load->$key =& $this->$key; - } - } + $this->_ci_autoloader(); + } } // -------------------------------------------------------------------- diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index ca4c4feba..1738438ed 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -28,15 +28,18 @@ */ class CI_Loader { - var $CI; - var $ob_level; - var $view_path = ''; - var $cached_vars = array(); - var $models = array(); - var $helpers = array(); - var $plugins = array(); - var $scripts = array(); - var $varmap = array('unit_test' => 'unit', 'user_agent' => 'agent'); + var $_ci_ob_level; + var $_ci_view_path = ''; + var $_ci_cached_vars = array(); + var $_ci_models = array(); + var $_ci_helpers = array(); + var $_ci_plugins = array(); + var $_ci_scripts = array(); + var $_ci_varmap = array('unit_test' => 'unit', 'user_agent' => 'agent'); + + var $_ci_use_instance = FALSE; // This variable determines whether we should + // use $this or $CI =& get_instance() + // throughout this class. Don't mess with it. /** * Constructor @@ -47,11 +50,9 @@ class CI_Loader { * @access public */ function CI_Loader() - { - $this->CI =& get_instance(); - - $this->view_path = APPPATH.'views/'; - $this->ob_level = ob_get_level(); + { + $this->_ci_view_path = APPPATH.'views/'; + $this->_ci_ob_level = ob_get_level(); log_message('debug', "Loader Class Initialized"); } @@ -95,8 +96,7 @@ class CI_Loader { if ($model == '') return; - // Is the model in a sub-folder? - // If so, parse out the filename and path. + // Is the model in a sub-folder? If so, parse out the filename and path. if (strpos($model, '/') === FALSE) { $path = ''; @@ -114,14 +114,25 @@ class CI_Loader { $name = $model; } - if (in_array($name, $this->models, TRUE)) + if (in_array($name, $this->_ci_models, TRUE)) { return; - } + } - if (isset($this->CI->$name)) + if ($this->_ci_use_instance) + { + $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); + } + } + else { - show_error('The model name you are loading is the name of a resource that is already being used: '.$name); + if (isset($this->$name)) + { + show_error('The model name you are loading is the name of a resource that is already being used: '.$name); + } } $model = strtolower($model); @@ -136,7 +147,14 @@ class CI_Loader { if ($db_conn === TRUE) $db_conn = ''; - $this->CI->load->database($db_conn, FALSE, TRUE); + if ($this->_ci_use_instance) + { + $CI->load->database($db_conn, FALSE, TRUE); + } + else + { + $this->database($db_conn, FALSE, TRUE); + } } if ( ! class_exists('Model')) @@ -147,8 +165,17 @@ class CI_Loader { require_once(APPPATH.'models/'.$path.$model.EXT); $model = ucfirst($model); - $this->CI->$name = new $model(); - $this->models[] = $name; + + if ($this->_ci_use_instance) + { + $CI->$name = new $model(); + } + else + { + $this->$name = new $model(); + } + + $this->_ci_models[] = $name; $this->_ci_assign_to_models(); } @@ -239,7 +266,7 @@ class CI_Loader { { foreach ($vars as $key => $val) { - $this->cached_vars[$key] = $val; + $this->_ci_cached_vars[$key] = $val; } } } @@ -264,7 +291,7 @@ class CI_Loader { foreach ($helpers as $helper) { - if (isset($this->helpers[$helper])) + if (isset($this->_ci_helpers[$helper])) { continue; } @@ -287,7 +314,7 @@ class CI_Loader { } } - $this->helpers[$helper] = TRUE; + $this->_ci_helpers[$helper] = TRUE; } log_message('debug', 'Helpers loaded: '.implode(', ', $helpers)); @@ -330,7 +357,7 @@ class CI_Loader { foreach ($plugins as $plugin) { - if (isset($this->plugins[$plugin])) + if (isset($this->_ci_plugins[$plugin])) { continue; } @@ -353,7 +380,7 @@ class CI_Loader { } } - $this->plugins[$plugin] = TRUE; + $this->_ci_plugins[$plugin] = TRUE; } log_message('debug', 'Plugins loaded: '.implode(', ', $plugins)); @@ -400,7 +427,7 @@ class CI_Loader { foreach ($scripts as $script) { - if (isset($this->scripts[$script])) + if (isset($this->_ci_scripts[$script])) { continue; } @@ -414,7 +441,7 @@ class CI_Loader { include_once(APPPATH.'scripts/'.$script.EXT); - $this->scripts[$script] = TRUE; + $this->_ci_scripts[$script] = TRUE; } log_message('debug', 'Scripts loaded: '.implode(', ', $scripts)); @@ -431,7 +458,15 @@ class CI_Loader { */ function language($file = '', $lang = '', $return = FALSE) { - return $this->CI->lang->load($file, $lang, $return); + if ($this->_ci_use_instance) + { + $CI =& get_instance(); + return $CI->lang->load($file, $lang, $return); + } + else + { + return $this->lang->load($file, $lang, $return); + } } // -------------------------------------------------------------------- @@ -444,8 +479,16 @@ class CI_Loader { * @return void */ function config($file = '') - { - $this->CI->config->load($file); + { + if ($this->_ci_use_instance) + { + $CI =& get_instance(); + $CI->config->load($file); + } + else + { + $this->config->load($file); + } } // -------------------------------------------------------------------- @@ -471,9 +514,18 @@ class CI_Loader { { show_error('You must include the name of the table you would like access when you initialize scaffolding'); } - - $this->CI->_ci_scaffolding = TRUE; - $this->CI->_ci_scaff_table = $table; + + if ($this->_ci_use_instance) + { + $CI =& get_instance(); + $CI->_ci_scaffolding = TRUE; + $CI->_ci_scaff_table = $table; + } + else + { + $this->_ci_scaffolding = TRUE; + $this->_ci_scaff_table = $table; + } } // -------------------------------------------------------------------- @@ -491,14 +543,20 @@ class CI_Loader { { // This allows anything loaded using $this->load (viwes, files, etc.) // to become accessible from within the Controller and Model functions. - foreach (get_object_vars($this->CI) as $key => $var) + // Only needed when running PHP 5 + + if ($this->_ci_use_instance) { - if (is_object($var)) + $CI =& get_instance(); + foreach (get_object_vars($CI) as $key => $var) { - $this->$key =& $this->CI->$key; + if ( ! isset($this->$key)) + { + $this->$key =& $CI->$key; + } } } - + // Set the default data variables foreach (array('view', 'vars', 'path', 'return') as $val) { @@ -515,16 +573,16 @@ class CI_Loader { */ if (is_array($vars)) { - $this->cached_vars = array_merge($this->cached_vars, $vars); + $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $vars); } - extract($this->cached_vars); + extract($this->_ci_cached_vars); // Set the path to the requested file if ($path == '') { $ext = pathinfo($view, PATHINFO_EXTENSION); $file = ($ext == '') ? $view.EXT : $view; - $path = $this->view_path.$file; + $path = $this->_ci_view_path.$file; } else { @@ -572,14 +630,15 @@ 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->ob_level + 1) + */ + if (ob_get_level() > $this->_ci_ob_level + 1) { ob_end_flush(); } else { - $this->CI->output->set_output(ob_get_contents()); + global $OUT; + $OUT->set_output(ob_get_contents()); ob_end_clean(); } } @@ -682,18 +741,33 @@ class CI_Loader { else { $class = strtolower($class); - $classvar = ( ! isset($this->varmap[$class])) ? $class : $this->varmap[$class]; + $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; } - // Instantiate the class - if ($config !== NULL) + // Instantiate the class + if ($this->_ci_use_instance) { - $this->CI->$classvar = new $name($config); + $CI =& get_instance(); + if ($config !== NULL) + { + $CI->$classvar = new $name($config); + } + else + { + $CI->$classvar = new $name; + } } else - { - $this->CI->$classvar = new $name; - } + { + if ($config !== NULL) + { + $this->$classvar = new $name($config); + } + else + { + $this->$classvar = new $name; + } + } } // -------------------------------------------------------------------- @@ -719,10 +793,21 @@ class CI_Loader { // Load any custome config file if (count($autoload['config']) > 0) - { - foreach ($autoload['config'] as $key => $val) + { + if ($this->_ci_use_instance) + { + $CI =& get_instance(); + foreach ($autoload['config'] as $key => $val) + { + $CI->config->load($val); + } + } + else { - $this->CI->config->load($val); + foreach ($autoload['config'] as $key => $val) + { + $this->config->load($val); + } } } @@ -788,14 +873,26 @@ class CI_Loader { */ function _ci_assign_to_models() { - if (count($this->models) == 0) + if (count($this->_ci_models) == 0) { return; } - foreach ($this->models as $model) - { - $this->CI->$model->_assign_libraries(); - } + + if ($this->_ci_use_instance) + { + $CI =& get_instance(); + foreach ($this->_ci_models as $model) + { + $CI->$model->_assign_libraries(); + } + } + else + { + foreach ($this->_ci_models as $model) + { + $this->$model->_assign_libraries(); + } + } } // -------------------------------------------------------------------- diff --git a/system/libraries/Model.php b/system/libraries/Model.php index 46f0367cb..48615e07c 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -51,8 +51,8 @@ class Model { { $CI =& get_instance(); foreach (get_object_vars($CI) as $key => $var) - { - if (is_object($var) AND ! isset($this->$key)) + { + if ( ! isset($this->$key)) { if ($use_reference === TRUE) { -- cgit v1.2.3-24-g4f1b From 34f7f2d0a84c59233689908c11d8d2c6c5ba0875 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 10 Oct 2006 08:06:42 +0000 Subject: --- system/libraries/Controller.php | 3 +- system/libraries/Loader.php | 77 +++++++++++++++++++++++++++++------------ 2 files changed, 57 insertions(+), 23 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index c80097a17..7a3f5e5d5 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -32,6 +32,8 @@ class Controller extends CI_Base { var $_ci_scaffolding = FALSE; var $_ci_scaff_table = FALSE; + + /** * Constructor * @@ -80,7 +82,6 @@ class Controller extends CI_Base { if (floor(phpversion()) >= 5) { $this->load = new CI_Loader(); - $this->load->_ci_use_instance = TRUE; $this->load->_ci_autoloader(); } else diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 1738438ed..43d1cbecb 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -28,8 +28,11 @@ */ class CI_Loader { + // All these are set automatically. Don't mess with them. var $_ci_ob_level; var $_ci_view_path = ''; + var $_ci_is_php5 = FALSE; + var $_ci_use_instance = FALSE; // Whether we should use $this or $CI =& get_instance() var $_ci_cached_vars = array(); var $_ci_models = array(); var $_ci_helpers = array(); @@ -37,20 +40,17 @@ class CI_Loader { var $_ci_scripts = array(); var $_ci_varmap = array('unit_test' => 'unit', 'user_agent' => 'agent'); - var $_ci_use_instance = FALSE; // This variable determines whether we should - // use $this or $CI =& get_instance() - // throughout this class. Don't mess with it. /** * Constructor * - * Sets the path to the view files and gets the initial output - * buffering level + * Sets the path to the view files and gets the initial output buffering level * * @access public */ function CI_Loader() { + $this->_ci_is_php5 = (floor(phpversion()) >= 5) ? TRUE : FALSE; $this->_ci_view_path = APPPATH.'views/'; $this->_ci_ob_level = ob_get_level(); @@ -119,7 +119,7 @@ class CI_Loader { return; } - if ($this->_ci_use_instance) + if ($this->_ci_use_instance()) { $CI =& get_instance(); if (isset($CI->$name)) @@ -147,7 +147,7 @@ class CI_Loader { if ($db_conn === TRUE) $db_conn = ''; - if ($this->_ci_use_instance) + if ($this->_ci_use_instance()) { $CI->load->database($db_conn, FALSE, TRUE); } @@ -165,20 +165,34 @@ class CI_Loader { require_once(APPPATH.'models/'.$path.$model.EXT); $model = ucfirst($model); - - if ($this->_ci_use_instance) + + if ($this->_ci_use_instance()) { - $CI->$name = new $model(); + $CI->$name = new $model(); + foreach (get_object_vars($CI) as $key => $var) + { + if ( ! isset($CI->$name->$key)) + { + $CI->$name->$key =& $CI->$key; + } + } } else { $this->$name = new $model(); - } + foreach (get_object_vars($this) as $key => $var) + { + if ( ! isset($this->$name->$key)) + { + $this->$name->$key =& $CI->$key; + } + } + } $this->_ci_models[] = $name; - $this->_ci_assign_to_models(); } + // -------------------------------------------------------------------- /** @@ -458,7 +472,7 @@ class CI_Loader { */ function language($file = '', $lang = '', $return = FALSE) { - if ($this->_ci_use_instance) + if ($this->_ci_use_instance()) { $CI =& get_instance(); return $CI->lang->load($file, $lang, $return); @@ -480,7 +494,7 @@ class CI_Loader { */ function config($file = '') { - if ($this->_ci_use_instance) + if ($this->_ci_use_instance()) { $CI =& get_instance(); $CI->config->load($file); @@ -515,7 +529,7 @@ class CI_Loader { show_error('You must include the name of the table you would like access when you initialize scaffolding'); } - if ($this->_ci_use_instance) + if ($this->_ci_use_instance()) { $CI =& get_instance(); $CI->_ci_scaffolding = TRUE; @@ -545,7 +559,7 @@ class CI_Loader { // to become accessible from within the Controller and Model functions. // Only needed when running PHP 5 - if ($this->_ci_use_instance) + if ($this->_ci_use_instance()) { $CI =& get_instance(); foreach (get_object_vars($CI) as $key => $var) @@ -627,7 +641,7 @@ class CI_Loader { * In order to permit views to be nested within * other views, we need to flush the content back out whenever * we are beyond the first level of output buffering so that - * it can be seen and included properly by the first included + * it can be seen and included properly by the first included * template and any subsequent ones. Oy! * */ @@ -637,6 +651,7 @@ class CI_Loader { } else { + // PHP 4 requires that we use a global global $OUT; $OUT->set_output(ob_get_contents()); ob_end_clean(); @@ -745,7 +760,7 @@ class CI_Loader { } // Instantiate the class - if ($this->_ci_use_instance) + if ($this->_ci_use_instance()) { $CI =& get_instance(); if ($config !== NULL) @@ -794,7 +809,7 @@ class CI_Loader { // Load any custome config file if (count($autoload['config']) > 0) { - if ($this->_ci_use_instance) + if ($this->_ci_use_instance()) { $CI =& get_instance(); foreach ($autoload['config'] as $key => $val) @@ -867,7 +882,7 @@ class CI_Loader { * Makes sure that anything loaded by the loader class (libraries, plugins, etc.) * will be available to modles, if any exist. * - * @access public + * @access private * @param object * @return array */ @@ -878,7 +893,7 @@ class CI_Loader { return; } - if ($this->_ci_use_instance) + if ($this->_ci_use_instance()) { $CI =& get_instance(); foreach ($this->_ci_models as $model) @@ -902,7 +917,7 @@ class CI_Loader { * * Takes an object as input and convers the class variables to array key/vals * - * @access public + * @access private * @param object * @return array */ @@ -911,6 +926,24 @@ class CI_Loader { return (is_object($object)) ? get_object_vars($object) : $object; } + // -------------------------------------------------------------------- + + /** + * Determines whether we should use the CI instance or $this + * + * @access private + * @return bool + */ + function _ci_use_instance() + { + if ($this->_ci_is_php5 == TRUE) + { + return TRUE; + } + + global $CI; + return (is_object($CI)) ? TRUE : FALSE; + } } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 1e3039878265b09e85f14e6b5ad3fbb6d4aa24c3 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 10 Oct 2006 16:35:43 +0000 Subject: --- system/libraries/Loader.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 43d1cbecb..96ec0c919 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -32,7 +32,7 @@ class CI_Loader { var $_ci_ob_level; var $_ci_view_path = ''; var $_ci_is_php5 = FALSE; - var $_ci_use_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 $_ci_cached_vars = array(); var $_ci_models = array(); var $_ci_helpers = array(); @@ -119,7 +119,7 @@ class CI_Loader { return; } - if ($this->_ci_use_instance()) + if ($this->_ci_is_instance()) { $CI =& get_instance(); if (isset($CI->$name)) @@ -147,7 +147,7 @@ class CI_Loader { if ($db_conn === TRUE) $db_conn = ''; - if ($this->_ci_use_instance()) + if ($this->_ci_is_instance()) { $CI->load->database($db_conn, FALSE, TRUE); } @@ -166,7 +166,7 @@ class CI_Loader { $model = ucfirst($model); - if ($this->_ci_use_instance()) + if ($this->_ci_is_instance()) { $CI->$name = new $model(); foreach (get_object_vars($CI) as $key => $var) @@ -472,7 +472,7 @@ class CI_Loader { */ function language($file = '', $lang = '', $return = FALSE) { - if ($this->_ci_use_instance()) + if ($this->_ci_is_instance()) { $CI =& get_instance(); return $CI->lang->load($file, $lang, $return); @@ -494,7 +494,7 @@ class CI_Loader { */ function config($file = '') { - if ($this->_ci_use_instance()) + if ($this->_ci_is_instance()) { $CI =& get_instance(); $CI->config->load($file); @@ -529,7 +529,7 @@ class CI_Loader { show_error('You must include the name of the table you would like access when you initialize scaffolding'); } - if ($this->_ci_use_instance()) + if ($this->_ci_is_instance()) { $CI =& get_instance(); $CI->_ci_scaffolding = TRUE; @@ -559,7 +559,7 @@ class CI_Loader { // to become accessible from within the Controller and Model functions. // Only needed when running PHP 5 - if ($this->_ci_use_instance()) + if ($this->_ci_is_instance()) { $CI =& get_instance(); foreach (get_object_vars($CI) as $key => $var) @@ -760,7 +760,7 @@ class CI_Loader { } // Instantiate the class - if ($this->_ci_use_instance()) + if ($this->_ci_is_instance()) { $CI =& get_instance(); if ($config !== NULL) @@ -809,7 +809,7 @@ class CI_Loader { // Load any custome config file if (count($autoload['config']) > 0) { - if ($this->_ci_use_instance()) + if ($this->_ci_is_instance()) { $CI =& get_instance(); foreach ($autoload['config'] as $key => $val) @@ -893,7 +893,7 @@ class CI_Loader { return; } - if ($this->_ci_use_instance()) + if ($this->_ci_is_instance()) { $CI =& get_instance(); foreach ($this->_ci_models as $model) @@ -934,7 +934,7 @@ class CI_Loader { * @access private * @return bool */ - function _ci_use_instance() + function _ci_is_instance() { if ($this->_ci_is_php5 == TRUE) { -- cgit v1.2.3-24-g4f1b From 7099a589d1719311427d7552523ec962ebc3b650 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 10 Oct 2006 17:47:59 +0000 Subject: --- system/libraries/Config.php | 2 +- system/libraries/Controller.php | 2 +- system/libraries/Hooks.php | 2 +- system/libraries/Input.php | 5 +++-- system/libraries/Log.php | 2 +- system/libraries/Output.php | 4 ++-- system/libraries/Router.php | 2 +- system/libraries/URI.php | 2 +- 8 files changed, 11 insertions(+), 10 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Config.php b/system/libraries/Config.php index 26770cc4f..82836b1f3 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -44,7 +44,7 @@ class CI_Config { */ function CI_Config() { - $this->config =& _get_config(); + $this->config = get_config(); log_message('debug', "Config Class Initialized"); } // END CI_Config() diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 7a3f5e5d5..938c46e4c 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -73,7 +73,7 @@ class Controller extends CI_Base { foreach ($classes as $var => $class) { - $this->$var =& _load_class($class); + $this->$var =& load_class($class); } diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index 8767e10d0..e2d0500c0 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -53,7 +53,7 @@ class CI_Hooks { */ function _initialize() { - $CFG =& _load_class('Config'); + $CFG =& load_class('Config'); // If hooks are not enabled in the config file // there is nothing else to do diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 0d3c87b49..72344e343 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -44,7 +44,7 @@ class CI_Input { { log_message('debug', "Input Class Initialized"); - $CFG =& _load_class('Config'); + $CFG =& load_class('Config'); $this->use_xss_clean = ($CFG->item('global_xss_filtering') === TRUE) ? TRUE : FALSE; $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; $this->_sanitize_globals(); @@ -306,7 +306,8 @@ class CI_Input { if ($this->ip_address === FALSE) { - return $this->ip_address = '0.0.0.0'; + $this->ip_address = '0.0.0.0'; + return $this->ip_address; } if (strstr($this->ip_address, ',')) diff --git a/system/libraries/Log.php b/system/libraries/Log.php index eff7cb7fc..09538fa0b 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -42,7 +42,7 @@ class CI_Log { */ function CI_Log() { - $config =& _get_config(); + $config = get_config(); $this->log_path = ($config['log_path'] != '') ? $config['log_path'] : BASEPATH.'logs/'; diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 507beab59..7e859453e 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -299,8 +299,8 @@ class CI_Output { */ function _display_cache(&$CFG, &$RTR) { - $CFG =& _load_class('Config'); - $RTR =& _load_class('Router'); + $CFG =& load_class('Config'); + $RTR =& load_class(('Router'); $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 27e3c27cc..dab84883e 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -48,7 +48,7 @@ class CI_Router { */ function CI_Router() { - $this->config =& _load_class('Config'); + $this->config =& load_class('Config'); $this->_set_route_mapping(); log_message('debug', "Router Class Initialized"); } diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 80b112660..fcf6afe4b 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -42,7 +42,7 @@ class CI_URI { */ function CI_URI() { - $this->router =& _load_class('Router'); + $this->router =& load_class('Router'); log_message('debug', "URI Class Initialized"); } -- cgit v1.2.3-24-g4f1b From 1b0ab4665720446eee6b03f864bb5576e6065a4a Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 10 Oct 2006 23:30:21 +0000 Subject: --- system/libraries/Output.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 7e859453e..9c48bbb84 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -300,7 +300,7 @@ class CI_Output { function _display_cache(&$CFG, &$RTR) { $CFG =& load_class('Config'); - $RTR =& load_class(('Router'); + $RTR =& load_class('Router'); $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); -- cgit v1.2.3-24-g4f1b From 2799120c10b8d2544dd71e37b3a48c1eaa834c48 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 11 Oct 2006 01:38:08 +0000 Subject: --- system/libraries/Table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 4771295a5..0f2c49d96 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -50,7 +50,7 @@ class CI_Table { */ function set_template($template) { - if ( ! is_array()) + if ( ! is_array($template)) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 4003718f35247ef9b4a8d678389bda639677bac7 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 11 Oct 2006 19:16:58 +0000 Subject: --- system/libraries/Controller.php | 3 +-- system/libraries/Table.php | 8 ++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 938c46e4c..88ab46164 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -75,8 +75,7 @@ class Controller extends CI_Base { { $this->$var =& load_class($class); } - - + // In PHP 5 the Controller class is run as a discreet // class. In PHP 4 it extends the Controller if (floor(phpversion()) >= 5) diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 0f2c49d96..61d04eef5 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -211,9 +211,13 @@ class CI_Table { } // Next blast through the result array and build out the rows - foreach ($query->result_array() as $row) + + if ($query->num_rows() > 0) { - $this->rows[] = $row; + foreach ($query->result_array() as $row) + { + $this->rows[] = $row; + } } } -- cgit v1.2.3-24-g4f1b From 4c1ab6c826c3f5c3158a38443c2d3c30203f0f5a Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 11 Oct 2006 21:48:33 +0000 Subject: --- system/libraries/Router.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index dab84883e..ead1439f6 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -366,24 +366,30 @@ class CI_Router { */ function _parse_request_uri() { - if (($request_uri = getenv('REQUEST_URI')) == '') + if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '') { return ''; } - $fc_path = FCPATH; + $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI'])); + + if ($request_uri == '') + { + return ''; + } + $fc_path = FCPATH; if (strpos($request_uri, '?') !== FALSE) { $fc_path .= '?'; } - $parsed_uri = explode("/", preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $request_uri))); - + $parsed_uri = explode("/", $request_uri); + $i = 0; foreach(explode("/", $fc_path) as $segment) { - if ($segment == $parsed_uri[$i]) + if (isset($parsed_uri[$i]) AND $segment == $parsed_uri[$i]) { $i++; } -- cgit v1.2.3-24-g4f1b From 606f99c043272f96f21911d89c21cd36c2ef59e4 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 11 Oct 2006 23:48:41 +0000 Subject: --- system/libraries/Loader.php | 11 +++-------- system/libraries/Table.php | 4 ++-- 2 files changed, 5 insertions(+), 10 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 96ec0c919..7a6637ac0 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -171,10 +171,7 @@ class CI_Loader { $CI->$name = new $model(); foreach (get_object_vars($CI) as $key => $var) { - if ( ! isset($CI->$name->$key)) - { - $CI->$name->$key =& $CI->$key; - } + $CI->$name->$key =& $CI->$key; } } else @@ -182,14 +179,12 @@ class CI_Loader { $this->$name = new $model(); foreach (get_object_vars($this) as $key => $var) { - if ( ! isset($this->$name->$key)) - { - $this->$name->$key =& $CI->$key; - } + $this->$name->$key =& $this->$key; } } $this->_ci_models[] = $name; + $this->_ci_assign_to_models(); } diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 61d04eef5..758676e27 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -202,12 +202,12 @@ class CI_Table { // First generate the headings from the table column names if (count($this->heading) == 0) { - if ( ! method_exists($query, 'field_names')) + if ( ! method_exists($query, 'list_fields')) { return FALSE; } - $this->heading = $query->field_names(); + $this->heading = $query->list_fields(); } // Next blast through the result array and build out the rows -- cgit v1.2.3-24-g4f1b From 0aef222d246da84c90e9a89f31f6677cbe6b4ddc Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 12 Oct 2006 18:00:22 +0000 Subject: --- system/libraries/Controller.php | 2 +- system/libraries/Loader.php | 173 ++++++++++++++-------------------------- system/libraries/Model.php | 28 ++----- 3 files changed, 71 insertions(+), 132 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 88ab46164..0bbc7773e 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -88,7 +88,7 @@ class Controller extends CI_Base { $this->_ci_autoloader(); } } - + // -------------------------------------------------------------------- /** diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 7a6637ac0..1f6a8bce1 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -119,20 +119,10 @@ class CI_Loader { return; } - if ($this->_ci_is_instance()) - { - $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); - } - } - else + $CI =& get_instance(); + if (isset($CI->$name)) { - if (isset($this->$name)) - { - show_error('The model name you are loading is the name of a resource that is already being used: '.$name); - } + show_error('The model name you are loading is the name of a resource that is already being used: '.$name); } $model = strtolower($model); @@ -147,14 +137,7 @@ class CI_Loader { if ($db_conn === TRUE) $db_conn = ''; - if ($this->_ci_is_instance()) - { - $CI->load->database($db_conn, FALSE, TRUE); - } - else - { - $this->database($db_conn, FALSE, TRUE); - } + $CI->load->database($db_conn, FALSE, TRUE); } if ( ! class_exists('Model')) @@ -166,28 +149,12 @@ class CI_Loader { $model = ucfirst($model); - if ($this->_ci_is_instance()) - { - $CI->$name = new $model(); - foreach (get_object_vars($CI) as $key => $var) - { - $CI->$name->$key =& $CI->$key; - } - } - else - { - $this->$name = new $model(); - foreach (get_object_vars($this) as $key => $var) - { - $this->$name->$key =& $this->$key; - } - } + $CI->$name = new $model(); + $CI->$name->_assign_libraries(); - $this->_ci_models[] = $name; - $this->_ci_assign_to_models(); + $this->_ci_models[] = $name; } - - + // -------------------------------------------------------------------- /** @@ -201,19 +168,49 @@ class CI_Loader { */ function database($params = '', $return = FALSE, $active_record = FALSE) { + // Do we even need to load the database class? + if (class_exists('CI_DB') AND $return == FALSE AND $active_record == FALSE) + { + return FALSE; + } + require_once(BASEPATH.'database/DB'.EXT); if ($return === TRUE) { - return DB($params, $return, $active_record); + return DB($params, $active_record); } - else + + $CI =& get_instance(); + $CI->db =& DB($params, $active_record); + $this->_ci_assign_to_models(); + } + + // -------------------------------------------------------------------- + + /** + * Load the Utilities Class + * + * @access public + * @return string + */ + function dbutil() + { + if ( ! class_exists('CI_DB')) { - DB($params, $return, $active_record); - $this->_ci_assign_to_models(); + $this->database(); } - } + $CI =& get_instance(); + + 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'; + + $CI->dbutil = new $class(); + $CI->load->_ci_assign_to_models(); + } + // -------------------------------------------------------------------- /** @@ -467,15 +464,8 @@ class CI_Loader { */ function language($file = '', $lang = '', $return = FALSE) { - if ($this->_ci_is_instance()) - { - $CI =& get_instance(); - return $CI->lang->load($file, $lang, $return); - } - else - { - return $this->lang->load($file, $lang, $return); - } + $CI =& get_instance(); + return $CI->lang->load($file, $lang, $return); } // -------------------------------------------------------------------- @@ -489,15 +479,8 @@ class CI_Loader { */ function config($file = '') { - if ($this->_ci_is_instance()) - { - $CI =& get_instance(); - $CI->config->load($file); - } - else - { - $this->config->load($file); - } + $CI =& get_instance(); + $CI->config->load($file); } // -------------------------------------------------------------------- @@ -524,17 +507,9 @@ class CI_Loader { show_error('You must include the name of the table you would like access when you initialize scaffolding'); } - if ($this->_ci_is_instance()) - { - $CI =& get_instance(); - $CI->_ci_scaffolding = TRUE; - $CI->_ci_scaff_table = $table; - } - else - { - $this->_ci_scaffolding = TRUE; - $this->_ci_scaff_table = $table; - } + $CI =& get_instance(); + $CI->_ci_scaffolding = TRUE; + $CI->_ci_scaff_table = $table; } // -------------------------------------------------------------------- @@ -755,29 +730,15 @@ class CI_Loader { } // Instantiate the class - if ($this->_ci_is_instance()) + $CI =& get_instance(); + if ($config !== NULL) { - $CI =& get_instance(); - if ($config !== NULL) - { - $CI->$classvar = new $name($config); - } - else - { - $CI->$classvar = new $name; - } + $CI->$classvar = new $name($config); } else - { - if ($config !== NULL) - { - $this->$classvar = new $name($config); - } - else - { - $this->$classvar = new $name; - } - } + { + $CI->$classvar = new $name; + } } // -------------------------------------------------------------------- @@ -804,20 +765,10 @@ class CI_Loader { // Load any custome config file if (count($autoload['config']) > 0) { - if ($this->_ci_is_instance()) - { - $CI =& get_instance(); - foreach ($autoload['config'] as $key => $val) - { - $CI->config->load($val); - } - } - else + $CI =& get_instance(); + foreach ($autoload['config'] as $key => $val) { - foreach ($autoload['config'] as $key => $val) - { - $this->config->load($val); - } + $CI->config->load($val); } } @@ -893,14 +844,14 @@ class CI_Loader { $CI =& get_instance(); foreach ($this->_ci_models as $model) { - $CI->$model->_assign_libraries(); + $CI->$model->_assign_libraries(); } } else - { + { foreach ($this->_ci_models as $model) { - $this->$model->_assign_libraries(); + $this->$model->_assign_libraries(); } } } diff --git a/system/libraries/Model.php b/system/libraries/Model.php index 48615e07c..017a9c6d8 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -33,10 +33,9 @@ class Model { */ function Model() { - $this->_assign_libraries(FALSE); + $this->_assign_libraries(); log_message('debug', "Model Class Initialized"); } - // END Model() /** * Assign Libraries @@ -47,26 +46,15 @@ class Model { * * @access private */ - function _assign_libraries($use_reference = TRUE) + function _assign_libraries() { - $CI =& get_instance(); - foreach (get_object_vars($CI) as $key => $var) - { - if ( ! isset($this->$key)) - { - if ($use_reference === TRUE) - { - $this->$key =& $CI->$key; - } - else - { - $this->$key = $CI->$key; - } - } - } - + $CI =& get_instance(); + + foreach (array_keys(get_object_vars($CI)) as $key) + { + $this->$key =& $CI->$key; + } } - // END _assign_libraries() } // END Model Class -- cgit v1.2.3-24-g4f1b From 9fa003797d794a63aa58356926fac9649269c668 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 12 Oct 2006 18:20:13 +0000 Subject: --- system/libraries/Encrypt.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 50b3fab39..b7dba2523 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -272,15 +272,15 @@ class CI_Encrypt { // -------------------------------------------------------------------- /** - * Set the Mcrypt Cypher + * Set the Mcrypt Cipher * * @access public * @param constant * @return string */ - function set_cypher($cypher) + function set_cipher($cipher) { - $this->_mcrypt_cipher = $cypher; + $this->_mcrypt_cipher = $cipher; } // -------------------------------------------------------------------- @@ -300,12 +300,12 @@ class CI_Encrypt { // -------------------------------------------------------------------- /** - * Get Mcrypt Cypher Value + * Get Mcrypt cipher Value * * @access private * @return string */ - function _get_cypher() + function _get_cipher() { if ($this->_mcrypt_cipher == '') { -- cgit v1.2.3-24-g4f1b From 80b2bd9b7f1ecafed0d0170be60bd0a2d8a4201c Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 12 Oct 2006 18:30:36 +0000 Subject: --- system/libraries/Loader.php | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 1f6a8bce1..2d312e9eb 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -67,15 +67,15 @@ class CI_Loader { * * @access public * @param string the name of the class - * @param sring the optional class variable name to assign the library to + * @param mixed the optional parameters * @return void */ - function library($class, $varname = NULL) + function library($class, $params = FALSE) { if ($class == '') return; - $this->_ci_load_class($class, $varname); + $this->_ci_load_class($class, $params); $this->_ci_assign_to_models(); } @@ -640,7 +640,7 @@ class CI_Loader { * @param mixed any additional parameters * @return void */ - function _ci_load_class($class, $varname = NULL) + function _ci_load_class($class, $params = FALSE) { // Prep the class name $class = strtolower(str_replace(EXT, '', $class)); @@ -665,7 +665,7 @@ class CI_Loader { } } - return $this->_ci_init_class($filename, 'MY_', $varname); + return $this->_ci_init_class($filename, 'MY_', $params); } // Lets search for the requested library file and load it. @@ -680,7 +680,7 @@ class CI_Loader { if (file_exists($path.'libraries/'.$filename.EXT)) { include_once($path.'libraries/'.$filename.EXT); - return $this->_ci_init_class($filename, '', $varname); + return $this->_ci_init_class($filename, '', $params); } } } @@ -700,13 +700,16 @@ class CI_Loader { * @param string * @return null */ - function _ci_init_class($class, $prefix = '', $varname = NULL) + function _ci_init_class($class, $prefix = '', $config = FALSE) { // Is there an associated config file for this class? - $config = NULL; - if (file_exists(APPPATH.'config/'.$class.EXT)) + if ($config !== FALSE) { - include_once(APPPATH.'config/'.$class.EXT); + $config = FALSE; + if (file_exists(APPPATH.'config/'.$class.EXT)) + { + include_once(APPPATH.'config/'.$class.EXT); + } } if ($prefix == '') @@ -719,16 +722,9 @@ class CI_Loader { } // Set the variable name we will assign the class to - if ( ! is_null($varname)) - { - $classvar = $varname; - } - else - { - $class = strtolower($class); - $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; - } - + $class = strtolower($class); + $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; + // Instantiate the class $CI =& get_instance(); if ($config !== NULL) -- cgit v1.2.3-24-g4f1b From f6615e650f7f871fbb4a2e0e1a75fd9afa2e3647 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 12 Oct 2006 19:16:57 +0000 Subject: --- system/libraries/Router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index ead1439f6..bbfa0d192 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -373,7 +373,7 @@ class CI_Router { $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI'])); - if ($request_uri == '') + if ($request_uri == '' OR $request_uri == SELF) { return ''; } -- cgit v1.2.3-24-g4f1b From 5a14ea1599841bdaac15b45e3efd4cba01601f49 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 12 Oct 2006 20:42:55 +0000 Subject: --- system/libraries/Loader.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 2d312e9eb..7bf11609b 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -70,7 +70,7 @@ class CI_Loader { * @param mixed the optional parameters * @return void */ - function library($class, $params = FALSE) + function library($class, $params = NULL) { if ($class == '') return; @@ -640,7 +640,7 @@ class CI_Loader { * @param mixed any additional parameters * @return void */ - function _ci_load_class($class, $params = FALSE) + function _ci_load_class($class, $params = NULL) { // Prep the class name $class = strtolower(str_replace(EXT, '', $class)); @@ -700,12 +700,12 @@ class CI_Loader { * @param string * @return null */ - function _ci_init_class($class, $prefix = '', $config = FALSE) + function _ci_init_class($class, $prefix = '', $config = NULL) { // Is there an associated config file for this class? - if ($config !== FALSE) + if ($config !== NULL) { - $config = FALSE; + $config = NULL; if (file_exists(APPPATH.'config/'.$class.EXT)) { include_once(APPPATH.'config/'.$class.EXT); -- cgit v1.2.3-24-g4f1b From b06d69f03f5149877390d7e99882006a141268ff Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 13 Oct 2006 21:44:17 +0000 Subject: --- system/libraries/Profiler.php | 15 +++++++++++++-- system/libraries/Session.php | 18 +++--------------- 2 files changed, 16 insertions(+), 17 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 3370c9113..7fecabd21 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -94,7 +94,12 @@ class CI_Profiler { // -------------------------------------------------------------------- - + /** + * Compile Queries + * + * @access private + * @return string + */ function _compile_queries() { $output = "\n\n"; @@ -130,7 +135,13 @@ class CI_Profiler { } // -------------------------------------------------------------------- - + + /** + * Compile $_POST Data + * + * @access private + * @return string + */ function _compile_post() { $output = "\n\n"; diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 16f373fd0..8390fd6d4 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -112,10 +112,8 @@ class CI_Session { } } - // Do we need encryption? - $this->encryption = $this->CI->config->item('sess_encrypt_cookie'); - - if ($this->encryption == TRUE) + // Do we need encryption? + if ($this->CI->config->item('sess_encrypt_cookie') == TRUE) { $this->CI->load->library('encrypt'); } @@ -160,7 +158,6 @@ class CI_Session { $this->sess_gc(); } } - // END sess_run() // -------------------------------------------------------------------- @@ -257,7 +254,6 @@ class CI_Session { return TRUE; } - // END sess_read() // -------------------------------------------------------------------- @@ -285,7 +281,6 @@ class CI_Session { 0 ); } - // END sess_read() // -------------------------------------------------------------------- @@ -321,7 +316,6 @@ class CI_Session { $this->userdata['last_visit'] = 0; $this->sess_write(); } - // END sess_read() // -------------------------------------------------------------------- @@ -349,7 +343,6 @@ class CI_Session { // Write the cookie $this->sess_write(); } - // END sess_update() // -------------------------------------------------------------------- @@ -370,7 +363,6 @@ class CI_Session { 0 ); } - // END sess_destroy() // -------------------------------------------------------------------- @@ -396,7 +388,6 @@ class CI_Session { log_message('debug', 'Session garbage collection performed.'); } } - // END sess_destroy() // -------------------------------------------------------------------- @@ -411,7 +402,6 @@ class CI_Session { { return ( ! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; } - // END sess_destroy() // -------------------------------------------------------------------- @@ -440,7 +430,6 @@ class CI_Session { $this->sess_write(); } - // END set_userdata() // -------------------------------------------------------------------- @@ -467,7 +456,6 @@ class CI_Session { $this->sess_write(); } - // END set_userdata() // -------------------------------------------------------------------- @@ -494,7 +482,7 @@ class CI_Session { return $vals; } - // END strip_slashes() + } // END Session Class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 9a661810d2b9b96c458c1f369f0059b31012b6a8 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 16 Oct 2006 19:02:48 +0000 Subject: --- system/libraries/Loader.php | 5 ++--- system/libraries/Router.php | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 7bf11609b..b402464e2 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -703,9 +703,8 @@ class CI_Loader { function _ci_init_class($class, $prefix = '', $config = NULL) { // Is there an associated config file for this class? - if ($config !== NULL) - { - $config = NULL; + if ($config === NULL) + { if (file_exists(APPPATH.'config/'.$class.EXT)) { include_once(APPPATH.'config/'.$class.EXT); diff --git a/system/libraries/Router.php b/system/libraries/Router.php index bbfa0d192..06037209b 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -373,7 +373,7 @@ class CI_Router { $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI'])); - if ($request_uri == '' OR $request_uri == SELF) + if ($request_uri == '' OR $request_uri == $this->config->item('index_page')) { return ''; } -- cgit v1.2.3-24-g4f1b From 30578eadecee1b7fd96e82b17100bba5347d362e Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 17 Oct 2006 02:31:06 +0000 Subject: --- system/libraries/Loader.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index b402464e2..336caf7dd 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -592,8 +592,24 @@ class CI_Loader { } 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 (ini_get("short_open_tag") == 0) + { + $file = file_get_contents($path); + + $file = str_replace('/", " ;?>", $file); + + echo eval('?>'.$file.' Date: Tue, 17 Oct 2006 02:32:59 +0000 Subject: --- system/libraries/Loader.php | 1 - 1 file changed, 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 336caf7dd..ba98a642a 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -599,7 +599,6 @@ class CI_Loader { if (ini_get("short_open_tag") == 0) { $file = file_get_contents($path); - $file = str_replace('/", " ;?>", $file); -- cgit v1.2.3-24-g4f1b From 94fe038a62c5d535920464266ae404b5e028f662 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 17 Oct 2006 02:36:31 +0000 Subject: --- system/libraries/Loader.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index ba98a642a..bc2e9dec7 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -599,8 +599,8 @@ class CI_Loader { if (ini_get("short_open_tag") == 0) { $file = file_get_contents($path); - $file = str_replace('/", " ;?>", $file); + $file = str_replace('/", ' ;?>', $file); echo eval('?>'.$file.' Date: Tue, 17 Oct 2006 03:40:51 +0000 Subject: --- system/libraries/Loader.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index bc2e9dec7..4252f1633 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -596,13 +596,10 @@ class CI_Loader { // 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 (ini_get("short_open_tag") == 0) - { - $file = file_get_contents($path); - $file = str_replace('/", ' ;?>', $file); - echo eval('?>'.$file.''.preg_replace("/;*\s*\?>/", "; ?>", str_replace(' Date: Thu, 19 Oct 2006 16:40:03 +0000 Subject: --- system/libraries/Hooks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index e2d0500c0..3c35c9088 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -39,8 +39,8 @@ class CI_Hooks { */ function CI_Hooks() { - log_message('debug', "Hooks Class Initialized"); $this->_initialize(); + log_message('debug', "Hooks Class Initialized"); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 90931313c2d8a90f84e3a62b59d9603f4ebe4127 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 20 Oct 2006 00:59:17 +0000 Subject: --- system/libraries/Router.php | 64 ++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 35 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 06037209b..94a9a5243 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -292,7 +292,7 @@ class CI_Router { // If the URL has a question mark then it's simplest to just // build the URI string from the zero index of the $_GET array. // This avoids having to deal with $_SERVER variables, which - // can be unreliable on some servers + // can be unreliable in some environments if (is_array($_GET) AND count($_GET) == 1) { return current(array_keys($_GET)); @@ -300,44 +300,38 @@ class CI_Router { // Is there a PATH_INFO variable? // Note: some servers seem to have trouble with getenv() so we'll test it two ways - $path_info = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); + $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); + if ($path != '' AND $path != "/".SELF) + { + return $path; + } + + // No PATH_INFO?... What about QUERY_STRING? + $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); + if ($path != '') + { + return $path; + } - if ($path_info != '' AND $path_info != "/".SELF) + // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists? + $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); + if ($path != '' AND $path != "/".SELF) { - return $path_info; + return $path; } - else + + // OK, how about REQUEST_URI? + // Note: REQUEST_URI is not supplied in a consistent manner with all platforms so it's + // a diffucult variable to use. We'll try to parse it out correctly. Hopfully one + // of the other variables above was available. + $path = $this->_parse_request_uri(); + if ($path != "") { - // OK, how about REQUEST_URI? - $req_uri = $this->_parse_request_uri(); - - if ($req_uri != "") - { - return $req_uri; - } - else - { - // Hm... maybe the ORIG_PATH_INFO variable exists? - $path_info = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); - if ($path_info != '' AND $path_info != "/".SELF) - { - return $path_info; - } - else - { - // At this point we've exhauseted all our options. - // Hopefully QUERY_STRING exists. If not, there's nothing else we can try. - $query_string = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); - - if ($query_string != '') - { - return $query_string; - } - - return ''; - } - } + return $path; } + + // We've exhausted all our options... + return ''; } else { @@ -373,7 +367,7 @@ class CI_Router { $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI'])); - if ($request_uri == '' OR $request_uri == $this->config->item('index_page')) + if ($request_uri == '' OR $request_uri == SELF) { return ''; } -- cgit v1.2.3-24-g4f1b From e0cd609abeaeb1be5ed0ef7ac88bb6de86627881 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 20 Oct 2006 01:00:31 +0000 Subject: --- system/libraries/Exceptions.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Exceptions.php b/system/libraries/Exceptions.php index c3af801ae..4bdbe4f83 100644 --- a/system/libraries/Exceptions.php +++ b/system/libraries/Exceptions.php @@ -117,7 +117,11 @@ class CI_Exceptions { function show_error($heading, $message, $template = 'error_general') { $message = '

'.implode('

', ( ! is_array($message)) ? array($message) : $message).'

'; - + + if (ob_get_level() > 1) + { + ob_end_flush(); + } ob_start(); include_once(APPPATH.'errors/'.$template.EXT); $buffer = ob_get_contents(); @@ -151,7 +155,11 @@ class CI_Exceptions { $x = explode('/', $filepath); $filepath = $x[count($x)-2].'/'.end($x); } - + + if (ob_get_level() > 1) + { + ob_end_flush(); + } ob_start(); include_once(APPPATH.'errors/error_php'.EXT); $buffer = ob_get_contents(); -- cgit v1.2.3-24-g4f1b From b807f32ab209a537bbb0a85d6129d495675b189f Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 20 Oct 2006 04:55:37 +0000 Subject: --- system/libraries/Loader.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 4252f1633..3b1a7f2cd 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -221,7 +221,7 @@ class CI_Loader { * 1. The name of the "view" file to be included. * 2. An associative array of data to be extracted for use in the view. * 3. TRUE/FALSE - whether to return the data or load it. In - * some cases it's advantageous to be able to retun data so that + * some cases it's advantageous to be able to return data so that * a developer can process it in some way. * * @access public @@ -257,7 +257,7 @@ class CI_Loader { /** * Set Variables * - * Once variables are set they become availabe within + * Once variables are set they become available within * the controller class and its "view" files. * * @access public @@ -525,7 +525,7 @@ class CI_Loader { */ function _ci_load($data) { - // This allows anything loaded using $this->load (viwes, files, etc.) + // 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 @@ -584,7 +584,7 @@ class CI_Loader { * need post processing? For one thing, in order to * show the elapsed page load time. Unless we * can intercept the content right before it's sent to - * the browser and then stop the timer it won't be acurate. + * the browser and then stop the timer it won't be accurate. */ if ( ! file_exists($path)) { -- cgit v1.2.3-24-g4f1b From 0625e19f3318874d6f95b546312601538edb0f14 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 20 Oct 2006 22:16:54 +0000 Subject: --- system/libraries/Benchmark.php | 1 - system/libraries/Loader.php | 50 +++++++++++++++--------------------------- 2 files changed, 18 insertions(+), 33 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index c20a54269..d4262792c 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -31,7 +31,6 @@ class CI_Benchmark { var $marker = array(); - // -------------------------------------------------------------------- /** diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 3b1a7f2cd..b313c6d5a 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -655,51 +655,37 @@ class CI_Loader { function _ci_load_class($class, $params = NULL) { // Prep the class name - $class = strtolower(str_replace(EXT, '', $class)); - - // Is this a class extension request? - if (substr($class, 0, 3) == 'my_') - { - $class = preg_replace("/my_(.+)/", "\\1", $class); + $class = ucfirst(strtolower(str_replace(EXT, '', $class))); - // Load the requested library from the main system/libraries folder - if (file_exists(BASEPATH.'libraries/'.ucfirst($class).EXT)) - { - include_once(BASEPATH.'libraries/'.ucfirst($class).EXT); - } - - // Now look for a matching library - foreach (array(ucfirst($class), $class) as $filename) + // Is this a class extension request? + if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT)) + { + if ( ! file_exists(BASEPATH.'libraries/'.$class.EXT)) { - if (file_exists(APPPATH.'libraries/'.$filename.EXT)) - { - include_once(APPPATH.'libraries/'.$filename.EXT); - } + log_message('error', "Unable to load the requested class: ".$class); + show_error("Unable to load the requested class: ".$class); } - - return $this->_ci_init_class($filename, 'MY_', $params); + + include_once(BASEPATH.'libraries/'.ucfirst($class).EXT); + include_once(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT); + + return $this->_ci_init_class($filename, config_item('subclass_prefix'), $params); } // Lets search for the requested library file and load it. - // For backward compatibility we'll test for filenames that are - // both uppercase and lower. - foreach (array(ucfirst($class), $class) as $filename) + for ($i = 1; $i < 3; $i++) { - for ($i = 1; $i < 3; $i++) + $path = ($i % 2) ? APPPATH : BASEPATH; + if (file_exists($path.'libraries/'.$filename.EXT)) { - $path = ($i % 2) ? APPPATH : BASEPATH; - - if (file_exists($path.'libraries/'.$filename.EXT)) - { - include_once($path.'libraries/'.$filename.EXT); - return $this->_ci_init_class($filename, '', $params); - } + include_once($path.'libraries/'.$filename.EXT); + return $this->_ci_init_class($filename, '', $params); } } // If we got this far we were unable to find the requested class log_message('error', "Unable to load the requested class: ".$class); - show_error("Unable to load the class: ".$class); + show_error("Unable to load the requested class: ".$class); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 570c161b4c22c1fcdc0345b0d57a9ea127db4b4a Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 20 Oct 2006 22:28:39 +0000 Subject: --- system/libraries/Loader.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index b313c6d5a..253d916c4 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -669,17 +669,17 @@ class CI_Loader { include_once(BASEPATH.'libraries/'.ucfirst($class).EXT); include_once(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT); - return $this->_ci_init_class($filename, config_item('subclass_prefix'), $params); + return $this->_ci_init_class($class, config_item('subclass_prefix'), $params); } // Lets search for the requested library file and load it. for ($i = 1; $i < 3; $i++) { $path = ($i % 2) ? APPPATH : BASEPATH; - if (file_exists($path.'libraries/'.$filename.EXT)) + if (file_exists($path.'libraries/'.$class.EXT)) { - include_once($path.'libraries/'.$filename.EXT); - return $this->_ci_init_class($filename, '', $params); + include_once($path.'libraries/'.$class.EXT); + return $this->_ci_init_class($class, '', $params); } } -- cgit v1.2.3-24-g4f1b From e7e1dcd452a15abaaa01c03cd1ade564e3a59453 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 18:04:01 +0000 Subject: --- system/libraries/Benchmark.php | 2 +- system/libraries/Controller.php | 2 +- system/libraries/Zip.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index d4262792c..5fd24b05f 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -54,7 +54,7 @@ class CI_Benchmark { * Calculates the time difference between two marked points. * * If the first parameter is empty this function instead returns the - * {elapsed_time} pseudo-variable. This permits the the full system + * {elapsed_time} pseudo-variable. This permits the full system * execution time to be shown in a template. The output class will * swap the real value for this variable. * diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 0bbc7773e..3db408bec 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -18,7 +18,7 @@ /** * Code Igniter Application Controller Class * - * This class object is the the super class the every library in + * This class object is the super class the every library in * Code Igniter will be assigned to. * * @package CodeIgniter diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index e13c713fe..6af1ca979 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -228,7 +228,7 @@ class CI_Zip { // -------------------------------------------------------------------- /** - * Write File to the specified direcotry + * Write File to the specified directory * * Lets you write a file * -- cgit v1.2.3-24-g4f1b From fafe28bec4f414e48f63e01ed9105ae5c2c99802 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 19:08:17 +0000 Subject: --- system/libraries/Calendar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 048934b82..52e99b5ad 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -250,7 +250,7 @@ class CI_Calendar { * month provided. * * @access public - * @parm integer the month + * @param integer the month * @return string */ function get_month_name($month) -- cgit v1.2.3-24-g4f1b From 1604062c207cc70eaa8f528e59756a807ba045db Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 19:09:49 +0000 Subject: --- system/libraries/Benchmark.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index 5fd24b05f..44c32a874 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -59,8 +59,8 @@ class CI_Benchmark { * swap the real value for this variable. * * @access public - * @param string a paricular marked point - * @param string a paricular marked point + * @param string a particular marked point + * @param string a particular marked point * @param integer the number of decimal places * @return mixed */ -- cgit v1.2.3-24-g4f1b From 5f95aab62d3923e05dacf65d94eeefb2283edc4d Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 19:10:51 +0000 Subject: --- system/libraries/Calendar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 52e99b5ad..ec355d24f 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -246,7 +246,7 @@ class CI_Calendar { /** * Get Month Name * - * Generates a texual month name based on the numeric + * Generates a textual month name based on the numeric * month provided. * * @access public -- cgit v1.2.3-24-g4f1b From 23db0ddcd518b8a6ab8b7688a3eab756a73463f0 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 19:16:50 +0000 Subject: --- system/libraries/Email.php | 63 +++++----------------------------------------- 1 file changed, 6 insertions(+), 57 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 23f7fe456..eb04ae9dc 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -87,7 +87,6 @@ class CI_Email { log_message('debug', "Email Class Initialized"); } - // END CI_Email() // -------------------------------------------------------------------- @@ -120,7 +119,6 @@ class CI_Email { $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; $this->_safe_mode = (@ini_get("safe_mode") == 0) ? FALSE : TRUE; } - // END initialize() // -------------------------------------------------------------------- @@ -151,7 +149,6 @@ class CI_Email { $this->_attach_disp = array(); } } - // END clear() // -------------------------------------------------------------------- @@ -179,7 +176,6 @@ class CI_Email { $this->_set_header('From', $name.' <'.$from.'>'); $this->_set_header('Return-Path', '<'.$from.'>'); } - // END from() // -------------------------------------------------------------------- @@ -212,7 +208,6 @@ class CI_Email { $this->_set_header('Reply-To', $name.' <'.$replyto.'>'); $this->_replyto_flag = TRUE; } - // END reply_to() // -------------------------------------------------------------------- @@ -244,7 +239,6 @@ class CI_Email { break; } } - // END to() // -------------------------------------------------------------------- @@ -268,7 +262,6 @@ class CI_Email { if ($this->_get_protocol() == "smtp") $this->_cc_array = $cc; } - // END cc() // -------------------------------------------------------------------- @@ -299,7 +292,6 @@ class CI_Email { else $this->_set_header('Bcc', implode(", ", $bcc)); } - // END bcc() // -------------------------------------------------------------------- @@ -317,7 +309,6 @@ class CI_Email { $this->_set_header('Subject', trim($subject)); } - // END subject() // -------------------------------------------------------------------- @@ -339,7 +330,6 @@ class CI_Email { $this->_body = stripslashes($this->_body); } - // END message() // -------------------------------------------------------------------- @@ -356,7 +346,6 @@ class CI_Email { $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename)))); $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters } - // END attach() // -------------------------------------------------------------------- @@ -372,7 +361,6 @@ class CI_Email { { $this->_headers[$header] = $value; } - // END _set_header() // -------------------------------------------------------------------- @@ -409,7 +397,6 @@ class CI_Email { } return $email; } - // END _str_to_array() // -------------------------------------------------------------------- @@ -424,7 +411,6 @@ class CI_Email { { $this->alt_message = ($str == '') ? '' : $str; } - // END set_alt_message() // -------------------------------------------------------------------- @@ -439,7 +425,6 @@ class CI_Email { { $this->mailtype = ($type == 'html') ? 'html' : 'text'; } - // END set_mailtype() // -------------------------------------------------------------------- @@ -454,12 +439,11 @@ class CI_Email { { $this->wordwrap = ($wordwrap === FALSE) ? FALSE : TRUE; } - // END set_wordwrap() // -------------------------------------------------------------------- /** - * Set Protocal + * Set Protocol * * @access public * @param string @@ -469,7 +453,6 @@ class CI_Email { { $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol); } - // END set_protocol() // -------------------------------------------------------------------- @@ -496,7 +479,6 @@ class CI_Email { $this->priority = $n; } - // END set_priority() // -------------------------------------------------------------------- @@ -517,22 +499,20 @@ class CI_Email { $this->newline = $newline; } - // END set_newline() // -------------------------------------------------------------------- /** - * Set Message Boundry + * Set Message Boundary * * @access private * @return void */ function _set_boundaries() { - $this->_alt_boundary = "B_ALT_".uniqid(''); // mulipart/alternative + $this->_alt_boundary = "B_ALT_".uniqid(''); // multipart/alternative $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary } - // END _set_boundaries() // -------------------------------------------------------------------- @@ -550,7 +530,6 @@ class CI_Email { return "<".uniqid('').strstr($from, '@').">"; } - // END _get_message_id() // -------------------------------------------------------------------- @@ -569,7 +548,6 @@ class CI_Email { if ($return == true) return $this->protocol; } - // END _get_protocol() // -------------------------------------------------------------------- @@ -590,7 +568,6 @@ class CI_Email { if ($return == true) return $this->_encoding; } - // END _get_encoding() // -------------------------------------------------------------------- @@ -613,7 +590,6 @@ class CI_Email { else return 'plain'; } - // END _get_content_type() // -------------------------------------------------------------------- @@ -632,7 +608,6 @@ class CI_Email { return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone); } - // END _set_date() // -------------------------------------------------------------------- @@ -646,7 +621,6 @@ class CI_Email { { return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format."; } - // END _get_mime_message() // -------------------------------------------------------------------- @@ -674,7 +648,6 @@ class CI_Email { } } } - // END validate_email() // -------------------------------------------------------------------- @@ -692,7 +665,6 @@ class CI_Email { else return TRUE; } - // END valid_email() // -------------------------------------------------------------------- @@ -725,7 +697,6 @@ class CI_Email { return $clean_email; } - // END clean_email() // -------------------------------------------------------------------- @@ -773,7 +744,6 @@ class CI_Email { return $this->word_wrap($body, '76'); } - // END _get_alt_message() // -------------------------------------------------------------------- @@ -846,7 +816,6 @@ class CI_Email { return $output; } - // END word_wrap() // -------------------------------------------------------------------- @@ -865,7 +834,6 @@ class CI_Email { $this->_set_header('Message-ID', $this->_get_message_id()); $this->_set_header('Mime-Version', '1.0'); } - // END _build_headers() // -------------------------------------------------------------------- @@ -899,7 +867,6 @@ class CI_Email { if ($this->_get_protocol() == 'mail') $this->_header_str = substr($this->_header_str, 0, -1); } - // END _write_headers() // -------------------------------------------------------------------- @@ -1062,7 +1029,6 @@ class CI_Email { return; } - // END _build_message() // -------------------------------------------------------------------- @@ -1102,12 +1068,11 @@ class CI_Email { else return TRUE; } - // END send() // -------------------------------------------------------------------- /** - * Batch Bcc Send. Sends groups of Bccs in batches + * Batch Bcc Send. Sends groups of BCCs in batches * * @access public * @return bool @@ -1154,7 +1119,6 @@ class CI_Email { $this->_spool_email(); } } - // END batch_bcc_send() // -------------------------------------------------------------------- @@ -1168,7 +1132,6 @@ class CI_Email { { $this->_finalbody = preg_replace_callback("/\{unwrap\}(.*?)\{\/unwrap\}/si", array($this, '_remove_nl_callback'), $this->_finalbody); } - // END _unwrap_specials() // -------------------------------------------------------------------- @@ -1182,7 +1145,6 @@ class CI_Email { { return preg_replace("/(\r\n)|(\r)|(\n)/", "", $matches['1']); } - // END _remove_nl_callback() // -------------------------------------------------------------------- @@ -1190,7 +1152,7 @@ class CI_Email { * Spool mail to the mail server * * @access private - * @return bol + * @return bool */ function _spool_email() { @@ -1228,7 +1190,6 @@ class CI_Email { $this->_set_error_message('email_sent', $this->_get_protocol()); return true; } - // END _spool_email() // -------------------------------------------------------------------- @@ -1255,7 +1216,6 @@ class CI_Email { return TRUE; } } - // END _send_with_mail() // -------------------------------------------------------------------- @@ -1281,7 +1241,6 @@ class CI_Email { return TRUE; } - // END _send_with_sendmail() // -------------------------------------------------------------------- @@ -1344,7 +1303,6 @@ class CI_Email { $this->_send_command('quit'); return true; } - // END _send_with_smtp() // -------------------------------------------------------------------- @@ -1373,7 +1331,6 @@ class CI_Email { $this->_set_error_message($this->_get_smtp_data()); return $this->_send_command('hello'); } - // END _smtp_connect() // -------------------------------------------------------------------- @@ -1439,7 +1396,6 @@ class CI_Email { return true; } - // END _send_command() // -------------------------------------------------------------------- @@ -1492,7 +1448,6 @@ class CI_Email { return true; } - // END _smtp_authenticate() // -------------------------------------------------------------------- @@ -1512,7 +1467,6 @@ class CI_Email { else return true; } - // END _send_data() // -------------------------------------------------------------------- @@ -1536,7 +1490,6 @@ class CI_Email { return $data; } - // END _get_smtp_data() // -------------------------------------------------------------------- @@ -1550,7 +1503,6 @@ class CI_Email { { return (isset($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain'; } - // END _get_hostname() // -------------------------------------------------------------------- @@ -1591,12 +1543,11 @@ class CI_Email { return $this->_IP; } - // END _get_ip() // -------------------------------------------------------------------- /** - * Get Debugg Message + * Get Debug Message * * @access public * @return string @@ -1641,7 +1592,6 @@ class CI_Email { $this->_debug_msg[] = str_replace('%s', $val, $line)."
"; } } - // END _set_error_message() // -------------------------------------------------------------------- @@ -1745,7 +1695,6 @@ class CI_Email { return ( ! isset($mimes[strtolower($ext)])) ? "application/x-unknown-content-type" : $mimes[strtolower($ext)]; } - // END _mime_types() } // END CI_Email class -- cgit v1.2.3-24-g4f1b From bd6bee75dd26ade1c8d9cfd104bb913065797c59 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 19:39:00 +0000 Subject: --- system/libraries/Config.php | 14 ++------------ system/libraries/Exceptions.php | 11 +++-------- system/libraries/Hooks.php | 3 --- system/libraries/Image_lib.php | 36 ++++++------------------------------ system/libraries/Input.php | 12 ++++++------ system/libraries/Language.php | 3 --- system/libraries/Loader.php | 4 ++-- system/libraries/Pagination.php | 2 +- system/libraries/Parser.php | 5 ----- system/libraries/Profiler.php | 2 +- system/libraries/Router.php | 8 ++++---- system/libraries/Session.php | 4 +--- system/libraries/Sha1.php | 5 ----- system/libraries/Table.php | 2 +- system/libraries/Trackback.php | 19 +++---------------- system/libraries/Unit_test.php | 2 +- system/libraries/Upload.php | 4 ++-- 17 files changed, 33 insertions(+), 103 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Config.php b/system/libraries/Config.php index 82836b1f3..ef6d46a25 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -46,9 +46,7 @@ class CI_Config { { $this->config = get_config(); log_message('debug', "Config Class Initialized"); - } - // END CI_Config() - + } // -------------------------------------------------------------------- @@ -110,7 +108,6 @@ class CI_Config { log_message('debug', 'Config file loaded: config/'.$file.EXT); return TRUE; } - // END load() // -------------------------------------------------------------------- @@ -152,7 +149,6 @@ class CI_Config { return $pref; } - // END item() // -------------------------------------------------------------------- @@ -186,9 +182,6 @@ class CI_Config { return $pref; } - // END item() - - // -------------------------------------------------------------------- @@ -216,8 +209,7 @@ class CI_Config { return $this->slash_item('base_url').$this->slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix; } } - // END site_url() - + // -------------------------------------------------------------------- /** @@ -231,7 +223,6 @@ class CI_Config { $x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH)); return $this->slash_item('base_url').end($x).'/'; } - // END system_url() // -------------------------------------------------------------------- @@ -247,7 +238,6 @@ class CI_Config { { $this->config[$item] = $value; } - // END set_item() } diff --git a/system/libraries/Exceptions.php b/system/libraries/Exceptions.php index 4bdbe4f83..a0591e4e5 100644 --- a/system/libraries/Exceptions.php +++ b/system/libraries/Exceptions.php @@ -55,7 +55,6 @@ class CI_Exceptions { { // Note: Do not log messages from this constructor. } - // END CI_Exceptions() // -------------------------------------------------------------------- @@ -77,7 +76,6 @@ class CI_Exceptions { log_message('error', 'Severity: '.$severity.' '.$severity.' --> '.$message. ' '.$filepath.' '.$line, TRUE); } - // END log_exception() // -------------------------------------------------------------------- @@ -97,7 +95,6 @@ class CI_Exceptions { echo $this->show_error($heading, $message, 'error_404'); exit; } - // END show_404() // -------------------------------------------------------------------- @@ -105,7 +102,7 @@ class CI_Exceptions { * General Error Page * * This function takes an error message as input - * (either as a string or an array) and displayes + * (either as a string or an array) and displays * it using the specified template. * * @access private @@ -128,8 +125,6 @@ class CI_Exceptions { ob_end_clean(); return $buffer; } - // END show_error() - // -------------------------------------------------------------------- @@ -166,8 +161,8 @@ class CI_Exceptions { ob_end_clean(); echo $buffer; } - // END show_php_error() -// END Exceptions Class + } +// END Exceptions Class ?> \ No newline at end of file diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index 3c35c9088..6f48723f6 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -109,7 +109,6 @@ class CI_Hooks { return TRUE; } - // END hook_exists() // -------------------------------------------------------------------- @@ -218,8 +217,6 @@ class CI_Hooks { $this->in_progress = FALSE; return TRUE; } - // END _run_hook() - } diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 16583c063..f8c05f834 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -92,7 +92,6 @@ class CI_Image_lib { log_message('debug', "Image Lib Class Initialized"); } - // END CI_Image_lib() // -------------------------------------------------------------------- @@ -113,7 +112,6 @@ class CI_Image_lib { $this->$val = ''; } } - // END clear() // -------------------------------------------------------------------- @@ -186,7 +184,7 @@ class CI_Image_lib { $this->source_image = end($x); $this->source_folder = str_replace($this->source_image, '', $full_source_path); - // Set the Image Propterties + // Set the Image Properties if ( ! $this->get_image_properties($this->source_folder.$this->source_image)) { return FALSE; @@ -333,7 +331,6 @@ class CI_Image_lib { return TRUE; } - // END initialize() // -------------------------------------------------------------------- @@ -357,7 +354,6 @@ class CI_Image_lib { return $this->$protocol('resize'); } - // END resize() // -------------------------------------------------------------------- @@ -381,7 +377,6 @@ class CI_Image_lib { return $this->$protocol('crop'); } - // END crop() // -------------------------------------------------------------------- @@ -435,7 +430,6 @@ class CI_Image_lib { return $this->image_rotate_gd(); } } - // END rotate() // -------------------------------------------------------------------- @@ -540,7 +534,6 @@ class CI_Image_lib { return TRUE; } - // END image_process_gd() // -------------------------------------------------------------------- @@ -611,7 +604,6 @@ class CI_Image_lib { return TRUE; } - // END image_process_imagemagick() // -------------------------------------------------------------------- @@ -698,7 +690,6 @@ class CI_Image_lib { return TRUE; } - // END image_process_netpbm() // -------------------------------------------------------------------- @@ -758,7 +749,6 @@ class CI_Image_lib { return true; } - // END image_rotate_gd() // -------------------------------------------------------------------- @@ -843,7 +833,6 @@ class CI_Image_lib { return TRUE; } - // END image_mirror_gd() // -------------------------------------------------------------------- @@ -868,7 +857,6 @@ class CI_Image_lib { return $this->text_watermark(); } } - // END image_mirror_gd() // -------------------------------------------------------------------- @@ -969,7 +957,6 @@ class CI_Image_lib { return TRUE; } - // END overlay_watermark() // -------------------------------------------------------------------- @@ -1110,7 +1097,6 @@ class CI_Image_lib { return TRUE; } - // END text_watermark() // -------------------------------------------------------------------- @@ -1168,12 +1154,11 @@ class CI_Image_lib { $this->set_error(array('imglib_unsupported_imagecreate')); return FALSE; } - // END image_create_gd() // -------------------------------------------------------------------- /** - * Write imge file to disk - GD + * Write image file to disk - GD * * Takes an image resource as input and writes the file * to the specified destination @@ -1226,12 +1211,11 @@ class CI_Image_lib { return TRUE; } - // END image_save_gd() // -------------------------------------------------------------------- /** - * Dynamically ouputs an image + * Dynamically outputs an image * * @access public * @param resource @@ -1256,18 +1240,17 @@ class CI_Image_lib { break; } } - // END image_display_gd() // -------------------------------------------------------------------- /** - * Reproportion Image Width/Height + * Re-proportion Image Width/Height * * When creating thumbs, the desired width/height * can end up warping the image due to an incorrect * ratio between the full-sized image and the thumb. * - * This function lets us reproportion the width/height + * This function lets us re-proportion the width/height * if users choose to maintain the aspect ratio when resizing. * * @access public @@ -1303,7 +1286,6 @@ class CI_Image_lib { } } } - // END image_reproportion() // -------------------------------------------------------------------- @@ -1355,7 +1337,6 @@ class CI_Image_lib { return TRUE; } - // END get_image_properties() // -------------------------------------------------------------------- @@ -1406,7 +1387,6 @@ class CI_Image_lib { return $vals; } - // END size_calculator() // -------------------------------------------------------------------- @@ -1447,7 +1427,6 @@ class CI_Image_lib { return $ret; } - // END explode_name() // -------------------------------------------------------------------- @@ -1469,7 +1448,6 @@ class CI_Image_lib { return TRUE; } - // END gd_loaded() // -------------------------------------------------------------------- @@ -1491,7 +1469,6 @@ class CI_Image_lib { return FALSE; } - // END gd_version() // -------------------------------------------------------------------- @@ -1524,7 +1501,6 @@ class CI_Image_lib { log_message('error', $msg); } } - // END set_error() // -------------------------------------------------------------------- @@ -1545,7 +1521,7 @@ class CI_Image_lib { return $str; } - // END display_errors() + } // END Image_lib Class ?> \ No newline at end of file diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 72344e343..57696c8a2 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -55,7 +55,7 @@ class CI_Input { /** * Sanitize Globals * - * This function does the folowing: + * This function does the following: * * Unsets $_GET data (if query strings are not enabled) * @@ -114,7 +114,7 @@ class CI_Input { // -------------------------------------------------------------------- /** - * Clean Intput Data + * Clean Input Data * * This is a helper function. It escapes data and * standardizes newline characters to \n @@ -399,7 +399,7 @@ class CI_Input { $str = preg_replace('/(\\\\0)+/', '', $str); /* - * Validate standard character entites + * Validate standard character entities * * Add a semicolon if missing. We do this to enable * the conversion of entities to ASCII later. @@ -408,7 +408,7 @@ class CI_Input { $str = preg_replace('#(&\#*\w+)[\x00-\x20]+;#u',"\\1;",$str); /* - * Validate UTF16 two byte encodeing (x00) + * Validate UTF16 two byte encoding (x00) * * Just as above, adds a semicolon if missing. * @@ -501,7 +501,7 @@ class CI_Input { * * Note: This code is a little blunt. It removes * the event handler and anything up to the closing >, - * but it's unlkely to be a problem. + * but it's unlikely to be a problem. * */ $str = preg_replace('#(<[^>]+.*?)(onblur|onchange|onclick|onfocus|onload|onmouseover|onmouseup|onmousedown|onselect|onsubmit|onunload|onkeypress|onkeydown|onkeyup|onresize)[^>]*>#iU',"\\1>",$str); @@ -525,7 +525,7 @@ class CI_Input { * tags it looks for PHP and JavaScript commands * that are disallowed. Rather than removing the * code, it simply converts the parenthesis to entities - * rendering the code unexecutable. + * rendering the code un-executable. * * For example: eval('some code') * Becomes: eval('some code') diff --git a/system/libraries/Language.php b/system/libraries/Language.php index 00e2fb7e8..825080745 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -38,7 +38,6 @@ class CI_Language { { log_message('debug', "Language Class Initialized"); } - // END CI_Language() // -------------------------------------------------------------------- @@ -103,7 +102,6 @@ class CI_Language { log_message('debug', 'Language file loaded: language/'.$idiom.'/'.$langfile); return TRUE; } - // END load() // -------------------------------------------------------------------- @@ -118,7 +116,6 @@ class CI_Language { { return ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line]; } - // END line() } // END Language Class diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 253d916c4..849ee731a 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -820,7 +820,7 @@ class CI_Loader { * Assign to Models * * Makes sure that anything loaded by the loader class (libraries, plugins, etc.) - * will be available to modles, if any exist. + * will be available to models, if any exist. * * @access private * @param object @@ -855,7 +855,7 @@ class CI_Loader { /** * Object to Array * - * Takes an object as input and convers the class variables to array key/vals + * Takes an object as input and converts the class variables to array key/vals * * @access private * @param object diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index b29571eee..26fb93ee4 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -199,7 +199,7 @@ class CI_Pagination { } // Kill double slashes. Note: Sometimes we can end up with a double slash - // in the penultimate link so we'll kill all double shashes. + // in the penultimate link so we'll kill all double slashes. $output = preg_replace("#([^:])//+#", "\\1/", $output); // Add the wrapper HTML if exists diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index a0c9dab9e..ebf7644ac 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -71,7 +71,6 @@ class CI_Parser { return $template; } - // END set_method() // -------------------------------------------------------------------- @@ -88,7 +87,6 @@ class CI_Parser { $this->l_delim = $l; $this->r_delim = $r; } - // END set_method() // -------------------------------------------------------------------- @@ -105,7 +103,6 @@ class CI_Parser { { return str_replace($this->l_delim.$key.$this->r_delim, $val, $string); } - // END set_method() // -------------------------------------------------------------------- @@ -148,7 +145,6 @@ class CI_Parser { return str_replace($match['0'], $str, $string); } - // END set_method() // -------------------------------------------------------------------- @@ -169,7 +165,6 @@ class CI_Parser { return $match; } - // END _match_pair() } // END Parser Class diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 7fecabd21..6e6fb675f 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -46,7 +46,7 @@ class CI_Profiler { * Auto Profiler * * This function cycles through the entire array of mark points and - * matches any two points that are named identially (ending in "_start" + * matches any two points that are named identically (ending in "_start" * and "_end" respectively). It then compiles the execution times for * all points and returns it as an array * diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 94a9a5243..6002027d6 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -58,7 +58,7 @@ class CI_Router { /** * Set the route mapping * - * This function determies what should be served based on the URI request, + * This function determines what should be served based on the URI request, * as well as any "routes" that have been set in the routing config file. * * @access private @@ -322,7 +322,7 @@ class CI_Router { // OK, how about REQUEST_URI? // Note: REQUEST_URI is not supplied in a consistent manner with all platforms so it's - // a diffucult variable to use. We'll try to parse it out correctly. Hopfully one + // a difficult variable to use. We'll try to parse it out correctly. Hopefully one // of the other variables above was available. $path = $this->_parse_request_uri(); if ($path != "") @@ -452,10 +452,10 @@ class CI_Router { return; } - // Loop through the route array looking for wildcards + // Loop through the route array looking for wild-cards foreach (array_slice($this->routes, 1) as $key => $val) { - // Convert wildcards to RegEx + // Convert wild-cards to RegEx $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); // Does the RegEx match? diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 8390fd6d4..a47599d12 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -35,8 +35,7 @@ class CI_Session { var $sess_cookie = 'ci_session'; var $userdata = array(); var $gc_probability = 5; - - + /** * Session Constructor @@ -51,7 +50,6 @@ class CI_Session { log_message('debug', "Session Class Initialized"); $this->sess_run(); } - // END display_errors() // -------------------------------------------------------------------- diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index 13196eb69..971c091ad 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -117,7 +117,6 @@ class CI_SHA { return $this->_hex($a).$this->_hex($b).$this->_hex($c).$this->_hex($d).$this->_hex($e); } - // END generate() // -------------------------------------------------------------------- @@ -139,7 +138,6 @@ class CI_SHA { return $str; } - // END _hex() // -------------------------------------------------------------------- @@ -160,7 +158,6 @@ class CI_SHA { return $b ^ $c ^ $d; } - // END _ft() // -------------------------------------------------------------------- @@ -189,7 +186,6 @@ class CI_SHA { return -899497514; } } - // END _kt() // -------------------------------------------------------------------- @@ -206,7 +202,6 @@ class CI_SHA { return ($msw << 16) | ($lsw & 0xFFFF); } - // END _safe_add() // -------------------------------------------------------------------- diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 758676e27..c40c85e17 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -123,7 +123,7 @@ class CI_Table { return 'Undefined table data'; } - // Compile and validate the templata date + // Compile and validate the template date $this->_compile_template(); diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index 8b6cce16d..74649151d 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -120,8 +120,7 @@ class CI_Trackback { } return $return; - } - // END send() + } // -------------------------------------------------------------------- @@ -165,14 +164,13 @@ class CI_Trackback { return TRUE; } - // END receive() // -------------------------------------------------------------------- /** * Send Trackback Error Message * - * Allows custom errros to be set. By default it + * Allows custom errors to be set. By default it * sends the "incomplete information" error, as that's * the most common one. * @@ -185,7 +183,6 @@ class CI_Trackback { echo "\n\n1\n".$message."\n"; exit; } - // END send_error() // -------------------------------------------------------------------- @@ -203,7 +200,6 @@ class CI_Trackback { echo "\n\n0\n"; exit; } - // END send_success() // -------------------------------------------------------------------- @@ -218,7 +214,6 @@ class CI_Trackback { { return ( ! isset($this->data[$item])) ? '' : $this->data[$item]; } - // END data() // -------------------------------------------------------------------- @@ -287,7 +282,6 @@ class CI_Trackback { return TRUE; } - // END process() // -------------------------------------------------------------------- @@ -326,7 +320,6 @@ class CI_Trackback { return $urls; } - // END extract_urls() // -------------------------------------------------------------------- @@ -348,7 +341,6 @@ class CI_Trackback { $url = "http://".$url; } } - // END validate_url() // -------------------------------------------------------------------- @@ -401,7 +393,6 @@ class CI_Trackback { return $tb_id; } } - // END get_id() // -------------------------------------------------------------------- @@ -428,7 +419,6 @@ class CI_Trackback { return $str; } - // END get_id() // -------------------------------------------------------------------- @@ -467,7 +457,6 @@ class CI_Trackback { } } } - // END get_id() // -------------------------------------------------------------------- @@ -517,7 +506,6 @@ class CI_Trackback { return $out; } - // END convert_ascii() // -------------------------------------------------------------------- @@ -533,7 +521,6 @@ class CI_Trackback { log_message('error', $msg); $this->error_msg[] = $msg; } - // END convert_ascii() // -------------------------------------------------------------------- @@ -555,7 +542,7 @@ class CI_Trackback { return $str; } - // END display_errors() + } // END Trackback Class ?> \ No newline at end of file diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 415162388..6bfc59dc3 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -220,7 +220,7 @@ class CI_Unit_test { * This lets us set the template to be used to display results * * @access public - * @params string + * @param string * @return void */ function set_template($template) diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 5bb506cdb..09a479431 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -284,8 +284,8 @@ class CI_Upload { * Set the file name * * This function takes a filename/path as input and looks for the - * existnace of a file with the same name. If found, it will append a - * number to the end of the filename to avoid overwritting a pre-existing file. + * existence of a file with the same name. If found, it will append a + * number to the end of the filename to avoid overwriting a pre-existing file. * * @access public * @param string -- cgit v1.2.3-24-g4f1b From e334c472fb4be44feec3a73402fc4a2b062cbfc0 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 19:44:22 +0000 Subject: --- system/libraries/Benchmark.php | 62 +++--- system/libraries/Calendar.php | 132 ++++++------- system/libraries/Config.php | 32 +-- system/libraries/Controller.php | 30 +-- system/libraries/Email.php | 127 ++++++------ system/libraries/Encrypt.php | 32 +-- system/libraries/Exceptions.php | 14 +- system/libraries/Hooks.php | 12 +- system/libraries/Image_lib.php | 136 ++++++------- system/libraries/Input.php | 38 ++-- system/libraries/Language.php | 10 +- system/libraries/Loader.php | 34 ++-- system/libraries/Log.php | 8 +- system/libraries/Model.php | 6 +- system/libraries/Output.php | 48 ++--- system/libraries/Pagination.php | 122 ++++++------ system/libraries/Parser.php | 6 +- system/libraries/Profiler.php | 4 +- system/libraries/Router.php | 24 +-- system/libraries/Session.php | 102 +++++----- system/libraries/Sha1.php | 292 ++++++++++++++-------------- system/libraries/Table.php | 6 +- system/libraries/Trackback.php | 54 +++--- system/libraries/URI.php | 18 +- system/libraries/Unit_test.php | 16 +- system/libraries/Upload.php | 418 ++++++++++++++++++++-------------------- system/libraries/User_agent.php | 20 +- system/libraries/Validation.php | 52 ++--- system/libraries/Xmlrpc.php | 152 +++++++-------- system/libraries/Xmlrpcs.php | 50 ++--- system/libraries/Zip.php | 46 ++--- 31 files changed, 1051 insertions(+), 1052 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index 44c32a874..66e8a24cf 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -43,18 +43,18 @@ class CI_Benchmark { * @param string $name name of the marker * @return void */ - function mark($name) - { - $this->marker[$name] = microtime(); - } + function mark($name) + { + $this->marker[$name] = microtime(); + } // -------------------------------------------------------------------- /** * Calculates the time difference between two marked points. * - * If the first parameter is empty this function instead returns the - * {elapsed_time} pseudo-variable. This permits the full system + * If the first parameter is empty this function instead returns the + * {elapsed_time} pseudo-variable. This permits the full system * execution time to be shown in a template. The output class will * swap the real value for this variable. * @@ -64,28 +64,28 @@ class CI_Benchmark { * @param integer the number of decimal places * @return mixed */ - function elapsed_time($point1 = '', $point2 = '', $decimals = 4) - { - if ($point1 == '') - { + function elapsed_time($point1 = '', $point2 = '', $decimals = 4) + { + if ($point1 == '') + { return '{elapsed_time}'; - } - - if ( ! isset($this->marker[$point1])) - { - return ''; - } - - if ( ! isset($this->marker[$point2])) - { - $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); - } + } + + if ( ! isset($this->marker[$point1])) + { + return ''; + } + + if ( ! isset($this->marker[$point2])) + { + $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); + } // -------------------------------------------------------------------- @@ -93,8 +93,8 @@ class CI_Benchmark { * Memory Usage * * This function returns the {memory_usage} pseudo-variable. - * This permits it to be put it anywhere in a template - * without the memory being calculated until the end. + * This permits it to be put it anywhere in a template + * without the memory being calculated until the end. * The output class will swap the real value for this variable. * * @access public diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index ec355d24f..84b096c8b 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -7,25 +7,25 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** * Code Igniter Calendar Class * - * This class enables the creation of calendars + * This class enables the creation of calendars * * @package CodeIgniter * @subpackage Libraries * @category Libraries * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/libraries/calendar.html - */ + */ class CI_Calendar { var $CI; @@ -78,7 +78,7 @@ class CI_Calendar { $this->$key = $val; } } - } + } // -------------------------------------------------------------------- @@ -91,13 +91,13 @@ class CI_Calendar { * @param array the data to be shown in the calendar cells * @return string */ - function generate($year = '', $month = '', $data = array()) - { + function generate($year = '', $month = '', $data = array()) + { // Set and validate the supplied month/year - if ($year == '') - $year = date("Y", $this->local_time); - - if ($month == '') + if ($year == '') + $year = date("Y", $this->local_time); + + if ($month == '') $month = date("m", $this->local_time); if (strlen($year) == 1) @@ -112,10 +112,10 @@ class CI_Calendar { $adjusted_date = $this->adjust_date($month, $year); $month = $adjusted_date['month']; - $year = $adjusted_date['year']; + $year = $adjusted_date['year']; // Determine the total days in the month - $total_days = $this->get_total_days($month, $year); + $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); @@ -194,7 +194,7 @@ class CI_Calendar { $out .= $this->temp['week_row_end']; $out .= "\n"; - // Build the main body of the calendar + // Build the main body of the calendar while ($day <= $total_days) { $out .= "\n"; @@ -202,7 +202,7 @@ class CI_Calendar { $out .= "\n"; 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) @@ -226,27 +226,27 @@ class CI_Calendar { $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']; - $day++; + $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; - } + } // -------------------------------------------------------------------- /** * Get Month Name * - * Generates a textual month name based on the numeric + * Generates a textual month name based on the numeric * month provided. * * @access public @@ -275,12 +275,12 @@ class CI_Calendar { } // -------------------------------------------------------------------- - + /** * Get Day Names * * Returns an array of day names (Sunday, Monday, etc.) based - * on the type. Options: long, short, abrev + * on the type. Options: long, short, abrev * * @access public * @param string @@ -327,32 +327,32 @@ class CI_Calendar { * @param integer the year * @return array */ - function adjust_date($month, $year) - { - $date = array(); - - $date['month'] = $month; - $date['year'] = $year; - - while ($date['month'] > 12) - { - $date['month'] -= 12; - $date['year']++; - } - - while ($date['month'] <= 0) - { - $date['month'] += 12; - $date['year']--; - } - - if (strlen($date['month']) == 1) - { - $date['month'] = '0'.$date['month']; - } - - return $date; - } + function adjust_date($month, $year) + { + $date = array(); + + $date['month'] = $month; + $date['year'] = $year; + + while ($date['month'] > 12) + { + $date['month'] -= 12; + $date['year']++; + } + + while ($date['month'] <= 0) + { + $date['month'] += 12; + $date['year']--; + } + + if (strlen($date['month']) == 1) + { + $date['month'] = '0'.$date['month']; + } + + return $date; + } // -------------------------------------------------------------------- @@ -364,26 +364,26 @@ class CI_Calendar { * @param integer the year * @return integer */ - function get_total_days($month, $year) - { - $days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); - - if ($month < 1 OR $month > 12) - { - return 0; - } - - // Is the year a leap year? - if ($month == 2) - { + function get_total_days($month, $year) + { + $days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); + + if ($month < 1 OR $month > 12) + { + return 0; + } + + // Is the year a leap year? + if ($month == 2) + { if ($year % 400 == 0 OR ($year % 4 == 0 AND $year % 100 != 0)) { return 29; } - } - - return $days_in_month[$month - 1]; - } + } + + return $days_in_month[$month - 1]; + } // -------------------------------------------------------------------- diff --git a/system/libraries/Config.php b/system/libraries/Config.php index ef6d46a25..aa26c9203 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -36,12 +36,12 @@ class CI_Config { * * Sets the $config data from the primary config.php file as a class variable * - * @access public - * @param string the config file name - * @param boolean if configuration values should be loaded into their own section - * @param boolean true if errors should just return false, false if an error message should be displayed - * @return boolean if the file was successfully loaded or not - */ + * @access public + * @param string the config file name + * @param boolean if configuration values should be loaded into their own section + * @param boolean true if errors should just return false, false if an error message should be displayed + * @return boolean if the file was successfully loaded or not + */ function CI_Config() { $this->config = get_config(); @@ -62,7 +62,7 @@ class CI_Config { $file = ($file == '') ? 'config' : str_replace(EXT, '', $file); if (in_array($file, $this->is_loaded, TRUE)) - { + { return TRUE; } @@ -125,7 +125,7 @@ class CI_Config { { if ($index == '') { - if ( ! isset($this->config[$item])) + if ( ! isset($this->config[$item])) { return FALSE; } @@ -134,7 +134,7 @@ class CI_Config { } else { - if ( ! isset($this->config[$index])) + if ( ! isset($this->config[$index])) { return FALSE; } @@ -147,7 +147,7 @@ class CI_Config { $pref = $this->config[$index][$item]; } - return $pref; + return $pref; } // -------------------------------------------------------------------- @@ -165,7 +165,7 @@ class CI_Config { */ function slash_item($item) { - if ( ! isset($this->config[$item])) + if ( ! isset($this->config[$item])) { return FALSE; } @@ -179,8 +179,8 @@ class CI_Config { $pref .= '/'; } } - - return $pref; + + return $pref; } // -------------------------------------------------------------------- @@ -195,7 +195,7 @@ class CI_Config { function site_url($uri = '') { if (is_array($uri)) - { + { $uri = implode('/', $uri); } diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 3db408bec..b1feee86c 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -7,18 +7,18 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** * Code Igniter Application Controller Class * - * This class object is the super class the every library in + * This class object is the super class the every library in * Code Igniter will be assigned to. * * @package CodeIgniter @@ -45,7 +45,7 @@ class Controller extends CI_Base { $this->_ci_initialize(); log_message('debug', "Controller Class Initialized"); } - + // -------------------------------------------------------------------- /** @@ -56,17 +56,17 @@ class Controller extends CI_Base { * * @access private * @return void - */ + */ function _ci_initialize() { // Assign all the class objects that were instantiated by the - // front controller to local class variables so that CI can be + // front controller to local class variables so that CI can be // run as one big super object. $classes = array( - 'config' => 'Config', - 'input' => 'Input', - 'benchmark' => 'Benchmark', - 'uri' => 'URI', + 'config' => 'Config', + 'input' => 'Input', + 'benchmark' => 'Benchmark', + 'uri' => 'URI', 'output' => 'Output', 'lang' => 'Language' ); @@ -76,7 +76,7 @@ class Controller extends CI_Base { $this->$var =& load_class($class); } - // In PHP 5 the Controller class is run as a discreet + // In PHP 5 the Controller class is run as a discreet // class. In PHP 4 it extends the Controller if (floor(phpversion()) >= 5) { @@ -97,8 +97,8 @@ class Controller extends CI_Base { * @access private * @return void */ - function _ci_scaffolding() - { + function _ci_scaffolding() + { if ($this->_ci_scaffolding === FALSE OR $this->_ci_scaff_table === FALSE) { show_404('Scaffolding unavailable'); @@ -109,8 +109,8 @@ class Controller extends CI_Base { require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); $scaff = new Scaffolding($this->_ci_scaff_table); $scaff->$method(); - } - + } + } // END _Controller class diff --git a/system/libraries/Email.php b/system/libraries/Email.php index eb04ae9dc..92f2e73fa 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -87,7 +87,7 @@ class CI_Email { log_message('debug', "Email Class Initialized"); } - + // -------------------------------------------------------------------- /** @@ -116,7 +116,7 @@ class CI_Email { } } } - $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; + $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; $this->_safe_mode = (@ini_get("safe_mode") == 0) ? FALSE : TRUE; } @@ -142,12 +142,12 @@ class CI_Email { $this->_set_header('User-Agent', $this->useragent); $this->_set_header('Date', $this->_set_date()); - if ($clear_attachments !== FALSE) - { - $this->_attach_name = array(); - $this->_attach_type = array(); - $this->_attach_disp = array(); - } + if ($clear_attachments !== FALSE) + { + $this->_attach_name = array(); + $this->_attach_type = array(); + $this->_attach_disp = array(); + } } // -------------------------------------------------------------------- @@ -344,9 +344,9 @@ class CI_Email { { $this->_attach_name[] = $filename; $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename)))); - $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters + $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters } - + // -------------------------------------------------------------------- /** @@ -450,7 +450,7 @@ class CI_Email { * @return void */ function set_protocol($protocol = 'mail') - { + { $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol); } @@ -528,7 +528,7 @@ class CI_Email { $from = str_replace(">", "", $from); $from = str_replace("<", "", $from); - return "<".uniqid('').strstr($from, '@').">"; + return "<".uniqid('').strstr($from, '@').">"; } // -------------------------------------------------------------------- @@ -545,7 +545,7 @@ class CI_Email { $this->protocol = strtolower($this->protocol); $this->protocol = ( ! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol; - if ($return == true) + if ($return == true) return $this->protocol; } @@ -562,13 +562,13 @@ class CI_Email { { $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '7bit' : $this->_encoding; - if ( ! in_array($this->charset, $this->_base_charsets, TRUE)) + if ( ! in_array($this->charset, $this->_base_charsets, TRUE)) $this->_encoding = "8bit"; - if ($return == true) + if ($return == true) return $this->_encoding; } - + // -------------------------------------------------------------------- /** @@ -641,7 +641,7 @@ class CI_Email { foreach ($email as $val) { - if ( ! $this->valid_email($val)) + if ( ! $this->valid_email($val)) { $this->_set_error_message('email_invalid_address', $val); return FALSE; @@ -662,7 +662,7 @@ class CI_Email { { if ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) return FALSE; - else + else return TRUE; } @@ -680,19 +680,19 @@ class CI_Email { if ( ! is_array($email)) { if (preg_match('/\<(.*)\>/', $email, $match)) - return $match['1']; - else - return $email; + return $match['1']; + else + return $email; } $clean_email = array(); - for ($i=0; $i < count($email); $i++) + for ($i=0; $i < count($email); $i++) { if (preg_match( '/\<(.*)\>/', $email[$i], $match)) - $clean_email[] = $match['1']; - else - $clean_email[] = $email[$i]; + $clean_email[] = $match['1']; + else + $clean_email[] = $email[$i]; } return $clean_email; @@ -705,7 +705,7 @@ class CI_Email { * * This function provides the raw message for use * in plain-text headers of HTML-formatted emails. - * If the user hasn't specified his own alternative message + * If the user hasn't specified his own alternative message * it creates one by stripping the HTML * * @access private @@ -764,7 +764,7 @@ class CI_Email { $output = ""; - while (list(, $thisline) = each($lines)) + while (list(, $thisline) = each($lines)) { if (strlen($thisline) > $chars) { @@ -772,9 +772,9 @@ class CI_Email { $words = split(" ", $thisline); - while(list(, $thisword) = each($words)) + while(list(, $thisword) = each($words)) { - while((strlen($thisword)) > $chars) + while((strlen($thisword)) > $chars) { if (stristr($thisword, '{unwrap}') !== FALSE OR stristr($thisword, '{/unwrap}') !== FALSE) { @@ -794,21 +794,21 @@ class CI_Email { $thisword = substr($thisword, $cur_pos, (strlen($thisword) - $cur_pos)); } - if ((strlen($line) + strlen($thisword)) > $chars) + if ((strlen($line) + strlen($thisword)) > $chars) { $output .= $line."\n"; $line = $thisword." "; - } - else + } + else { $line .= $thisword." "; } } $output .= $line."\n"; - } - else + } + else { $output .= $thisline."\n"; } @@ -854,7 +854,7 @@ class CI_Email { reset($this->_headers); $this->_header_str = ""; - foreach($this->_headers as $key => $val) + foreach($this->_headers as $key => $val) { $val = trim($val); @@ -972,7 +972,7 @@ class CI_Email { { $this->_header_str .= $hdr; - $body = $this->_body . $this->newline . $this->newline; + $body = $this->_body . $this->newline . $this->newline; $body .= "--" . $this->_alt_boundary . "--" . $this->newline . $this->newline; } @@ -995,7 +995,7 @@ class CI_Email { if ( ! file_exists($filename)) { - $this->_set_error_message('email_attachment_missing', $filename); + $this->_set_error_message('email_attachment_missing', $filename); return FALSE; } @@ -1010,7 +1010,7 @@ class CI_Email { if ( ! $fp = fopen($filename, 'r')) { - $this->_set_error_message('email_attachment_unredable', $filename); + $this->_set_error_message('email_attachment_unredable', $filename); return FALSE; } @@ -1128,10 +1128,10 @@ class CI_Email { * @access private * @return void */ - function _unwrap_specials() - { - $this->_finalbody = preg_replace_callback("/\{unwrap\}(.*?)\{\/unwrap\}/si", array($this, '_remove_nl_callback'), $this->_finalbody); - } + function _unwrap_specials() + { + $this->_finalbody = preg_replace_callback("/\{unwrap\}(.*?)\{\/unwrap\}/si", array($this, '_remove_nl_callback'), $this->_finalbody); + } // -------------------------------------------------------------------- @@ -1141,10 +1141,10 @@ class CI_Email { * @access private * @return string */ - function _remove_nl_callback($matches) - { - return preg_replace("/(\r\n)|(\r)|(\n)/", "", $matches['1']); - } + function _remove_nl_callback($matches) + { + return preg_replace("/(\r\n)|(\r)|(\n)/", "", $matches['1']); + } // -------------------------------------------------------------------- @@ -1156,7 +1156,7 @@ class CI_Email { */ function _spool_email() { - $this->_unwrap_specials(); + $this->_unwrap_specials(); switch ($this->_get_protocol()) { @@ -1168,7 +1168,7 @@ class CI_Email { return FALSE; } break; - case 'sendmail' : + case 'sendmail' : if ( ! $this->_send_with_sendmail()) { @@ -1176,7 +1176,7 @@ class CI_Email { return FALSE; } break; - case 'smtp' : + case 'smtp' : if ( ! $this->_send_with_smtp()) { @@ -1252,8 +1252,8 @@ class CI_Email { */ function _send_with_smtp() { - if ($this->smtp_host == '') - { + if ($this->smtp_host == '') + { $this->_set_error_message('email_no_hostname'); return FALSE; } @@ -1316,10 +1316,10 @@ class CI_Email { function _smtp_connect() { - $this->_smtp_connect = fsockopen($this->smtp_host, + $this->_smtp_connect = fsockopen($this->smtp_host, $this->smtp_port, - $errno, - $errstr, + $errno, + $errstr, $this->smtp_timeout); if( ! is_resource($this->_smtp_connect)) @@ -1478,17 +1478,17 @@ class CI_Email { */ function _get_smtp_data() { - $data = ""; - - while ($str = fgets($this->_smtp_connect, 512)) - { + $data = ""; + + while ($str = fgets($this->_smtp_connect, 512)) + { $data .= $str; if (substr($str, 3, 1) == " ") break; - } - - return $data; + } + + return $data; } // -------------------------------------------------------------------- @@ -1567,7 +1567,6 @@ class CI_Email { $msg .= "
".$this->_header_str."\n".$this->_subject."\n".$this->_finalbody.'
'; return $msg; } - // print_debugger() // -------------------------------------------------------------------- diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index b7dba2523..0f860a967 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource @@ -98,12 +98,12 @@ class CI_Encrypt { /** * Encode * - * Encodes the message string using bitwise XOR encoding. - * The key is combined with a random hash, and then it - * too gets converted using XOR. The whole thing is then run - * through mcrypt (if supported) using the randomized key. - * The end result is a double-encrypted message string - * that is randomized with each call to this function, + * Encodes the message string using bitwise XOR encoding. + * The key is combined with a random hash, and then it + * too gets converted using XOR. The whole thing is then run + * through mcrypt (if supported) using the randomized key. + * The end result is a double-encrypted message string + * that is randomized with each call to this function, * even if the supplied message and key are the same. * * @access public @@ -169,8 +169,8 @@ class CI_Encrypt { function _xor_encode($string, $key) { $rand = ''; - while (strlen($rand) < 32) - { + while (strlen($rand) < 32) + { $rand .= mt_rand(0, mt_getrandmax()); } @@ -190,7 +190,7 @@ class CI_Encrypt { /** * XOR Decode * - * Takes an encoded string and key as input and generates the + * Takes an encoded string and key as input and generates the * plain-text original message * * @access private @@ -245,7 +245,7 @@ class CI_Encrypt { * @param string * @return string */ - function mcrypt_encode($data, $key) + function mcrypt_encode($data, $key) { $init_size = mcrypt_get_iv_size($this->_get_cipher(), $this->_get_mode()); $init_vect = mcrypt_create_iv($init_size, MCRYPT_RAND); @@ -262,7 +262,7 @@ class CI_Encrypt { * @param string * @return string */ - function mcrypt_decode($data, $key) + function mcrypt_decode($data, $key) { $init_size = mcrypt_get_iv_size($this->_get_cipher(), $this->_get_mode()); $init_vect = mcrypt_create_iv($init_size, MCRYPT_RAND); @@ -307,7 +307,7 @@ class CI_Encrypt { */ function _get_cipher() { - if ($this->_mcrypt_cipher == '') + if ($this->_mcrypt_cipher == '') { $this->_mcrypt_cipher = MCRYPT_RIJNDAEL_256; } @@ -325,7 +325,7 @@ class CI_Encrypt { */ function _get_mode() { - if ($this->_mcrypt_mode == '') + if ($this->_mcrypt_mode == '') { $this->_mcrypt_mode = MCRYPT_MODE_ECB; } @@ -378,7 +378,7 @@ class CI_Encrypt { { require_once(BASEPATH.'libraries/Sha1'.EXT); $SH = new CI_SHA; - return $SH->generate($str); + return $SH->generate($str); } else { @@ -389,7 +389,7 @@ class CI_Encrypt { { return sha1($str); } - } + } } diff --git a/system/libraries/Exceptions.php b/system/libraries/Exceptions.php index a0591e4e5..6d58ee6b9 100644 --- a/system/libraries/Exceptions.php +++ b/system/libraries/Exceptions.php @@ -7,17 +7,17 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** * Exceptions Class - * + * * @package CodeIgniter * @subpackage Libraries * @category Exceptions @@ -48,7 +48,7 @@ class CI_Exceptions { /** - * Constructor + * Constructor * */ function CI_Exceptions() @@ -76,7 +76,7 @@ class CI_Exceptions { log_message('error', 'Severity: '.$severity.' '.$severity.' --> '.$message. ' '.$filepath.' '.$line, TRUE); } - + // -------------------------------------------------------------------- /** @@ -89,7 +89,7 @@ class CI_Exceptions { function show_404($page = '') { $heading = "404 Page Not Found"; - $message = "The page you requested was not found."; + $message = "The page you requested was not found."; log_message('error', '404 Page Not Found --> '.$page); echo $this->show_error($heading, $message, 'error_404'); @@ -125,7 +125,7 @@ class CI_Exceptions { ob_end_clean(); return $buffer; } - + // -------------------------------------------------------------------- /** diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index 6f48723f6..99d2e3e30 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -132,7 +132,7 @@ class CI_Hooks { // Safety - Prevents run-away loops // ----------------------------------- - // If the script being called happens to have the same + // If the script being called happens to have the same // hook call within it a loop can happen if ($this->in_progress == TRUE) @@ -164,17 +164,17 @@ class CI_Hooks { $function = FALSE; $params = ''; - if (isset($data['class']) AND $data['class'] != '') + if (isset($data['class']) AND $data['class'] != '') { $class = $data['class']; } - if (isset($data['function'])) + if (isset($data['function'])) { $function = $data['function']; } - if (isset($data['params'])) + if (isset($data['params'])) { $params = $data['params']; } diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index f8c05f834..561c5c03a 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -7,17 +7,17 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** * Image Manipulation class - * + * * @package CodeIgniter * @subpackage Libraries * @category Image_lib @@ -77,7 +77,7 @@ class CI_Image_lib { var $wm_use_truetype = FALSE; /** - * Constructor + * Constructor * * @access public * @param string @@ -123,7 +123,7 @@ class CI_Image_lib { * @return void */ function initialize($props = array()) - { + { /* * Convert array elements into class variables */ @@ -144,7 +144,7 @@ class CI_Image_lib { if ($this->source_image == '') { $this->set_error('imglib_source_image_required'); - return FALSE; + return FALSE; } /* @@ -155,7 +155,7 @@ class CI_Image_lib { * properties using ImageMagick and NetPBM * */ - if ( ! function_exists('getimagesize')) + if ( ! function_exists('getimagesize')) { $this->set_error('imglib_gd_required_for_props'); return FALSE; @@ -173,7 +173,7 @@ class CI_Image_lib { */ if (function_exists('realpath') AND @realpath($this->source_image) !== FALSE) { - $full_source_path = str_replace("\\", "/", realpath($this->source_image)); + $full_source_path = str_replace("\\", "/", realpath($this->source_image)); } else { @@ -187,7 +187,7 @@ class CI_Image_lib { // Set the Image Properties if ( ! $this->get_image_properties($this->source_folder.$this->source_image)) { - return FALSE; + return FALSE; } /* @@ -215,11 +215,11 @@ class CI_Image_lib { { if (function_exists('realpath') AND @realpath($this->new_image) !== FALSE) { - $full_dest_path = str_replace("\\", "/", realpath($this->new_image)); + $full_dest_path = str_replace("\\", "/", realpath($this->new_image)); } else { - $full_dest_path = $this->new_image; + $full_dest_path = $this->new_image; } // Is there a file name? @@ -257,7 +257,7 @@ class CI_Image_lib { $filename = $xp['name']; $file_ext = $xp['ext']; - $this->full_src_path = $this->source_folder.$this->source_image; + $this->full_src_path = $this->source_folder.$this->source_image; $this->full_dst_path = $this->dest_folder.$filename.$this->thumb_marker.$file_ext; /* @@ -316,7 +316,7 @@ class CI_Image_lib { if ($this->wm_overlay_path != '') { - $this->wm_overlay_path = str_replace("\\", "/", realpath($this->wm_overlay_path)); + $this->wm_overlay_path = str_replace("\\", "/", realpath($this->wm_overlay_path)); } if ($this->wm_shadow_color != '') @@ -330,7 +330,7 @@ class CI_Image_lib { } return TRUE; - } + } // -------------------------------------------------------------------- @@ -397,7 +397,7 @@ class CI_Image_lib { if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs, TRUE)) { $this->set_error('imglib_rotation_angle_required'); - return FALSE; + return FALSE; } // Reassign the width and height @@ -454,7 +454,7 @@ class CI_Image_lib { // We'll return true so the user thinks the process succeeded. // It'll be our little secret... - return TRUE; + return TRUE; } // Reassign the source width/height if cropping @@ -478,7 +478,7 @@ class CI_Image_lib { if ( ! @copy($this->full_src_path, $this->full_dst_path)) { $this->set_error('imglib_copy_failed'); - return FALSE; + return FALSE; } @chmod($this->full_dst_path, 0777); @@ -508,12 +508,12 @@ class CI_Image_lib { $copy = 'imagecopyresized'; } - $dst_img = $create($this->width, $this->height); - $copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height); + $dst_img = $create($this->width, $this->height); + $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 if ($this->dynamic_output == TRUE) - { + { $this->image_display_gd($dst_img); } else @@ -526,11 +526,11 @@ class CI_Image_lib { } // Kill the file handles - imagedestroy($dst_img); + imagedestroy($dst_img); imagedestroy($src_img); // Set the file to 777 - @chmod($this->full_dst_path, 0777); + @chmod($this->full_dst_path, 0777); return TRUE; } @@ -555,7 +555,7 @@ class CI_Image_lib { return FALSE; } - if ( ! eregi("convert$", $this->library_path)) + if ( ! eregi("convert$", $this->library_path)) { if ( ! eregi("/$", $this->library_path)) $this->library_path .= "/"; @@ -593,14 +593,14 @@ class CI_Image_lib { @exec($cmd, $output, $retval); // Did it work? - if ($retval > 0) + if ($retval > 0) { $this->set_error('imglib_image_process_failed'); return FALSE; } // Set the file to 777 - @chmod($this->full_dst_path, 0777); + @chmod($this->full_dst_path, 0777); return TRUE; } @@ -675,7 +675,7 @@ class CI_Image_lib { @exec($cmd, $output, $retval); // Did it work? - if ($retval > 0) + if ($retval > 0) { $this->set_error('imglib_image_process_failed'); return FALSE; @@ -686,7 +686,7 @@ class CI_Image_lib { // we have to rename the temp file. copy ($this->dest_folder.'netpbm.tmp', $this->full_dst_path); unlink ($this->dest_folder.'netpbm.tmp'); - @chmod($dst_image, 0777); + @chmod($dst_image, 0777); return TRUE; } @@ -704,7 +704,7 @@ class CI_Image_lib { // Is Image Rotation Supported? // this function is only supported as of PHP 4.3 if ( ! function_exists('imagerotate')) - { + { $this->set_error('imglib_rotate_unsupported'); return FALSE; } @@ -727,7 +727,7 @@ class CI_Image_lib { // Save the Image if ($this->dynamic_output == TRUE) - { + { $this->image_display_gd($dst_img); } else @@ -740,12 +740,12 @@ class CI_Image_lib { } // Kill the file handles - imagedestroy($dst_img); + imagedestroy($dst_img); imagedestroy($src_img); // Set the file to 777 - @chmod($this->full_dst_path, 0777); + @chmod($this->full_dst_path, 0777); return true; } @@ -773,47 +773,47 @@ class CI_Image_lib { if ($this->rotation_angle == 'hor') { for ($i = 0; $i < $height; $i++) - { - $left = 0; - $right = $width-1; + { + $left = 0; + $right = $width-1; while ($left < $right) - { - $cl = imagecolorat($src_img, $left, $i); + { + $cl = imagecolorat($src_img, $left, $i); $cr = imagecolorat($src_img, $right, $i); - imagesetpixel($src_img, $left, $i, $cr); - imagesetpixel($src_img, $right, $i, $cl); + imagesetpixel($src_img, $left, $i, $cr); + imagesetpixel($src_img, $right, $i, $cl); - $left++; - $right--; - } + $left++; + $right--; + } } } else { for ($i = 0; $i < $width; $i++) - { - $top = 0; - $bot = $height-1; + { + $top = 0; + $bot = $height-1; while ($top < $bot) - { + { $ct = imagecolorat($src_img, $i, $top); $cb = imagecolorat($src_img, $i, $bot); - imagesetpixel($src_img, $i, $top, $cb); - imagesetpixel($src_img, $i, $bot, $ct); + imagesetpixel($src_img, $i, $top, $cb); + imagesetpixel($src_img, $i, $bot, $ct); - $top++; - $bot--; - } + $top++; + $bot--; + } } } // Show the image if ($this->dynamic_output == TRUE) - { + { $this->image_display_gd($src_img); } else @@ -829,7 +829,7 @@ class CI_Image_lib { imagedestroy($src_img); // Set the file to 777 - @chmod($this->full_dst_path, 0777); + @chmod($this->full_dst_path, 0777); return TRUE; } @@ -930,8 +930,8 @@ class CI_Image_lib { } // Build the finalized image - if ($wm_img_type == 3 AND function_exists('imagealphablending')) - { + if ($wm_img_type == 3 AND function_exists('imagealphablending')) + { @imagealphablending($src_img, TRUE); } @@ -941,7 +941,7 @@ class CI_Image_lib { // Output the image if ($this->dynamic_output == TRUE) - { + { $this->image_display_gd($src_img); } else @@ -966,7 +966,7 @@ class CI_Image_lib { * @access public * @return bool */ - function text_watermark() + function text_watermark() { if ( ! ($src_img = $this->image_create_gd())) { @@ -1039,7 +1039,7 @@ class CI_Image_lib { $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); - switch ($this->wm_vrt_alignment) + switch ($this->wm_vrt_alignment) { case "T" : break; @@ -1053,7 +1053,7 @@ class CI_Image_lib { $y_shad = $y_axis + $this->wm_shadow_distance; // Set horizontal alignment - switch ($this->wm_hor_alignment) + switch ($this->wm_hor_alignment) { case "L": break; @@ -1085,7 +1085,7 @@ class CI_Image_lib { // Output the final image if ($this->dynamic_output == TRUE) - { + { $this->image_display_gd($src_img); } else @@ -1160,7 +1160,7 @@ class CI_Image_lib { /** * Write image file to disk - GD * - * Takes an image resource as input and writes the file + * Takes an image resource as input and writes the file * to the specified destination * * @access public @@ -1226,7 +1226,7 @@ class CI_Image_lib { header("Content-Disposition: filename={$this->source_image};"); header("Content-Type: {$this->mime_type}"); header('Content-Transfer-Encoding: binary'); - header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT'); + header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT'); switch ($this->image_type) { @@ -1247,9 +1247,9 @@ class CI_Image_lib { * Re-proportion Image Width/Height * * When creating thumbs, the desired width/height - * can end up warping the image due to an incorrect - * ratio between the full-sized image and the thumb. - * + * can end up warping the image due to an incorrect + * ratio between the full-sized image and the thumb. + * * This function lets us re-proportion the width/height * if users choose to maintain the aspect ratio when resizing. * @@ -1323,7 +1323,7 @@ class CI_Image_lib { $v['width'] = $vals['0']; $v['height'] = $vals['1']; $v['image_type'] = $vals['2']; - $v['size_str'] = $vals['3']; + $v['size_str'] = $vals['3']; $v['mime_type'] = $mime; return $v; @@ -1332,8 +1332,8 @@ class CI_Image_lib { $this->orig_width = $vals['0']; $this->orig_height = $vals['1']; $this->image_type = $vals['2']; - $this->size_str = $vals['3']; - $this->mime_type = $mime; + $this->size_str = $vals['3']; + $this->mime_type = $mime; return TRUE; } @@ -1352,7 +1352,7 @@ class CI_Image_lib { * 'height' => $height, * 'new_width' => 40, * 'new_height' => '' - * ); + * ); * * @access public * @param array diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 57696c8a2..8408b16fc 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -7,17 +7,17 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** * Input Class - * + * * Pre-processes global input data for security * * @package CodeIgniter @@ -103,7 +103,7 @@ class CI_Input { if (is_array($_COOKIE) AND count($_COOKIE) > 0) { foreach($_COOKIE as $key => $val) - { + { $_COOKIE[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); } } @@ -116,7 +116,7 @@ class CI_Input { /** * Clean Input Data * - * This is a helper function. It escapes data and + * This is a helper function. It escapes data and * standardizes newline characters to \n * * @access private @@ -149,8 +149,8 @@ class CI_Input { /** * Clean Keys * - * This is a helper function. To prevent malicious users - * from trying to exploit keys we make sure that keys are + * This is a helper function. To prevent malicious users + * from trying to exploit keys we make sure that keys are * only named with alpha-numeric text and a few other items. * * @access private @@ -160,7 +160,7 @@ class CI_Input { function _clean_input_keys($str) { if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str)) - { + { exit('Disallowed Key Characters: '.$str); } @@ -378,7 +378,7 @@ class CI_Input { * got from Bitflux: http://blog.bitflux.ch/wiki/XSS_Prevention * * To help develop this script I used this great list of - * vulnerabilities along with a few other hacks I've + * vulnerabilities along with a few other hacks I've * harvested from examining vulnerabilities in other programs: * http://ha.ckers.org/xss.html * @@ -408,7 +408,7 @@ class CI_Input { $str = preg_replace('#(&\#*\w+)[\x00-\x20]+;#u',"\\1;",$str); /* - * Validate UTF16 two byte encoding (x00) + * Validate UTF16 two byte encoding (x00) * * Just as above, adds a semicolon if missing. * @@ -429,20 +429,20 @@ class CI_Input { $str = preg_replace("/%([a-z0-9]{2})/i", "&#x\\1;", $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 * these are the ones that will pose security problems. * */ - + if (preg_match_all("/<(.+?)>/si", $str, $matches)) { for ($i = 0; $i < count($matches['0']); $i++) { - $str = str_replace($matches['1'][$i], - $this->_html_entity_decode($matches['1'][$i], $charset), + $str = str_replace($matches['1'][$i], + $this->_html_entity_decode($matches['1'][$i], $charset), $str); } } @@ -500,7 +500,7 @@ class CI_Input { * Remove JavaScript Event Handlers * * Note: This code is a little blunt. It removes - * the event handler and anything up to the closing >, + * the event handler and anything up to the closing >, * but it's unlikely to be a problem. * */ @@ -509,7 +509,7 @@ class CI_Input { /* * Sanitize naughty HTML elements * - * If a tag containing any of the words in the list + * If a tag containing any of the words in the list * below is found, the tag gets converted to entities. * * So this: @@ -552,7 +552,7 @@ class CI_Input { foreach ($bad as $key => $val) { - $str = preg_replace("#".$key."#i", $val, $str); + $str = preg_replace("#".$key."#i", $val, $str); } @@ -582,11 +582,11 @@ class CI_Input { /* -------------------------------------------------*/ /* - NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the + NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the character set, and the PHP developers said they were not back porting the fix to versions other than PHP 5.x. */ - function _html_entity_decode($str, $charset='ISO-8859-1') + function _html_entity_decode($str, $charset='ISO-8859-1') { if (stristr($str, '&') === FALSE) return $str; diff --git a/system/libraries/Language.php b/system/libraries/Language.php index 825080745..37a5c7e99 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -7,17 +7,17 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** * Language Class - * + * * @package CodeIgniter * @subpackage Libraries * @category Language @@ -30,7 +30,7 @@ class CI_Language { var $is_loaded = array(); /** - * Constructor + * Constructor * * @access public */ @@ -83,7 +83,7 @@ class CI_Language { } } - + if ( ! isset($lang)) { log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile); diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 849ee731a..7a1fd6802 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -7,17 +7,17 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** * Loader Class - * + * * Loads views and files * * @package CodeIgniter @@ -192,7 +192,7 @@ class CI_Loader { * Load the Utilities Class * * @access public - * @return string + * @return string */ function dbutil() { @@ -550,9 +550,9 @@ class CI_Loader { /* * Extract and cache variables * - * You can either set variables using the dedicated $this->load_vars() - * 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 + * You can either set variables using the dedicated $this->load_vars() + * 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($vars)) @@ -579,9 +579,9 @@ class CI_Loader { * * We buffer the output for two reasons: * 1. Speed. You get a significant speed boost. - * 2. So that the final rendered template can be + * 2. So that the final rendered template can be * post-processed by the output class. Why do we - * need post processing? For one thing, in order to + * need post processing? For one thing, in order to * show the elapsed page load time. Unless we * can intercept the content right before it's sent to * the browser and then stop the timer it won't be accurate. @@ -612,7 +612,7 @@ class CI_Loader { if ($return === TRUE) { $buffer = ob_get_contents(); - ob_end_clean(); + ob_end_clean(); return $buffer; } @@ -621,9 +621,9 @@ class CI_Loader { * Flush the buffer... or buff the flusher? * * In order to permit views to be nested within - * other views, we need to flush the content back out whenever - * we are beyond the first level of output buffering so that - * it can be seen and included properly by the first included + * other views, we need to flush the content back out whenever + * we are beyond the first level of output buffering so that + * it can be seen and included properly by the first included * template and any subsequent ones. Oy! * */ @@ -702,7 +702,7 @@ class CI_Loader { { // Is there an associated config file for this class? if ($config !== NULL) - { + { $cong = NULL; if (file_exists(APPPATH.'config/'.$class.EXT)) { @@ -740,7 +740,7 @@ class CI_Loader { /** * Autoloader * - * The config/autoload.php file contains an array that permits sub-systems, + * The config/autoload.php file contains an array that permits sub-systems, * libraries, plugins, and helpers to be loaded automatically. * * @access private @@ -785,14 +785,14 @@ class CI_Loader { // Load libraries if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0) { - // Load the database driver. + // Load the database driver. if (in_array('database', $autoload['libraries'])) { $this->database(); $autoload['libraries'] = array_diff($autoload['libraries'], array('database')); } - // Load the model class. + // Load the model class. if (in_array('model', $autoload['libraries'])) { $this->model(); diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 09538fa0b..03dc64005 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -7,17 +7,17 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** * Logging Class - * + * * @package CodeIgniter * @subpackage Libraries * @category Logging @@ -78,7 +78,7 @@ class CI_Log { function write_log($level = 'error', $msg, $php_error = FALSE) { if ($this->_enabled === FALSE) - { + { return FALSE; } diff --git a/system/libraries/Model.php b/system/libraries/Model.php index 017a9c6d8..240db4397 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -41,7 +41,7 @@ class Model { * Assign Libraries * * Creates local references to all currently instantiated objects - * so that any syntax that can be legally used in a controller + * so that any syntax that can be legally used in a controller * can be used within models. * * @access private diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 9c48bbb84..0c2620df7 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -7,19 +7,19 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** * Output Class * * Responsible for sending final output to browser - * + * * @package CodeIgniter * @subpackage Libraries * @category Output @@ -42,7 +42,7 @@ class CI_Output { // -------------------------------------------------------------------- /** - * Get Output + * Get Output * * Returns the current output string * @@ -57,7 +57,7 @@ class CI_Output { // -------------------------------------------------------------------- /** - * Set Output + * Set Output * * Sets the output string * @@ -73,7 +73,7 @@ class CI_Output { // -------------------------------------------------------------------- /** - * Set Header + * Set Header * * Lets you set a server header which will be outputted with the final display. * @@ -92,7 +92,7 @@ class CI_Output { // -------------------------------------------------------------------- /** - * Enable/disable Profiler + * Enable/disable Profiler * * @access public * @param bool @@ -106,7 +106,7 @@ class CI_Output { // -------------------------------------------------------------------- /** - * Set Cache + * Set Cache * * @access public * @param integer @@ -135,8 +135,8 @@ class CI_Output { */ 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, + // 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. global $BM, $CFG; @@ -158,7 +158,7 @@ class CI_Output { // -------------------------------------------------------------------- - // Parse out the elapsed time and memory usage, + // 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'); @@ -249,7 +249,7 @@ class CI_Output { // -------------------------------------------------------------------- /** - * Write a Cache File + * Write a Cache File * * @access public * @return void @@ -272,19 +272,19 @@ class CI_Output { $cache_path .= md5($uri); - if ( ! $fp = @fopen($cache_path, 'wb')) - { + if ( ! $fp = @fopen($cache_path, 'wb')) + { log_message('error', "Unable to write ache file: ".$cache_path); - return; + return; } $expire = time() + ($this->cache_expiration * 60); - flock($fp, LOCK_EX); - fwrite($fp, $expire.'TS--->'.$output); - flock($fp, LOCK_UN); - fclose($fp); - @chmod($cache_path, 0777); + flock($fp, LOCK_EX); + fwrite($fp, $expire.'TS--->'.$output); + flock($fp, LOCK_UN); + fclose($fp); + @chmod($cache_path, 0777); log_message('debug', "Cache file written: ".$cache_path); } @@ -292,7 +292,7 @@ class CI_Output { // -------------------------------------------------------------------- /** - * Update/serve a cached file + * Update/serve a cached file * * @access public * @return void @@ -329,13 +329,13 @@ class CI_Output { flock($fp, LOCK_SH); $cache = ''; - if (filesize($filepath) > 0) + if (filesize($filepath) > 0) { - $cache = fread($fp, filesize($filepath)); + $cache = fread($fp, filesize($filepath)); } flock($fp, LOCK_UN); - fclose($fp); + fclose($fp); // Strip out the embedded timestamp if ( ! preg_match("/(\d+TS--->)/", $cache, $match)) diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 26fb93ee4..a004419d6 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource @@ -28,13 +28,13 @@ class CI_Pagination { var $base_url = ''; // The page we are linking to 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 $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 $next_link = '>'; var $prev_link = '<'; - var $last_link = 'Last ›'; + var $last_link = 'Last ›'; var $uri_segment = 3; var $full_tag_open = ''; var $full_tag_close = ''; @@ -57,15 +57,15 @@ class CI_Pagination { * @access public * @param array initialization parameters */ - function CI_Pagination($params = array()) - { + function CI_Pagination($params = array()) + { if (count($params) > 0) { $this->initialize($params); } log_message('debug', "Pagination Class Initialized"); - } + } // -------------------------------------------------------------------- @@ -76,8 +76,8 @@ class CI_Pagination { * @param array initialization parameters * @return void */ - function initialize($params = array()) - { + function initialize($params = array()) + { if (count($params) > 0) { foreach ($params as $key => $val) @@ -88,7 +88,7 @@ class CI_Pagination { } } } - } + } // -------------------------------------------------------------------- @@ -98,34 +98,34 @@ class CI_Pagination { * @access public * @return string */ - function create_links() - { + function create_links() + { // If our item count or per-page total is zero there is no need to continue. - if ($this->total_rows == 0 OR $this->per_page == 0) - { - return ''; - } + if ($this->total_rows == 0 OR $this->per_page == 0) + { + return ''; + } // Calculate the total number of pages - $num_pages = ceil($this->total_rows / $this->per_page); + $num_pages = ceil($this->total_rows / $this->per_page); - /* + /* // Calculate the total number of pages $num_pages = intval($this->total_rows / $this->per_page); // Use modulus to see if our division has a remainder. If so, add one to our page number. - if ($this->total_rows % $this->per_page) + if ($this->total_rows % $this->per_page) { $num_pages++; } */ - - // Is there only one page? Hm... nothing more to do here then. - if ($num_pages == 1) - { - return ''; - } - + + // Is there only one page? Hm... nothing more to do here then. + if ($num_pages == 1) + { + return ''; + } + // Determine the current page number. $CI =& get_instance(); if ($CI->uri->segment($this->uri_segment) != 0) @@ -140,35 +140,35 @@ class CI_Pagination { $uri_page_number = $this->cur_page; $this->cur_page = floor(($this->cur_page/$this->per_page) + 1); - + // Calculate the start and end numbers. These determine // which number to start and end the digit links with - $start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1; - $end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages; - + $start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1; + $end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages; + // Add a trailing slash to the base URL if needed $this->base_url = preg_replace("/(.+?)\/*$/", "\\1/", $this->base_url); // And here we go... - $output = ''; - + $output = ''; + // Render the "First" link - if ($this->cur_page > $this->num_links) - { - $output .= $this->first_tag_open.''.$this->first_link.''.$this->first_tag_close; - } - + if ($this->cur_page > $this->num_links) + { + $output .= $this->first_tag_open.''.$this->first_link.''.$this->first_tag_close; + } + // Render the "previous" link - if (($this->cur_page - $this->num_links) >= 0) - { - $i = $uri_page_number - $this->per_page; - if ($i == 0) $i = ''; - $output .= $this->prev_tag_open.''.$this->prev_link.''.$this->prev_tag_close; - } - + if (($this->cur_page - $this->num_links) >= 0) + { + $i = $uri_page_number - $this->per_page; + if ($i == 0) $i = ''; + $output .= $this->prev_tag_open.''.$this->prev_link.''.$this->prev_tag_close; + } + // Write the digit links - for ($loop = $start -1; $loop <= $end; $loop++) - { + for ($loop = $start -1; $loop <= $end; $loop++) + { $i = ($loop * $this->per_page) - $this->per_page; if ($i >= 0) @@ -183,30 +183,30 @@ class CI_Pagination { $output .= $this->num_tag_open.''.$loop.''.$this->num_tag_close; } } - } + } // Render the "next" link - if ($this->cur_page < $num_pages) - { - $output .= $this->next_tag_open.''.$this->next_link.''.$this->next_tag_close; - } + if ($this->cur_page < $num_pages) + { + $output .= $this->next_tag_open.''.$this->next_link.''.$this->next_tag_close; + } // Render the "Last" link - if (($this->cur_page + $this->num_links) < $num_pages) - { - $i = (($num_pages * $this->per_page) - $this->per_page); - $output .= $this->last_tag_open.''.$this->last_link.''.$this->last_tag_close; - } - - // Kill double slashes. Note: Sometimes we can end up with a double slash + if (($this->cur_page + $this->num_links) < $num_pages) + { + $i = (($num_pages * $this->per_page) - $this->per_page); + $output .= $this->last_tag_open.''.$this->last_link.''.$this->last_tag_close; + } + + // Kill double slashes. Note: Sometimes we can end up with a double slash // in the penultimate link so we'll kill all double slashes. - $output = preg_replace("#([^:])//+#", "\\1/", $output); + $output = preg_replace("#([^:])//+#", "\\1/", $output); // Add the wrapper HTML if exists $output = $this->full_tag_open.$output.$this->full_tag_close; return $output; - } + } } // END Pagination Class ?> \ No newline at end of file diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index ebf7644ac..760d5d4d3 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource @@ -17,7 +17,7 @@ /** * Parser Class - * + * * @package CodeIgniter * @subpackage Libraries * @category Parser @@ -33,7 +33,7 @@ class CI_Parser { /** * Parse a template * - * Parses pseudo-variables contained in the specified template, + * Parses pseudo-variables contained in the specified template, * replacing them with the data in the second param * * @access public diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 6e6fb675f..e03097ab6 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 6002027d6..17a441c77 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -7,17 +7,17 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** * Router Class - * + * * Parses URIs and determines routing * * @package CodeIgniter @@ -44,7 +44,7 @@ class CI_Router { /** * Constructor * - * Runs the route mapping function. + * Runs the route mapping function. */ function CI_Router() { @@ -94,7 +94,7 @@ class CI_Router { // If the URI contains only a slash we'll kill it if ($this->uri_string == '/') - { + { $this->uri_string = ''; } @@ -243,7 +243,7 @@ class CI_Router { * Re-index Segments * * This function re-indexes the $this->segment array so that it - * starts at 1 rather then 0. Doing so makes it simpler to + * starts at 1 rather then 0. Doing so makes it simpler to * use functions like $this->uri->segment(n) since there is * a 1:1 relationship between the segment array and the actual segments. * @@ -320,9 +320,9 @@ class CI_Router { return $path; } - // OK, how about REQUEST_URI? + // OK, how about REQUEST_URI? // Note: REQUEST_URI is not supplied in a consistent manner with all platforms so it's - // a difficult variable to use. We'll try to parse it out correctly. Hopefully one + // a difficult variable to use. We'll try to parse it out correctly. Hopefully one // of the other variables above was available. $path = $this->_parse_request_uri(); if ($path != "") @@ -352,7 +352,7 @@ class CI_Router { * Parse the REQUEST_URI * * Due to the way REQUEST_URI works it usually contains path info - * that makes it unusable as URI data. We'll trim off the unnecessary + * that makes it unusable as URI data. We'll trim off the unnecessary * data, hopefully arriving at a valid URI that we can use. * * @access private @@ -413,7 +413,7 @@ class CI_Router { if ($this->config->item('permitted_uri_chars') != '') { if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) - { + { exit('The URI you submitted has disallowed characters: '.$str); } } @@ -426,7 +426,7 @@ class CI_Router { * Parse Routes * * This function matches any routes that may exist in - * the config/routes.php file against the URI to + * the config/routes.php file against the URI to * determine if the class/method need to be remapped. * * @access private @@ -472,7 +472,7 @@ class CI_Router { } } - // If we got this far it means we didn't encounter a + // If we got this far it means we didn't encounter a // matching route so we'll set the site default route $this->_compile_segments($this->segments); } diff --git a/system/libraries/Session.php b/system/libraries/Session.php index a47599d12..96a0c43b2 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource @@ -17,7 +17,7 @@ /** * Session Class - * + * * @package CodeIgniter * @subpackage Libraries * @category Sessions @@ -26,16 +26,16 @@ */ class CI_Session { - var $CI; + var $CI; var $now; var $encryption = TRUE; var $use_database = FALSE; var $session_table = FALSE; - var $sess_length = 7200; - var $sess_cookie = 'ci_session'; + var $sess_length = 7200; + var $sess_cookie = 'ci_session'; var $userdata = array(); - var $gc_probability = 5; - + var $gc_probability = 5; + /** * Session Constructor @@ -66,7 +66,7 @@ class CI_Session { * * It can either set to GMT or time(). The pref * is set in the config file. If the developer - * is doing any sort of time localization they + * is doing any sort of time localization they * might want to set the session time to GMT so * they can offset the "last_activity" and * "last_visit" times based on each user's locale. @@ -75,7 +75,7 @@ class CI_Session { if (strtolower($this->CI->config->item('time_reference')) == 'gmt') { $now = time(); - $this->now = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); + $this->now = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); if (strlen($this->now) < 10) { @@ -92,7 +92,7 @@ class CI_Session { * Set the session length * * If the session expiration is set to zero in - * the config file we'll set the expiration + * the config file we'll set the expiration * two years from now. * */ @@ -191,7 +191,7 @@ class CI_Session { } // Is the session current? - if (($session['last_activity'] + $this->sess_length) < $this->now) + if (($session['last_activity'] + $this->sess_length) < $this->now) { $this->sess_destroy(); return FALSE; @@ -236,7 +236,7 @@ class CI_Session { else { $row = $query->row(); - if (($row->last_activity + $this->sess_length) < $this->now) + if (($row->last_activity + $this->sess_length) < $this->now) { $this->CI->db->where('session_id', $session['session_id']); $this->CI->db->delete($this->session_table); @@ -271,11 +271,11 @@ class CI_Session { } setcookie( - $this->sess_cookie, - $cookie_data, - $this->sess_length + $this->now, - $this->CI->config->item('cookie_path'), - $this->CI->config->item('cookie_domain'), + $this->sess_cookie, + $cookie_data, + $this->sess_length + $this->now, + $this->CI->config->item('cookie_path'), + $this->CI->config->item('cookie_domain'), 0 ); } @@ -291,8 +291,8 @@ class CI_Session { function sess_create() { $sessid = ''; - while (strlen($sessid) < 32) - { + while (strlen($sessid) < 32) + { $sessid .= mt_rand(0, mt_getrandmax()); } @@ -325,10 +325,10 @@ class CI_Session { */ function sess_update() { - if (($this->userdata['last_activity'] + $this->sess_length) < $this->now) - { + if (($this->userdata['last_activity'] + $this->sess_length) < $this->now) + { $this->userdata['last_visit'] = $this->userdata['last_activity']; - } + } $this->userdata['last_activity'] = $this->now; @@ -353,11 +353,11 @@ class CI_Session { function sess_destroy() { setcookie( - $this->sess_cookie, - addslashes(serialize(array())), - ($this->now - 31500000), - $this->CI->config->item('cookie_path'), - $this->CI->config->item('cookie_domain'), + $this->sess_cookie, + addslashes(serialize(array())), + ($this->now - 31500000), + $this->CI->config->item('cookie_path'), + $this->CI->config->item('cookie_domain'), 0 ); } @@ -373,19 +373,19 @@ class CI_Session { * @access public * @return void */ - function sess_gc() - { + function sess_gc() + { srand(time()); - if ((rand() % 100) < $this->gc_probability) - { + if ((rand() % 100) < $this->gc_probability) + { $expire = $this->now - $this->sess_length; $this->CI->db->where("last_activity < {$expire}"); $this->CI->db->delete($this->session_table); log_message('debug', 'Session garbage collection performed.'); - } - } + } + } // -------------------------------------------------------------------- @@ -398,7 +398,7 @@ class CI_Session { */ function userdata($item) { - return ( ! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; + return ( ! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; } // -------------------------------------------------------------------- @@ -426,7 +426,7 @@ class CI_Session { } } - $this->sess_write(); + $this->sess_write(); } // -------------------------------------------------------------------- @@ -452,7 +452,7 @@ class CI_Session { } } - $this->sess_write(); + $this->sess_write(); } // -------------------------------------------------------------------- @@ -464,21 +464,21 @@ class CI_Session { * @param mixed * @return mixed */ - function strip_slashes($vals) - { - if (is_array($vals)) - { - foreach ($vals as $key=>$val) - { - $vals[$key] = $this->strip_slashes($val); - } - } - else - { - $vals = stripslashes($vals); - } - - return $vals; + function strip_slashes($vals) + { + if (is_array($vals)) + { + foreach ($vals as $key=>$val) + { + $vals[$key] = $this->strip_slashes($val); + } + } + else + { + $vals = stripslashes($vals); + } + + return $vals; } } diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index 971c091ad..4dde04038 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -7,35 +7,35 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** * SHA1 Encoding Class * - * Purpose: Provides 160 bit hashing using The Secure Hash Algorithm - * developed at the National Institute of Standards and Technology. The 40 + * Purpose: Provides 160 bit hashing using The Secure Hash Algorithm + * developed at the National Institute of Standards and Technology. The 40 * character SHA1 message hash is computationally infeasible to crack. - * - * This class is a fallback for servers that are not running PHP greater than + * + * This class is a fallback for servers that are not running PHP greater than * 4.3, or do not have the MHASH library. * * This class is based on two scripts: - * - * Marcus Campbell's PHP implementation (GNU license) + * + * Marcus Campbell's PHP implementation (GNU license) * http://www.tecknik.net/sha-1/ * - * ...which is based on Paul Johnston's JavaScript version + * ...which is based on Paul Johnston's JavaScript version * (BSD license). http://pajhome.org.uk/ - * + * * I encapsulated the functions and wrote one additional method to fix * a hex conversion bug. - Rick Ellis - * + * * @package CodeIgniter * @subpackage Libraries * @category Encryption @@ -56,67 +56,67 @@ class CI_SHA { * @param string * @return string */ - function generate($str) - { - $n = ((strlen($str) + 8) >> 6) + 1; - - for ($i = 0; $i < $n * 16; $i++) - { - $x[$i] = 0; - } - - for ($i = 0; $i < strlen($str); $i++) - { - $x[$i >> 2] |= ord(substr($str, $i, 1)) << (24 - ($i % 4) * 8); - } - - $x[$i >> 2] |= 0x80 << (24 - ($i % 4) * 8); - - $x[$n * 16 - 1] = strlen($str) * 8; - - $a = 1732584193; - $b = -271733879; - $c = -1732584194; - $d = 271733878; - $e = -1009589776; - - for ($i = 0; $i < sizeof($x); $i += 16) - { - $olda = $a; - $oldb = $b; - $oldc = $c; - $oldd = $d; - $olde = $e; - - for($j = 0; $j < 80; $j++) - { - if ($j < 16) - { - $w[$j] = $x[$i + $j]; - } - else - { - $w[$j] = $this->_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1); - } - - $t = $this->_safe_add($this->_safe_add($this->_rol($a, 5), $this->_ft($j, $b, $c, $d)), $this->_safe_add($this->_safe_add($e, $w[$j]), $this->_kt($j))); - - $e = $d; - $d = $c; - $c = $this->_rol($b, 30); - $b = $a; - $a = $t; - } - - $a = $this->_safe_add($a, $olda); - $b = $this->_safe_add($b, $oldb); - $c = $this->_safe_add($c, $oldc); - $d = $this->_safe_add($d, $oldd); - $e = $this->_safe_add($e, $olde); - } - - return $this->_hex($a).$this->_hex($b).$this->_hex($c).$this->_hex($d).$this->_hex($e); - } + function generate($str) + { + $n = ((strlen($str) + 8) >> 6) + 1; + + for ($i = 0; $i < $n * 16; $i++) + { + $x[$i] = 0; + } + + for ($i = 0; $i < strlen($str); $i++) + { + $x[$i >> 2] |= ord(substr($str, $i, 1)) << (24 - ($i % 4) * 8); + } + + $x[$i >> 2] |= 0x80 << (24 - ($i % 4) * 8); + + $x[$n * 16 - 1] = strlen($str) * 8; + + $a = 1732584193; + $b = -271733879; + $c = -1732584194; + $d = 271733878; + $e = -1009589776; + + for ($i = 0; $i < sizeof($x); $i += 16) + { + $olda = $a; + $oldb = $b; + $oldc = $c; + $oldd = $d; + $olde = $e; + + for($j = 0; $j < 80; $j++) + { + if ($j < 16) + { + $w[$j] = $x[$i + $j]; + } + else + { + $w[$j] = $this->_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1); + } + + $t = $this->_safe_add($this->_safe_add($this->_rol($a, 5), $this->_ft($j, $b, $c, $d)), $this->_safe_add($this->_safe_add($e, $w[$j]), $this->_kt($j))); + + $e = $d; + $d = $c; + $c = $this->_rol($b, 30); + $b = $a; + $a = $t; + } + + $a = $this->_safe_add($a, $olda); + $b = $this->_safe_add($b, $oldb); + $c = $this->_safe_add($c, $oldc); + $d = $this->_safe_add($d, $oldd); + $e = $this->_safe_add($e, $olde); + } + + return $this->_hex($a).$this->_hex($b).$this->_hex($c).$this->_hex($d).$this->_hex($e); + } // -------------------------------------------------------------------- @@ -127,17 +127,17 @@ class CI_SHA { * @param string * @return string */ - function _hex($str) - { - $str = dechex($str); - - if (strlen($str) == 7) - { - $str = '0'.$str; - } - - return $str; - } + function _hex($str) + { + $str = dechex($str); + + if (strlen($str) == 7) + { + $str = '0'.$str; + } + + return $str; + } // -------------------------------------------------------------------- @@ -147,18 +147,18 @@ class CI_SHA { * @access private * @return string */ - function _ft($t, $b, $c, $d) - { - if ($t < 20) - return ($b & $c) | ((~$b) & $d); - if ($t < 40) - return $b ^ $c ^ $d; - if ($t < 60) - return ($b & $c) | ($b & $d) | ($c & $d); - - return $b ^ $c ^ $d; - } - + function _ft($t, $b, $c, $d) + { + if ($t < 20) + return ($b & $c) | ((~$b) & $d); + if ($t < 40) + return $b ^ $c ^ $d; + if ($t < 60) + return ($b & $c) | ($b & $d) | ($c & $d); + + return $b ^ $c ^ $d; + } + // -------------------------------------------------------------------- /** @@ -167,25 +167,25 @@ class CI_SHA { * @access private * @return string */ - function _kt($t) - { - if ($t < 20) - { - return 1518500249; - } - else if ($t < 40) - { - return 1859775393; - } - else if ($t < 60) - { - return -1894007588; - } - else - { - return -899497514; - } - } + function _kt($t) + { + if ($t < 20) + { + return 1518500249; + } + else if ($t < 40) + { + return 1859775393; + } + else if ($t < 60) + { + return -1894007588; + } + else + { + return -899497514; + } + } // -------------------------------------------------------------------- @@ -195,13 +195,13 @@ class CI_SHA { * @access private * @return string */ - function _safe_add($x, $y) - { - $lsw = ($x & 0xFFFF) + ($y & 0xFFFF); - $msw = ($x >> 16) + ($y >> 16) + ($lsw >> 16); - - return ($msw << 16) | ($lsw & 0xFFFF); - } + function _safe_add($x, $y) + { + $lsw = ($x & 0xFFFF) + ($y & 0xFFFF); + $msw = ($x >> 16) + ($y >> 16) + ($lsw >> 16); + + return ($msw << 16) | ($lsw & 0xFFFF); + } // -------------------------------------------------------------------- @@ -211,11 +211,11 @@ class CI_SHA { * @access private * @return integer */ - function _rol($num, $cnt) - { - return ($num << $cnt) | $this->_zero_fill($num, 32 - $cnt); - } - + function _rol($num, $cnt) + { + return ($num << $cnt) | $this->_zero_fill($num, 32 - $cnt); + } + // -------------------------------------------------------------------- /** @@ -224,26 +224,26 @@ class CI_SHA { * @access private * @return string */ - function _zero_fill($a, $b) - { - $bin = decbin($a); - - if (strlen($bin) < $b) - { - $bin = 0; - } - else - { - $bin = substr($bin, 0, strlen($bin) - $b); - } - - for ($i=0; $i < $b; $i++) - { - $bin = "0".$bin; - } - - return bindec($bin); - } + function _zero_fill($a, $b) + { + $bin = decbin($a); + + if (strlen($bin) < $b) + { + $bin = 0; + } + else + { + $bin = substr($bin, 0, strlen($bin) - $b); + } + + for ($i=0; $i < $b; $i++) + { + $bin = "0".$bin; + } + + return bindec($bin); + } } // END CI_SHA ?> \ No newline at end of file diff --git a/system/libraries/Table.php b/system/libraries/Table.php index c40c85e17..f3f9b32f6 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -7,17 +7,17 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.3.1 * @filesource */ - + // ------------------------------------------------------------------------ /** * HTML Table Generating Class - * + * * Lets you create tables manually or from database result objects, or arrays. * * @package CodeIgniter diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index 74649151d..6d5e206ff 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource @@ -19,7 +19,7 @@ * Trackback Class * * Trackback Sending/Receiving Class - * + * * @package CodeIgniter * @subpackage Libraries * @category Trackbacks @@ -57,7 +57,7 @@ class CI_Trackback { function send($tb_data) { if ( ! is_array($tb_data)) - { + { $this->set_error('The send() method must be passed an array'); return FALSE; } @@ -66,7 +66,7 @@ class CI_Trackback { foreach (array('url', 'title', 'excerpt', 'blog_name', 'ping_url') as $item) { if ( ! isset($tb_data[$item])) - { + { $this->set_error('Required item missing: '.$item); return FALSE; } @@ -104,7 +104,7 @@ 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); + $data = "url=".rawurlencode($url)."&title=".rawurlencode($title)."&blog_name=".rawurlencode($blog_name)."&excerpt=".rawurlencode($excerpt)."&charset=".rawurlencode($charset); // Send Trackback(s) $return = TRUE; @@ -170,7 +170,7 @@ class CI_Trackback { /** * Send Trackback Error Message * - * Allows custom errors to be set. By default it + * Allows custom errors to be set. By default it * sends the "incomplete information" error, as that's * the most common one. * @@ -220,7 +220,7 @@ class CI_Trackback { /** * Process Trackback * - * Opens a socket connection and passes the data to + * Opens a socket connection and passes the data to * the server. Returns true on success, false on failure * * @access public @@ -249,22 +249,22 @@ class CI_Trackback { { $data = "tb_id=".$id."&".$data; } - + // Transfer the data - fputs ($fp, "POST " . $path . " HTTP/1.0\r\n" ); - fputs ($fp, "Host: " . $target['host'] . "\r\n" ); - fputs ($fp, "Content-type: application/x-www-form-urlencoded\r\n" ); - fputs ($fp, "Content-length: " . strlen($data) . "\r\n" ); - fputs ($fp, "Connection: close\r\n\r\n" ); + fputs ($fp, "POST " . $path . " HTTP/1.0\r\n" ); + fputs ($fp, "Host: " . $target['host'] . "\r\n" ); + fputs ($fp, "Content-type: application/x-www-form-urlencoded\r\n" ); + fputs ($fp, "Content-length: " . strlen($data) . "\r\n" ); + fputs ($fp, "Connection: close\r\n\r\n" ); fputs ($fp, $data); - + // Was it successful? $this->response = ""; while(!feof($fp)) { $this->response .= fgets($fp, 128); - } + } @fclose($fp); if ( ! eregi("0", $this->response)) @@ -297,7 +297,7 @@ class CI_Trackback { * @return string */ function extract_urls($urls) - { + { // Remove the pesky white space and replace with a comma. $urls = preg_replace("/\s*(\S+)\s*/", "\\1,", $urls); @@ -316,7 +316,7 @@ class CI_Trackback { // Removes duplicates $urls = array_unique($urls); - array_walk($urls, array($this, 'validate_url')); + array_walk($urls, array($this, 'validate_url')); return $urls; } @@ -384,7 +384,7 @@ class CI_Trackback { } } - if ( ! preg_match ("/^([0-9]+)$/", $tb_id)) + if ( ! preg_match ("/^([0-9]+)$/", $tb_id)) { return false; } @@ -435,7 +435,7 @@ class CI_Trackback { */ function limit_characters($str, $n = 500, $end_char = '…') { - if (strlen($str) < $n) + if (strlen($str) < $n) { return $str; } @@ -453,7 +453,7 @@ class CI_Trackback { $out .= $val.' '; if (strlen($out) >= $n) { - return trim($out).$end_char; + return trim($out).$end_char; } } } @@ -475,11 +475,11 @@ class CI_Trackback { $count = 1; $out = ''; $temp = array(); - + for ($i = 0, $s = strlen($str); $i < $s; $i++) { $ordinal = ord($str[$i]); - + if ($ordinal < 128) { $out .= $str[$i]; @@ -490,9 +490,9 @@ class CI_Trackback { { $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); @@ -500,10 +500,10 @@ class CI_Trackback { $out .= '&#'.$number.';'; $count = 1; $temp = array(); - } - } + } + } } - + return $out; } diff --git a/system/libraries/URI.php b/system/libraries/URI.php index fcf6afe4b..10654a69c 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -7,17 +7,17 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** * URI Class - * + * * Parses URIs and determines routing * * @package CodeIgniter @@ -36,7 +36,7 @@ class CI_URI { * * Simply globalizes the $RTR object. The front * loads the Router class early on so it's not available - * normally as other classes are. + * normally as other classes are. * * @access public */ @@ -51,7 +51,7 @@ class CI_URI { /** * Fetch a URI Segment * - * This function returns the URI segment based on the number provided. + * This function returns the URI segment based on the number provided. * * @access public * @param integer @@ -87,7 +87,7 @@ class CI_URI { /** * Generate a key value pair from the URI string * - * This function generates and associative array of URI data starting + * This function generates and associative array of URI data starting * at the supplied segment. For example, if this is your URI: * * www.your-site.com/user/search/name/joe/location/UK/gender/male @@ -99,7 +99,7 @@ class CI_URI { * location => UK * gender => male * ) - * + * * @access public * @param integer the starting segment number * @param array an array of default values @@ -122,7 +122,7 @@ class CI_URI { /** * Generate a key value pair from the URI string or Re-routed URI string - * + * * @access private * @param integer the starting segment number * @param array an array of default values @@ -206,7 +206,7 @@ class CI_URI { /** * Generate a URI string from an associative array * - * + * * @access public * @param array an associative array of key/values * @return array diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 6bfc59dc3..f68f69e71 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -7,17 +7,17 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.3.1 * @filesource */ - + // ------------------------------------------------------------------------ /** * Unit Testing Class - * + * * Simple testing class * * @package CodeIgniter @@ -148,7 +148,7 @@ class CI_Unit_test { /** * Make Unit testing active * - * Enables/disables unit testing + * Enables/disables unit testing * * @access public * @param bool @@ -233,14 +233,14 @@ class CI_Unit_test { /** * Generate a backtrace * - * This lets us show file names and line numbers + * This lets us show file names and line numbers * * @access private * @return array */ - function _backtrace() + function _backtrace() { - if (function_exists('debug_backtrace')) + if (function_exists('debug_backtrace')) { $back = debug_backtrace(); @@ -314,7 +314,7 @@ class CI_Unit_test { /** * Helper functions to test boolean true/false - * + * * * @access private * @return bool diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 09a479431..1a0b0fc8f 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource @@ -17,7 +17,7 @@ /** * File Uploading Class - * + * * @package CodeIgniter * @subpackage Libraries * @category Uploads @@ -43,7 +43,7 @@ class CI_Upload { var $image_width = ''; var $image_height = ''; var $image_type = ''; - var $image_size_str = ''; + var $image_size_str = ''; var $error_msg = array(); var $mimes = array(); var $remove_spaces = TRUE; @@ -75,7 +75,7 @@ class CI_Upload { * @return void */ function initialize($config = array()) - { + { foreach ($config as $key => $val) { $method = 'set_'.$key; @@ -98,41 +98,41 @@ class CI_Upload { * @access public * @return bool */ - function do_upload($field = 'userfile') - { + function do_upload($field = 'userfile') + { // Is $_FILES[$field] set? If not, no reason to continue. - if ( ! isset($_FILES[$field])) - { + if ( ! isset($_FILES[$field])) + { $this->set_error('upload_userfile_not_set'); return FALSE; - } - + } + // Is the upload path valid? if ( ! $this->validate_upload_path()) { return FALSE; } - + // Was the file able to be uploaded? If not, determine the reason why. - if ( ! is_uploaded_file($_FILES[$field]['tmp_name'])) - { - $error = ( ! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error']; - - switch($error) - { - case 1 : $this->set_error('upload_file_exceeds_limit'); - break; - case 3 : $this->set_error('upload_file_partial'); - break; - case 4 : $this->set_error('upload_no_file_selected'); - break; - default : $this->set_error('upload_no_file_selected'); - break; - } - - return FALSE; - } - + if ( ! is_uploaded_file($_FILES[$field]['tmp_name'])) + { + $error = ( ! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error']; + + switch($error) + { + case 1 : $this->set_error('upload_file_exceeds_limit'); + break; + case 3 : $this->set_error('upload_file_partial'); + break; + case 4 : $this->set_error('upload_no_file_selected'); + break; + default : $this->set_error('upload_no_file_selected'); + break; + } + + return FALSE; + } + // Set the uploaded data as class variables $this->file_temp = $_FILES[$field]['tmp_name']; $this->file_name = $_FILES[$field]['name']; @@ -148,36 +148,36 @@ class CI_Upload { } // Is the file type allowed to be uploaded? - if ( ! $this->is_allowed_filetype()) - { + if ( ! $this->is_allowed_filetype()) + { $this->set_error('upload_invalid_filetype'); return FALSE; - } + } // Is the file size within the allowed maximum? - if ( ! $this->is_allowed_filesize()) - { + if ( ! $this->is_allowed_filesize()) + { $this->set_error('upload_invalid_filesize'); - return FALSE; - } - + return FALSE; + } + // Are the image dimensions within the allowed size? // Note: This can fail if the server has an open_basdir restriction. - if ( ! $this->is_allowed_dimensions()) - { + if ( ! $this->is_allowed_dimensions()) + { $this->set_error('upload_invalid_dimensions'); - return FALSE; - } - + return FALSE; + } + // Sanitize the file name for security - $this->file_name = $this->clean_file_name($this->file_name); - + $this->file_name = $this->clean_file_name($this->file_name); + // Remove white spaces in the name - if ($this->remove_spaces == TRUE) - { - $this->file_name = preg_replace("/\s+/", "_", $this->file_name); - } - + if ($this->remove_spaces == TRUE) + { + $this->file_name = preg_replace("/\s+/", "_", $this->file_name); + } + /* * Validate the file name * This function appends an number onto the end of @@ -195,7 +195,7 @@ class CI_Upload { return FALSE; } } - + /* * Move the file to the final destination * To deal with different server configurations @@ -204,42 +204,42 @@ class CI_Upload { * reliably work in most environments */ if ( ! @copy($this->file_temp, $this->file_path.$this->file_name)) - { + { if ( ! @move_uploaded_file($this->file_temp, $this->file_path.$this->file_name)) { $this->set_error('upload_destination_error'); return FALSE; } - } + } /* * Run the file through the XSS hacking filter * This helps prevent malicious code from being - * embedded within a file. Scripts can easily + * embedded within a file. Scripts can easily * be disguised as images or other file types. */ if ($this->xss_clean == TRUE) { $this->do_xss_clean(); } - + /* * Set the finalized image dimensions * This sets the image width/height (assuming the * file was an image). We use this information * in the "data" function. */ - $this->set_image_properties($this->file_path.$this->file_name); - + $this->set_image_properties($this->file_path.$this->file_name); + return TRUE; - } + } // -------------------------------------------------------------------- /** - * Finalized Data Array + * Finalized Data Array * - * Returns an associative array containing all of the information + * Returns an associative array containing all of the information * related to the upload, allowing the developer easy access in one array. * * @access public @@ -267,24 +267,24 @@ class CI_Upload { // -------------------------------------------------------------------- /** - * Set Upload Path + * Set Upload Path * * @access public * @param string * @return void */ - function set_upload_path($path) - { + function set_upload_path($path) + { $this->file_path = $path; } // -------------------------------------------------------------------- /** - * Set the file name + * Set the file name * - * This function takes a filename/path as input and looks for the - * existence of a file with the same name. If found, it will append a + * This function takes a filename/path as input and looks for the + * existence of a file with the same name. If found, it will append a * number to the end of the filename to avoid overwriting a pre-existing file. * * @access public @@ -331,58 +331,58 @@ class CI_Upload { // -------------------------------------------------------------------- /** - * Set Maximum File Size + * Set Maximum File Size * * @access public * @param integer * @return void */ - function set_max_filesize($n) - { - $this->max_size = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; - } + function set_max_filesize($n) + { + $this->max_size = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + } // -------------------------------------------------------------------- /** - * Set Maximum Image Width + * Set Maximum Image Width * * @access public * @param integer * @return void */ - function set_max_width($n) - { - $this->max_width = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; - } + function set_max_width($n) + { + $this->max_width = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + } // -------------------------------------------------------------------- /** - * Set Maximum Image Height + * Set Maximum Image Height * * @access public * @param integer * @return void */ - function set_max_height($n) - { - $this->max_height = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; - } + function set_max_height($n) + { + $this->max_height = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + } // -------------------------------------------------------------------- /** - * Set Allowed File Types + * Set Allowed File Types * * @access public * @param string * @return void */ - function set_allowed_types($types) - { - $this->allowed_types = explode('|', $types); - } + function set_allowed_types($types) + { + $this->allowed_types = explode('|', $types); + } // -------------------------------------------------------------------- @@ -395,26 +395,26 @@ class CI_Upload { * @param string * @return void */ - function set_image_properties($path = '') - { - if ( ! $this->is_image()) - { - return; - } - - if (function_exists('getimagesize')) - { - if (FALSE !== ($D = @getimagesize($path))) - { + function set_image_properties($path = '') + { + if ( ! $this->is_image()) + { + return; + } + + if (function_exists('getimagesize')) + { + if (FALSE !== ($D = @getimagesize($path))) + { $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); - + $this->image_width = $D['0']; $this->image_height = $D['1']; $this->image_type = ( ! isset($types[$D['2']])) ? 'unknown' : $types[$D['2']]; $this->image_size_str = $D['3']; // string containing height and width } - } - } + } + } // -------------------------------------------------------------------- @@ -441,21 +441,21 @@ class CI_Upload { * @access public * @return bool */ - function is_image() - { - $img_mimes = array( - 'image/gif', - 'image/jpg', - 'image/jpe', - 'image/jpeg', - 'image/pjpeg', - 'image/png', - 'image/x-png' - ); - + function is_image() + { + $img_mimes = array( + 'image/gif', + 'image/jpg', + 'image/jpe', + 'image/jpeg', + 'image/pjpeg', + 'image/png', + 'image/x-png' + ); + return (in_array($this->file_type, $img_mimes, TRUE)) ? TRUE : FALSE; - } + } // -------------------------------------------------------------------- @@ -465,36 +465,36 @@ class CI_Upload { * @access public * @return bool */ - function is_allowed_filetype() - { - if (count($this->allowed_types) == 0) - { + function is_allowed_filetype() + { + if (count($this->allowed_types) == 0) + { $this->set_error('upload_no_file_types'); return FALSE; - } - - foreach ($this->allowed_types as $val) - { - $mime = $this->mimes_types(strtolower($val)); - - if (is_array($mime)) - { - if (in_array($this->file_type, $mime, TRUE)) - { - return TRUE; - } - } - else - { + } + + foreach ($this->allowed_types as $val) + { + $mime = $this->mimes_types(strtolower($val)); + + if (is_array($mime)) + { + if (in_array($this->file_type, $mime, TRUE)) + { + return TRUE; + } + } + else + { if ($mime == $this->file_type) { return TRUE; } - } - } - - return FALSE; - } + } + } + + return FALSE; + } // -------------------------------------------------------------------- @@ -504,17 +504,17 @@ class CI_Upload { * @access public * @return bool */ - function is_allowed_filesize() - { - if ($this->max_size != 0 AND $this->file_size > $this->max_size) - { - return FALSE; - } - else - { - return TRUE; - } - } + function is_allowed_filesize() + { + if ($this->max_size != 0 AND $this->file_size > $this->max_size) + { + return FALSE; + } + else + { + return TRUE; + } + } // -------------------------------------------------------------------- @@ -524,37 +524,37 @@ class CI_Upload { * @access public * @return bool */ - function is_allowed_dimensions() - { - if ( ! $this->is_image()) - { - return TRUE; - } - - if (function_exists('getimagesize')) - { - $D = @getimagesize($this->file_temp); - - if ($this->max_width > 0 AND $D['0'] > $this->max_width) - { - return FALSE; - } - - if ($this->max_height > 0 AND $D['1'] > $this->max_height) - { - return FALSE; - } - - return TRUE; - } - - return TRUE; - } + function is_allowed_dimensions() + { + if ( ! $this->is_image()) + { + return TRUE; + } + + if (function_exists('getimagesize')) + { + $D = @getimagesize($this->file_temp); + + if ($this->max_width > 0 AND $D['0'] > $this->max_width) + { + return FALSE; + } + + if ($this->max_height > 0 AND $D['1'] > $this->max_height) + { + return FALSE; + } + + return TRUE; + } + + return TRUE; + } // -------------------------------------------------------------------- /** - * Validate Upload Path + * Validate Upload Path * * Verifies that it is a valid upload path with proper permissions. * @@ -562,34 +562,34 @@ class CI_Upload { * @access public * @return bool */ - function validate_upload_path() - { - if ($this->file_path == '') - { + function validate_upload_path() + { + if ($this->file_path == '') + { $this->set_error('upload_no_filepath'); return FALSE; - } - + } + if (function_exists('realpath') AND @realpath($this->file_path) !== FALSE) { - $this->file_path = str_replace("\\", "/", realpath($this->file_path)); + $this->file_path = str_replace("\\", "/", realpath($this->file_path)); } - - if ( ! @is_dir($this->file_path)) - { + + if ( ! @is_dir($this->file_path)) + { $this->set_error('upload_no_filepath'); return FALSE; - } - - if ( ! is_writable($this->file_path)) - { + } + + if ( ! is_writable($this->file_path)) + { $this->set_error('upload_not_writable'); return FALSE; - } - + } + $this->file_path = preg_replace("/(.+?)\/*$/", "\\1/", $this->file_path); return TRUE; - } + } // -------------------------------------------------------------------- @@ -617,7 +617,7 @@ class CI_Upload { */ function clean_file_name($filename) { - $bad = array( + $bad = array( "", "'", @@ -636,21 +636,21 @@ class CI_Upload { "%253c", // < "%3e", // > "%0e", // > - "%28", // ( - "%29", // ) + "%28", // ( + "%29", // ) "%2528", // ( "%26", // & "%24", // $ "%3f", // ? "%3b", // ; "%3d" // = - ); - - foreach ($bad as $val) - { - $filename = str_replace($val, '', $filename); - } - + ); + + foreach ($bad as $val) + { + $filename = str_replace($val, '', $filename); + } + return $filename; } @@ -659,7 +659,7 @@ class CI_Upload { /** * Runs the file through the XSS clean function * - * This prevents people from embedding malicious code in their files. + * This prevents people from embedding malicious code in their files. * I'm not sure that it won't negatively affect certain files in unexpected ways, * but so far I haven't found that it causes trouble. * @@ -670,7 +670,7 @@ class CI_Upload { { $file = $this->file_path.$this->file_name; - if (filesize($file) == 0) + if (filesize($file) == 0) { return FALSE; } @@ -680,16 +680,16 @@ class CI_Upload { return FALSE; } - flock($fp, LOCK_EX); + flock($fp, LOCK_EX); - $data = fread($fp, filesize($file)); + $data = fread($fp, filesize($file)); $CI =& get_instance(); $data = $CI->input->xss_clean($data); - fwrite($fp, $data); - flock($fp, LOCK_UN); - fclose($fp); + fwrite($fp, $data); + flock($fp, LOCK_UN); + fclose($fp); } // -------------------------------------------------------------------- diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 11c2baa68..b217367fe 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -7,17 +7,17 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** * User Agent Class - * + * * Identifies the platform, browser, robot, or mobile devise of the browsing agent * * @package CodeIgniter @@ -155,9 +155,9 @@ class CI_User_agent { { if (is_array($this->platforms) AND count($this->platforms) > 0) { - foreach ($this->platforms as $key => $val) + foreach ($this->platforms as $key => $val) { - if (preg_match("|".preg_quote($key)."|i", $this->agent)) + if (preg_match("|".preg_quote($key)."|i", $this->agent)) { $this->platform = $val; return TRUE; @@ -179,9 +179,9 @@ class CI_User_agent { { if (is_array($this->browsers) AND count($this->browsers) > 0) { - foreach ($this->browsers as $key => $val) + foreach ($this->browsers as $key => $val) { - if (preg_match("|".preg_quote($key).".*?([0-9\.]+)|i", $this->agent, $match)) + if (preg_match("|".preg_quote($key).".*?([0-9\.]+)|i", $this->agent, $match)) { $this->is_browser = TRUE; $this->version = $match[1]; @@ -205,9 +205,9 @@ class CI_User_agent { { if (is_array($this->robots) AND count($this->robots) > 0) { - foreach ($this->robots as $key => $val) + foreach ($this->robots as $key => $val) { - if (preg_match("|".preg_quote($key)."|i", $this->agent)) + if (preg_match("|".preg_quote($key)."|i", $this->agent)) { $this->is_robot = TRUE; $this->robot = $val; @@ -230,7 +230,7 @@ class CI_User_agent { { if (is_array($this->mobiles) AND count($this->mobiles) > 0) { - foreach ($this->mobiles as $key => $val) + foreach ($this->mobiles as $key => $val) { if (FALSE !== (strpos(strtolower($this->agent), $key))) { diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 07ca35a33..ec7e412c6 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource @@ -17,7 +17,7 @@ /** * Validation Class - * + * * @package CodeIgniter * @subpackage Libraries * @category Validation @@ -40,7 +40,7 @@ class CI_Validation { /** - * Constructor + * Constructor * */ function CI_Validation() @@ -102,7 +102,7 @@ class CI_Validation { /** * Set Rules * - * This function takes an array of field names and validation + * This function takes an array of field names and validation * rules as input ad simply stores is for use later. * * @access public @@ -131,7 +131,7 @@ class CI_Validation { /** * Set Error Message * - * Lets users set their own error messages on the fly. Note: The key + * Lets users set their own error messages on the fly. Note: The key * name has to match the function name that it corresponds to. * * @access public @@ -216,7 +216,7 @@ class CI_Validation { { if (in_array('isset', $ex, TRUE) OR in_array('required', $ex)) { - if ( ! isset($this->_error_messages['isset'])) + if ( ! isset($this->_error_messages['isset'])) { if (FALSE === ($line = $this->CI->lang->line('isset'))) { @@ -308,7 +308,7 @@ class CI_Validation { // Did the rule test negatively? If so, grab the error. if ($result === FALSE) { - if ( ! isset($this->_error_messages[$rule])) + if ( ! isset($this->_error_messages[$rule])) { if (FALSE === ($line = $this->CI->lang->line($rule))) { @@ -352,7 +352,7 @@ class CI_Validation { } $this->set_fields(); - + // Did we end up with any errors? if ($total_errors == 0) { @@ -653,15 +653,15 @@ class CI_Validation { * @param string * @return string */ - function prep_for_form($str = '') - { - if ($this->_safe_form_data == FALSE OR $str == '') - { - return $str; - } - + function prep_for_form($str = '') + { + if ($this->_safe_form_data == FALSE OR $str == '') + { + return $str; + } + return str_replace(array("'", '"', '<', '>'), array("'", """, '<', '>'), stripslashes($str)); - } + } // -------------------------------------------------------------------- @@ -672,8 +672,8 @@ class CI_Validation { * @param string * @return string */ - function prep_url($str = '') - { + function prep_url($str = '') + { if ($str == 'http://' OR $str == '') { $_POST[$this->_current_field] = ''; @@ -686,7 +686,7 @@ class CI_Validation { } $_POST[$this->_current_field] = $str; - } + } // -------------------------------------------------------------------- @@ -697,10 +697,10 @@ class CI_Validation { * @param string * @return string */ - function strip_image_tags($str) - { - $_POST[$this->_current_field] = $this->input->strip_image_tags($str); - } + function strip_image_tags($str) + { + $_POST[$this->_current_field] = $this->input->strip_image_tags($str); + } // -------------------------------------------------------------------- @@ -725,9 +725,9 @@ class CI_Validation { * @param string * @return string */ - function encode_php_tags($str) - { - $_POST[$this->_current_field] = str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); + function encode_php_tags($str) + { + $_POST[$this->_current_field] = str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); } } diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 0a3dedae1..2d9a4c11b 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -7,15 +7,15 @@ * @package CodeIgniter * @author Rick Ellis, Paul Burdick * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + if ( ! function_exists('xml_parser_create')) { - show_error('Your PHP installation does not support XML'); + show_error('Your PHP installation does not support XML'); } @@ -23,7 +23,7 @@ if ( ! function_exists('xml_parser_create')) /** * XML-RPC request handler class - * + * * @package CodeIgniter * @subpackage Libraries * @category XML-RPC @@ -33,7 +33,7 @@ if ( ! function_exists('xml_parser_create')) class CI_Xmlrpc { var $debug = FALSE; // Debugging on or off - var $xmlrpcI4 = 'i4'; + var $xmlrpcI4 = 'i4'; var $xmlrpcInt = 'int'; var $xmlrpcBoolean = 'boolean'; var $xmlrpcDouble = 'double'; @@ -65,10 +65,10 @@ class CI_Xmlrpc { //------------------------------------- - // VALUES THAT MULTIPLE CLASSES NEED - //------------------------------------- + // VALUES THAT MULTIPLE CLASSES NEED + //------------------------------------- - function CI_Xmlrpc ($config = array()) + function CI_Xmlrpc ($config = array()) { $this->xmlrpcName = $this->xmlrpcName; @@ -76,14 +76,14 @@ class CI_Xmlrpc { // Types for info sent back and forth $this->xmlrpcTypes = array( - $this->xmlrpcI4 => '1', - $this->xmlrpcInt => '1', + $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->xmlrpcArray => '2', $this->xmlrpcStruct => '3' ); @@ -129,10 +129,10 @@ class CI_Xmlrpc { //------------------------------------- - // Initialize Prefs - //------------------------------------- + // Initialize Prefs + //------------------------------------- - function initialize($config = array()) + function initialize($config = array()) { if (sizeof($config) > 0) { @@ -148,10 +148,10 @@ class CI_Xmlrpc { // END //------------------------------------- - // Take URL and parse it - //------------------------------------- + // Take URL and parse it + //------------------------------------- - function server($url, $port=80) + function server($url, $port=80) { if (substr($url, 0, 4) != "http") { @@ -173,9 +173,9 @@ class CI_Xmlrpc { //------------------------------------- // Set Timeout - //------------------------------------- + //------------------------------------- - function timeout($seconds=5) + function timeout($seconds=5) { if ( ! is_null($this->client) && is_int($seconds)) { @@ -186,9 +186,9 @@ class CI_Xmlrpc { //------------------------------------- // Set Methods - //------------------------------------- + //------------------------------------- - function method($function) + function method($function) { $this->method = $function; } @@ -196,9 +196,9 @@ class CI_Xmlrpc { //------------------------------------- // Take Array of Data and Create Objects - //------------------------------------- + //------------------------------------- - function request($incoming) + function request($incoming) { if ( ! is_array($incoming)) { @@ -215,7 +215,7 @@ class CI_Xmlrpc { //------------------------------------- // Set Debug - //------------------------------------- + //------------------------------------- function set_debug($flag = TRUE) { @@ -224,7 +224,7 @@ class CI_Xmlrpc { //------------------------------------- // Values Parsing - //------------------------------------- + //------------------------------------- function values_parsing($value, $return = FALSE) { @@ -260,9 +260,9 @@ class CI_Xmlrpc { //------------------------------------- // Sends XML-RPC Request - //------------------------------------- + //------------------------------------- - function send_request() + function send_request() { $this->message = new XML_RPC_Message($this->method,$this->data); $this->message->debug = $this->debug; @@ -286,9 +286,9 @@ class CI_Xmlrpc { //------------------------------------- // Returns Error - //------------------------------------- + //------------------------------------- - function display_error() + function display_error() { return $this->error; } @@ -296,9 +296,9 @@ class CI_Xmlrpc { //------------------------------------- // Returns Remote Server Response - //------------------------------------- + //------------------------------------- - function display_response() + function display_response() { return $this->response; } @@ -306,7 +306,7 @@ class CI_Xmlrpc { //------------------------------------- // Sends an Error Message for Server Request - //------------------------------------- + //------------------------------------- function send_error_message($number, $message) { @@ -317,7 +317,7 @@ class CI_Xmlrpc { //------------------------------------- // Send Response for Server Request - //------------------------------------- + //------------------------------------- function send_response($response) { @@ -336,7 +336,7 @@ class CI_Xmlrpc { /** * XML-RPC Client class - * + * * @category XML-RPC * @author Paul Burdick * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html @@ -355,8 +355,8 @@ class XML_RPC_Client extends CI_Xmlrpc { parent::CI_Xmlrpc(); - $this->port = $port; - $this->server = $server; + $this->port = $port; + $this->server = $server; $this->path = $path; } @@ -414,7 +414,7 @@ class XML_RPC_Client extends CI_Xmlrpc /** * XML-RPC Response class - * + * * @category XML-RPC * @author Paul Burdick * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html @@ -432,7 +432,7 @@ class XML_RPC_Response { // error $this->errno = $code; - $this->errstr = htmlentities($fstr); + $this->errstr = htmlentities($fstr); } else if (!is_object($val)) { @@ -484,7 +484,7 @@ class XML_RPC_Response else { $result .= "\n\n" . - $this->val->serialize_class() . + $this->val->serialize_class() . "\n"; } $result .= "\n"; @@ -532,7 +532,7 @@ class XML_RPC_Response //------------------------------------- // XML-RPC Object to PHP Types - //------------------------------------- + //------------------------------------- function xmlrpc_decoder($xmlrpc_val) { @@ -554,7 +554,7 @@ class XML_RPC_Response { $arr[] = $this->xmlrpc_decoder($xmlrpc_val->me['array'][$i]); } - return $arr; + return $arr; } elseif($kind == 'struct') { @@ -572,7 +572,7 @@ class XML_RPC_Response //------------------------------------- // ISO-8601 time to server or UTC time - //------------------------------------- + //------------------------------------- function iso8601_decode($time, $utc=0) { @@ -584,7 +584,7 @@ class XML_RPC_Response $t = gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); else $t = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); - } + } return $t; } @@ -594,7 +594,7 @@ class XML_RPC_Response /** * XML-RPC Message class - * + * * @category XML-RPC * @author Paul Burdick * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html @@ -623,7 +623,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- // Create Payload to Send - //------------------------------------- + //------------------------------------- function createPayload() { @@ -643,7 +643,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- // Parse External XML-RPC Server's Response - //------------------------------------- + //------------------------------------- function parseResponse($fp) { @@ -667,7 +667,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- // Check for data - //------------------------------------- + //------------------------------------- if($data == "") { @@ -679,7 +679,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- // Check for HTTP 200 Response - //------------------------------------- + //------------------------------------- if(ereg("^HTTP",$data) && !ereg("^HTTP/[0-9\.]+ 200 ", $data)) { @@ -690,7 +690,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- // Create and Set Up XML Parser - //------------------------------------- + //------------------------------------- $parser = xml_parser_create($this->xmlrpc_defencoding); @@ -711,7 +711,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- // GET HEADERS - //------------------------------------- + //------------------------------------- $lines = explode("\r\n", $data); while (($line = array_shift($lines))) @@ -790,7 +790,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- // SEND RESPONSE - //------------------------------------- + //------------------------------------- $v = $this->xh[$parser]['value']; @@ -825,7 +825,7 @@ class XML_RPC_Message extends CI_Xmlrpc // ac - used to accumulate values // isf - used to indicate a fault // lv - used to indicate "looking for a value": implements - // the logic to allow values with no types to be strings + // the logic to allow values with no types to be strings // params - used to store parameters in method calls // method - used to store method name // stack - array with parent tree of the xml element, @@ -833,7 +833,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- // Start Element Handler - //------------------------------------- + //------------------------------------- function open_tag($the_parser, $name, $attrs) { @@ -870,7 +870,7 @@ class XML_RPC_Message extends CI_Xmlrpc $cur_val = array('value' => array(), 'type' => $name); - + array_unshift($this->xh[$the_parser]['valuestack'], $cur_val); break; case 'METHODNAME': @@ -935,7 +935,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- // End Element Handler - //------------------------------------- + //------------------------------------- function closing_tag($the_parser, $name) { @@ -974,7 +974,7 @@ class XML_RPC_Message extends CI_Xmlrpc } elseif ($name=='DATETIME.ISO8601') { - $this->xh[$the_parser]['vt'] = $this->xmlrpcDateTime; + $this->xh[$the_parser]['vt'] = $this->xmlrpcDateTime; $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; } elseif ($name=='BASE64') @@ -1041,7 +1041,7 @@ class XML_RPC_Message extends CI_Xmlrpc else { // Struct - $this->xh[$the_parser]['value'] = $temp; + $this->xh[$the_parser]['value'] = $temp; } break; case 'MEMBER': @@ -1079,7 +1079,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- // Parses Character Data - //------------------------------------- + //------------------------------------- function character_data($the_parser, $data) { @@ -1130,21 +1130,21 @@ class XML_RPC_Message extends CI_Xmlrpc $parameters = array(); for ($i = 0; $i < sizeof($this->params); $i++) - { - $a_param = $this->decode_message($this->params[$i]); - - if (is_array($a_param)) - { - $parameters[] = $this->output_parameters($a_param); - } - else - { - $parameters[] = $CI->input->xss_clean($a_param); - } - } - } - - return $parameters; + { + $a_param = $this->decode_message($this->params[$i]); + + if (is_array($a_param)) + { + $parameters[] = $this->output_parameters($a_param); + } + else + { + $parameters[] = $CI->input->xss_clean($a_param); + } + } + } + + return $parameters; } @@ -1168,7 +1168,7 @@ class XML_RPC_Message extends CI_Xmlrpc $arr[] = $this->decode_message($param->me['array'][$i]); } - return $arr; + return $arr; } elseif($kind == 'struct') { @@ -1191,7 +1191,7 @@ class XML_RPC_Message extends CI_Xmlrpc /** * XML-RPC Values class - * + * * @category XML-RPC * @author Paul Burdick * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html @@ -1387,7 +1387,7 @@ class XML_RPC_Values extends CI_Xmlrpc //------------------------------------- // Encode time in ISO-8601 form. - //------------------------------------- + //------------------------------------- // Useful for sending time in XML-RPC diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index e4d3cffde..bdb058e82 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis, Paul Burdick * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource @@ -15,19 +15,19 @@ if ( ! function_exists('xml_parser_create')) { - show_error('Your PHP installation does not support XML'); + show_error('Your PHP installation does not support XML'); } if ( ! class_exists('CI_Xmlrpc')) { - show_error('You must load the Xmlrpc class before loading the Xmlrpcs class in order to create a server.'); + show_error('You must load the Xmlrpc class before loading the Xmlrpcs class in order to create a server.'); } // ------------------------------------------------------------------------ /** * XML-RPC server class - * + * * @package CodeIgniter * @subpackage Libraries * @category XML-RPC @@ -44,7 +44,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Constructor, more or less - //------------------------------------- + //------------------------------------- function CI_Xmlrpcs($config=array()) { @@ -61,7 +61,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Initialize Prefs and Serve - //------------------------------------- + //------------------------------------- function initialize($config=array()) { @@ -78,7 +78,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Setting of System Methods - //------------------------------------- + //------------------------------------- function set_system_methods () { @@ -105,7 +105,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Main Server Function - //------------------------------------- + //------------------------------------- function serve() { @@ -121,7 +121,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Add Method to Class - //------------------------------------- + //------------------------------------- function add_to_map($methodname,$function,$sig,$doc) { @@ -135,7 +135,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Parse Server Request - //------------------------------------- + //------------------------------------- function parseRequest($data='') { @@ -143,7 +143,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Get Data - //------------------------------------- + //------------------------------------- if ($data == '') { @@ -153,7 +153,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Set up XML Parser - //------------------------------------- + //------------------------------------- $parser = xml_parser_create($this->xmlrpc_defencoding); $parser_object = new XML_RPC_Message("filler"); @@ -221,7 +221,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc // SET DEBUGGING MESSAGE //------------------------------------- - if ($this->debug === TRUE) + if ($this->debug === TRUE) { $this->debug_msg = "\n"; } @@ -231,7 +231,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Executes the Method - //------------------------------------- + //------------------------------------- function _execute($m) { @@ -244,7 +244,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Check for Function - //------------------------------------- + //------------------------------------- if (!isset($methods[$methName]['function'])) { @@ -275,7 +275,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Checking Methods Signature - //------------------------------------- + //------------------------------------- if (isset($methods[$methName]['signature'])) { @@ -298,7 +298,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc return new XML_RPC_Response(0, $this->xmlrpcerr['incorrect_params'], - $this->xmlrpcstr['incorrect_params'] . + $this->xmlrpcstr['incorrect_params'] . ": Wanted {$wanted}, got {$pt} at param {$pno})"); } } @@ -308,7 +308,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Calls the Function - //------------------------------------- + //------------------------------------- if ($objectCall) { @@ -334,7 +334,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Server Function: List Methods - //------------------------------------- + //------------------------------------- function listMethods($m) { @@ -356,7 +356,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Server Function: Return Signature for Method - //------------------------------------- + //------------------------------------- function methodSignature($m) { @@ -398,7 +398,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Server Function: Doc String for Method - //------------------------------------- + //------------------------------------- function methodHelp($m) { @@ -421,7 +421,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Server Function: Multi-call - //------------------------------------- + //------------------------------------- function multicall($m) { @@ -441,7 +441,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Multi-call Function: Error Handling - //------------------------------------- + //------------------------------------- function multicall_error($err) { @@ -457,7 +457,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Multi-call Function: Processes method - //------------------------------------- + //------------------------------------- function do_multicall($call) { @@ -469,7 +469,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc list($scalar_type,$scalar_value)=each($methName->me); $scalar_type = $scalar_type == $this->xmlrpcI4 ? $this->xmlrpcInt : $scalar_type; - if ($methName->kindOf() != 'scalar' || $scalar_type != 'string') + if ($methName->kindOf() != 'scalar' || $scalar_type != 'string') return $this->multicall_error('notstring'); elseif ($scalar_value == 'system.multicall') return $this->multicall_error('recursion'); diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 6af1ca979..092f9f378 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -21,16 +21,16 @@ * This class is based on a library I found at Zend: * http://www.zend.com/codex.php?id=696&single=1 * - * The original library is a little rough around the edges so I + * The original library is a little rough around the edges so I * refactored it and added several additional methods -- Rick Ellis - * + * * @package CodeIgniter * @subpackage Libraries * @category Encryption * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/general/encryption.html */ -class CI_Zip { +class CI_Zip { var $zipfile = ''; var $zipdata = array(); @@ -53,7 +53,7 @@ class CI_Zip { * @param mixed the directory name. Can be string or array * @return void */ - function add_dir($directory) + function add_dir($directory) { foreach ((array)$directory as $dir) { @@ -75,9 +75,9 @@ class CI_Zip { * @param string the directory name * @return void */ - function _add_dir($dir) + function _add_dir($dir) { - $dir = str_replace("\\", "/", $dir); + $dir = str_replace("\\", "/", $dir); $this->zipdata[] = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" .pack('V', 0) @@ -88,7 +88,7 @@ class CI_Zip { .$dir .pack('V', 0) .pack('V', 0) - .pack('V', 0); + .pack('V', 0); $newoffset = strlen(implode('', $this->zipdata)); @@ -106,7 +106,7 @@ class CI_Zip { .$dir; $this->offset = $newoffset; - $this->directory[] = $record; + $this->directory[] = $record; } // -------------------------------------------------------------------- @@ -150,14 +150,14 @@ class CI_Zip { */ function _add_data($filepath, $data) { - $filepath = str_replace("\\", "/", $filepath); + $filepath = str_replace("\\", "/", $filepath); - $oldlen = strlen($data); - $crc32 = crc32($data); + $oldlen = strlen($data); + $crc32 = crc32($data); $gzdata = gzcompress($data); $gzdata = substr(substr($gzdata, 0, strlen($gzdata) - 4), 2); - $newlen = strlen($gzdata); + $newlen = strlen($gzdata); $this->zipdata[] = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" .pack('V', $crc32) @@ -169,7 +169,7 @@ class CI_Zip { .$gzdata .pack('V', $crc32) .pack('V', $newlen) - .pack('V', $oldlen); + .pack('V', $oldlen); $newoffset = strlen(implode("", $this->zipdata)); @@ -183,10 +183,10 @@ class CI_Zip { .pack('v', 0) .pack('v', 0) .pack('V', 32) - .pack('V', $this->offset); + .pack('V', $this->offset); $this->offset = $newoffset; - $this->directory[] = $record.$filepath; + $this->directory[] = $record.$filepath; } // -------------------------------------------------------------------- @@ -198,7 +198,7 @@ class CI_Zip { * @return binary string */ function get_zip() - { + { // We cache the zip data so multiple calls // do not require recompiling if ($this->zipfile != '') @@ -212,8 +212,8 @@ class CI_Zip { return FALSE; } - $data = implode('', $this->zipdata); - $dir = implode('', $this->directory); + $data = implode('', $this->zipdata); + $dir = implode('', $this->directory); $this->zipfile = $data.$dir."\x50\x4b\x05\x06\x00\x00\x00\x00" .pack('v', sizeof($this->directory)) @@ -278,8 +278,8 @@ class CI_Zip { header("Content-Transfer-Encoding: binary"); header('Pragma: public'); header("Content-Length: ".strlen($this->get_zip())); - } - else + } + else { header('Content-Type: application/x-zip'); header('Content-Disposition: attachment; filename="'.$filename.'"'); @@ -297,7 +297,7 @@ class CI_Zip { /** * Initialize Data * - * Lets you clear current zip data. Useful if you need to create + * Lets you clear current zip data. Useful if you need to create * multiple zips with different data. * * @access public -- cgit v1.2.3-24-g4f1b From 36e644241623461d6ac9531bdc5a61ee40b28be4 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 22 Oct 2006 01:30:50 +0000 Subject: --- system/libraries/Session.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 96a0c43b2..c1fc345d9 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -110,8 +110,10 @@ class CI_Session { } } - // Do we need encryption? - if ($this->CI->config->item('sess_encrypt_cookie') == TRUE) + // Do we need encryption? + $this->encryption = $this->CI->config->item('sess_encrypt_cookie'); + + if ($this->encryption == TRUE) { $this->CI->load->library('encrypt'); } -- cgit v1.2.3-24-g4f1b From ca3dafb5ad0f04147128be596c872c156e176594 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 23 Oct 2006 01:24:11 +0000 Subject: --- system/libraries/Loader.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 7a1fd6802..aaeee7f6b 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -701,9 +701,9 @@ class CI_Loader { function _ci_init_class($class, $prefix = '', $config = FALSE) { // Is there an associated config file for this class? - if ($config !== NULL) + if ($config === NULL) { - $cong = NULL; + $config = NULL; if (file_exists(APPPATH.'config/'.$class.EXT)) { include_once(APPPATH.'config/'.$class.EXT); -- cgit v1.2.3-24-g4f1b From b6224a136c3fc2893e7f1bd3005959fab4008a47 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 23 Oct 2006 01:25:46 +0000 Subject: --- system/libraries/Router.php | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 17a441c77..d4d1b2fdb 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -319,16 +319,6 @@ class CI_Router { { return $path; } - - // OK, how about REQUEST_URI? - // Note: REQUEST_URI is not supplied in a consistent manner with all platforms so it's - // a difficult variable to use. We'll try to parse it out correctly. Hopefully one - // of the other variables above was available. - $path = $this->_parse_request_uri(); - if ($path != "") - { - return $path; - } // We've exhausted all our options... return ''; -- cgit v1.2.3-24-g4f1b From 5725a40301b3aceab1b838e33d003ecaf7ab113e Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 23 Oct 2006 20:02:04 +0000 Subject: --- system/libraries/Zip.php | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'system/libraries') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 092f9f378..828ef0c25 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -191,6 +191,71 @@ class CI_Zip { // -------------------------------------------------------------------- + /** + * Read the contents of a file and add it to the zip + * + * @access public + * @return bool + */ + function read_file($path, $preserve_filepath = FALSE) + { + if ( ! file_exists($path)) + { + return FALSE; + } + + if (FALSE !== ($data = file_get_contents($path))) + { + $name = str_replace("\\", "/", $path); + + if ($preserve_filepath === FALSE) + { + $name = preg_replace("|.*/(.+)|", "\\1", $name); + } + + $this->add_data($name, $data); + return TRUE; + } + return FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * Read a directory and add it to the zip. + * + * This function recursively reads a folder and everything it contains (including + * sub-folders) and creates a zip based on it. Whatever directory structure + * is in the original file path will be recreated in the zip file. + * + * @access public + * @param string path to source + * @return bool + */ + function read_dir($path) + { + if ($fp = @opendir($path)) + { + while (FALSE !== ($file = readdir($fp))) + { + if (@is_dir($path.$file) && substr($file, 0, 1) != '.') + { + $this->read_dir($path.$file."/"); + } + elseif (substr($file, 0, 1) != ".") + { + if (FALSE !== ($data = file_get_contents($path.$file))) + { + $this->add_data(str_replace("\\", "/", $path).$file, $data); + } + } + } + return TRUE; + } + } + + // -------------------------------------------------------------------- + /** * Get the Zip file * -- cgit v1.2.3-24-g4f1b From 7acd581d9441fb8ada4c46c58f4ec30a01507506 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 23 Oct 2006 21:37:22 +0000 Subject: --- system/libraries/Router.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index d4d1b2fdb..886433f37 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -295,7 +295,10 @@ class CI_Router { // can be unreliable in some environments if (is_array($_GET) AND count($_GET) == 1) { - return current(array_keys($_GET)); + // Note: Due to a bug in current() that affects some versions + // of PHP we can not pass function call directly into it + $keys = array_keys($_GET); + return current($keys); } // Is there a PATH_INFO variable? -- cgit v1.2.3-24-g4f1b From 41f908d57db3e5599b7f94f608f53e651dba43a6 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 23 Oct 2006 21:46:31 +0000 Subject: --- system/libraries/Session.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Session.php b/system/libraries/Session.php index c1fc345d9..89662fe52 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -275,7 +275,7 @@ class CI_Session { setcookie( $this->sess_cookie, $cookie_data, - $this->sess_length + $this->now, + $this->sess_length + time(), $this->CI->config->item('cookie_path'), $this->CI->config->item('cookie_domain'), 0 -- cgit v1.2.3-24-g4f1b From c75b09fd0d96a3871a8b02cbf0182d09b80d96e4 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 24 Oct 2006 00:14:28 +0000 Subject: --- system/libraries/Model.php | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Model.php b/system/libraries/Model.php index 240db4397..dfb48a5d0 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -26,6 +26,8 @@ */ class Model { + var $_parent_name = ''; + /** * Constructor * @@ -33,7 +35,17 @@ class Model { */ function Model() { - $this->_assign_libraries(); + // If the magic __get() method is used in a Model references can't be used. + $this->_assign_libraries( (method_exists($this, '__get')) ? 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 + $methods = get_class_methods($this); + if (isset($methods[0])) + { + $this->_parent_name = $methods[0]; + } + log_message('debug', "Model Class Initialized"); } @@ -42,17 +54,30 @@ class 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() + function _assign_libraries($use_reference = TRUE) { - $CI =& get_instance(); - + $CI =& get_instance(); foreach (array_keys(get_object_vars($CI)) as $key) { - $this->$key =& $CI->$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) + { + // Needed to prevent reference errors with some configurations + $this->$key = ''; + $this->$key =& $CI->$key; + } + else + { + $this->$key = $CI->$key; + } + } } } -- cgit v1.2.3-24-g4f1b From 2b47ea414625b77a5694419f6905927d614e3e3b Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 24 Oct 2006 00:15:02 +0000 Subject: --- system/libraries/Controller.php | 2 -- system/libraries/Loader.php | 16 ++++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index b1feee86c..922382ab7 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -32,8 +32,6 @@ class Controller extends CI_Base { var $_ci_scaffolding = FALSE; var $_ci_scaff_table = FALSE; - - /** * Constructor * diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index aaeee7f6b..7c42123f5 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -181,8 +181,17 @@ class CI_Loader { return DB($params, $active_record); } + // Grab the super object $CI =& get_instance(); - $CI->db =& DB($params, $active_record); + + // Initialize the db variable. Needed to prevent + // reference errors with some configurations + $CI->db = ''; + + // Load the DB class + $CI->db =& DB($params, $active_record); + + // Assign the DB object to any existing models $this->_ci_assign_to_models(); } @@ -828,11 +837,6 @@ class CI_Loader { */ function _ci_assign_to_models() { - if (count($this->_ci_models) == 0) - { - return; - } - if ($this->_ci_is_instance()) { $CI =& get_instance(); -- cgit v1.2.3-24-g4f1b From 2bc13859b72ceb8400d37adbba52b8404995bf03 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 24 Oct 2006 23:16:17 +0000 Subject: --- system/libraries/Loader.php | 5 +++++ system/libraries/Model.php | 1 + system/libraries/Table.php | 38 ++++++++++++++++++++++++++++++++------ 3 files changed, 38 insertions(+), 6 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 7c42123f5..f243a2879 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -837,6 +837,11 @@ class CI_Loader { */ function _ci_assign_to_models() { + if (count($this->_ci_models) == 0) + { + return; + } + if ($this->_ci_is_instance()) { $CI =& get_instance(); diff --git a/system/libraries/Model.php b/system/libraries/Model.php index dfb48a5d0..2fe93dd00 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -37,6 +37,7 @@ class Model { { // If the magic __get() method is used in a Model references can't be used. $this->_assign_libraries( (method_exists($this, '__get')) ? FALSE : TRUE ); + //$this->_assign_libraries( (method_exists($this, '__get') OR method_exists('__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 diff --git a/system/libraries/Table.php b/system/libraries/Table.php index f3f9b32f6..da7bbbecf 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -28,10 +28,11 @@ */ class CI_Table { - var $rows = array(); - var $heading = array(); - var $template = NULL; - var $newline = "\n"; + var $rows = array(); + var $heading = array(); + var $template = NULL; + var $newline = "\n"; + var $empty_cells = ""; function CI_Table() @@ -77,6 +78,22 @@ class CI_Table { // -------------------------------------------------------------------- + /** + * Set "empty" cells + * + * Can be passed as an array or discreet params + * + * @access public + * @param mixed + * @return void + */ + function set_empty($value) + { + $this->empty_cells = $value; + } + + // -------------------------------------------------------------------- + /** * Add a table row * @@ -166,10 +183,19 @@ class CI_Table { $out .= $this->template['row_'.$alt.'start']; $out .= $this->newline; - foreach($row as $cells) + foreach($row as $cell) { $out .= $this->template['cell_'.$alt.'start']; - $out .= $cells; + + if ($cell == "") + { + $out .= $this->empty_cells; + } + else + { + $out .= $cell; + } + $out .= $this->template['cell_'.$alt.'end']; } -- cgit v1.2.3-24-g4f1b From 1716cb80344dcb09dd263293b7901cd5b669e302 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 25 Oct 2006 05:12:34 +0000 Subject: --- system/libraries/Model.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Model.php b/system/libraries/Model.php index 2fe93dd00..e0335bf45 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -35,13 +35,13 @@ class Model { */ function Model() { - // If the magic __get() method is used in a Model references can't be used. - $this->_assign_libraries( (method_exists($this, '__get')) ? FALSE : TRUE ); - //$this->_assign_libraries( (method_exists($this, '__get') OR method_exists('__set')) ? FALSE : TRUE ); + // 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('__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 $methods = get_class_methods($this); + if (isset($methods[0])) { $this->_parent_name = $methods[0]; -- cgit v1.2.3-24-g4f1b From 29932c2e84b863a4c969a5d7424020272e3cd29e Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 26 Oct 2006 23:03:43 +0000 Subject: --- system/libraries/Ftp.php | 357 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 357 insertions(+) create mode 100644 system/libraries/Ftp.php (limited to 'system/libraries') diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php new file mode 100644 index 000000000..7d30137ea --- /dev/null +++ b/system/libraries/Ftp.php @@ -0,0 +1,357 @@ + 0) + { + $this->initialize($config); + } + + log_message('debug', "FTP Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Initialize preferences + * + * @access public + * @param array + * @return void + */ + function initialize($config = array()) + { + foreach ($config as $key => $val) + { + if (isset($this->$key)) + { + $this->$key = $val; + } + } + + $this->hostname = str_replace(array('ftp://', 'sftp://'), '', $this->hostname); + } + + // -------------------------------------------------------------------- + + /** + * FTP Connect + * + * @access public + * @return bool + */ + function connect() + { + $method = ($this->secure == FALSE) ? 'ftp_connect' : 'ftp_ssl_connect'; + + if (FALSE === ($this->conn_id = @$method($this->hostname, $this->port))) + { + if ($this->debug == TRUE) + { + $this->_error('ftp_unable_to_connect'); + } + return FALSE; + } + + if ( ! $this->_login()) + { + if ($this->debug == TRUE) + { + $this->_error('ftp_unable_to_login'); + } + return FALSE; + } + + + if ($this->passive == TRUE) + { + ftp_pasv($this->conn_id, TRUE); + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * FTP Login + * + * @access private + * @return bool + */ + function _login() + { + return @ftp_login($this->conn_id, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Change direcotries + * + * @access public + * @param string + * @return array + */ + function changedir($path = '') + { + if ($path == '') + { + return FALSE; + } + + //$path = preg_replace("|(.+)/$|", "\\1", $path); + + $result = @ftp_chdir($this->conn_id, $path); + + if ($result === FALSE) + { + if ($this->debug == TRUE) + { + $this->_error('ftp_unable_to_changedir'); + } + return FALSE; + } + + return TRUE; + + } + + // -------------------------------------------------------------------- + + /** + * Create a directory + * + * @access public + * @param string + * @return array + */ + function mkdir($path = '') + { + if ($path == '') + { + return FALSE; + } + + $result = @ftp_mkdir($this->conn_id, $path); + + if ($result === FALSE) + { + if ($this->debug == TRUE) + { + $this->_error('ftp_unable_to_makdir'); + } + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Upload a file to the server + * + * @access public + * @param string + * @param string + * @param string + * @return array + */ + function upload($locpath, $rempath, $mode = 'ascii', $permissions = NULL) + { + if ( ! file_exists($locpath)) + { + $this->_error('ftp_no_source_file'); + + return FALSE; + } + + + $mode = ($mode == 'ascii') ? FTP_ASCII : FTP_BINARY; + $result = @ftp_put($this->conn_id, $rempath, $locpath, $mode); + + if ($result === FALSE) + { + if ($this->debug == TRUE) + { + $this->_error('ftp_unable_to_upload'); + } + return FALSE; + } + + + if ( ! is_null($permissions)) + { + $this->chmod($rempath, (int)$permissions); + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Set file permissions + * + * @access public + * @param string the file path + * @param string the permissions + * @return array + */ + function chmod($path, $perm) + { + $result = @ftp_chmod($this->conn_id, $perm, $path); + + if ($result === FALSE) + { + if ($this->debug == TRUE) + { + $this->_error('ftp_unable_to_chmod'); + } + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * FTP List files in the specified directory + * + * @access public + * @return array + */ + function filelist($path = '.') + { + return ftp_nlist($this->conn_id, $path); + } + + // ------------------------------------------------------------------------ + + /** + * Read a directory and recreates it remotely + * + * This function recursively reads a folder and everything it contains (including + * sub-folders) and creates a mirror via FTP based on it. Whatever directory structure + * is in the original file path will be recreated in the zip file. + * + * @access public + * @param string path to source + * @param string path to destination + * @return bool + */ + function mirror($locpath, $rempath) + { + // Open the local file path + if ($fp = @opendir($locpath)) + { + // Attempt to open the remote file path. + if ( ! $this->changedir($rempath)) + { + // If it doesn't exist we'll attempt to create the direcotory + if ( ! $this->mkdir($rempath) OR ! $this->changedir($rempath)) + { + return FALSE; + } + } + + // Recursively read the local directory + while (FALSE !== ($file = readdir($fp))) + { + if (@is_dir($locpath.$file) && substr($file, 0, 1) != '.') + { + $this->mirror($locpath.$file."/", $rempath.$file."/"); + } + elseif (substr($file, 0, 1) != ".") + { + $mode = 'ascii'; + $this->upload($locpath.$file, $rempath.$file, $mode); + } + } + return TRUE; + } + + return FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * Close the connection + * + * @access public + * @param string path to source + * @param string path to destination + * @return bool + */ + function close() + { + @ftp_close($this->conn_id); + } + + // ------------------------------------------------------------------------ + + /** + * Display error message + * + * @access private + * @param string + * @return bool + */ + function _error($line) + { + $CI =& get_instance(); + $CI->lang->load('ftp'); + show_error($CI->lang->line($line)); + } + + +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 58e3d024e20040c16563c77293ac5c4bf8ea20d0 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 26 Oct 2006 23:33:11 +0000 Subject: --- system/libraries/Ftp.php | 94 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 77 insertions(+), 17 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 7d30137ea..d61e0aba4 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -36,9 +36,6 @@ class CI_FTP { var $conn_id; - var $CI; - - /** * Constructor - Sets Preferences * @@ -73,7 +70,8 @@ class CI_FTP { } } - $this->hostname = str_replace(array('ftp://', 'sftp://'), '', $this->hostname); + // Prep the hostname + $this->hostname = preg_replace('|.+?://|', '', $this->hostname); } // -------------------------------------------------------------------- @@ -106,7 +104,7 @@ class CI_FTP { return FALSE; } - + // Set passive mode if needed if ($this->passive == TRUE) { ftp_pasv($this->conn_id, TRUE); @@ -135,22 +133,21 @@ class CI_FTP { * * @access public * @param string + * @param bool lets us momentarily turn off debugging. * @return array */ - function changedir($path = '') + function changedir($path = '', $supress_debug = FALSE) { if ($path == '') { return FALSE; } - //$path = preg_replace("|(.+)/$|", "\\1", $path); - $result = @ftp_chdir($this->conn_id, $path); if ($result === FALSE) { - if ($this->debug == TRUE) + if ($this->debug == TRUE AND $supress_debug != TRUE) { $this->_error('ftp_unable_to_changedir'); } @@ -158,7 +155,6 @@ class CI_FTP { } return TRUE; - } // -------------------------------------------------------------------- @@ -202,7 +198,7 @@ class CI_FTP { * @param string * @return array */ - function upload($locpath, $rempath, $mode = 'ascii', $permissions = NULL) + function upload($locpath, $rempath, $mode = 'auto', $permissions = NULL) { if ( ! file_exists($locpath)) { @@ -211,8 +207,16 @@ class CI_FTP { return FALSE; } - + // Set the mode if not specified + if ($mode == 'auto') + { + // Get the file extension so we can se the upload type + $ext = $this->_getext($locpath); + $mode = $this->_settype($ext); + } + $mode = ($mode == 'ascii') ? FTP_ASCII : FTP_BINARY; + $result = @ftp_put($this->conn_id, $rempath, $locpath, $mode); if ($result === FALSE) @@ -224,7 +228,7 @@ class CI_FTP { return FALSE; } - + // Set file permissions if needed if ( ! is_null($permissions)) { $this->chmod($rempath, (int)$permissions); @@ -275,7 +279,7 @@ class CI_FTP { // ------------------------------------------------------------------------ /** - * Read a directory and recreates it remotely + * Read a directory and recreate it remotely * * This function recursively reads a folder and everything it contains (including * sub-folders) and creates a mirror via FTP based on it. Whatever directory structure @@ -292,7 +296,7 @@ class CI_FTP { if ($fp = @opendir($locpath)) { // Attempt to open the remote file path. - if ( ! $this->changedir($rempath)) + if ( ! $this->changedir($rempath, TRUE)) { // If it doesn't exist we'll attempt to create the direcotory if ( ! $this->mkdir($rempath) OR ! $this->changedir($rempath)) @@ -310,7 +314,10 @@ class CI_FTP { } elseif (substr($file, 0, 1) != ".") { - $mode = 'ascii'; + // Get the file extension so we can se the upload type + $ext = $this->_getext($file); + $mode = $this->_settype($ext); + $this->upload($locpath.$file, $rempath.$file, $mode); } } @@ -320,6 +327,59 @@ class CI_FTP { return FALSE; } + + // -------------------------------------------------------------------- + + /** + * Extract the file extension + * + * @access private + * @param string + * @return string + */ + function _getext($filename) + { + if (FALSE === strpos($filename, '.')) + { + return 'txt'; + } + + $x = explode('.', $filename); + return end($x); + } + + + // -------------------------------------------------------------------- + + /** + * Set the upload type + * + * @access private + * @param string + * @return string + */ + function _settype($ext) + { + $text_types = array( + 'txt', + 'text', + 'php', + 'phps', + 'php4', + 'js', + 'css', + 'htm', + 'html', + 'phtml', + 'shtml', + 'log', + 'xml' + ); + + + return (in_array($ext, $text_types)) ? 'ascii' : 'binary'; + } + // ------------------------------------------------------------------------ /** @@ -353,5 +413,5 @@ class CI_FTP { } - +// END FTP Class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b84f7c03473f271ca53c80f9cb0f4b28755bb2cf Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 27 Oct 2006 03:11:11 +0000 Subject: --- system/libraries/Pagination.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index a004419d6..c66d570cd 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -109,17 +109,6 @@ class CI_Pagination { // Calculate the total number of pages $num_pages = ceil($this->total_rows / $this->per_page); - /* - // Calculate the total number of pages - $num_pages = intval($this->total_rows / $this->per_page); - - // Use modulus to see if our division has a remainder. If so, add one to our page number. - if ($this->total_rows % $this->per_page) - { - $num_pages++; - } - */ - // Is there only one page? Hm... nothing more to do here then. if ($num_pages == 1) { @@ -138,6 +127,13 @@ class CI_Pagination { $this->cur_page = 0; } + // Is the page number beyond the result range? + // If so we show the last page + if ($this->cur_page > $this->total_rows) + { + $this->cur_page = ($num_pages - 1) * $this->per_page; + } + $uri_page_number = $this->cur_page; $this->cur_page = floor(($this->cur_page/$this->per_page) + 1); -- cgit v1.2.3-24-g4f1b From 3f643e678ef64ae29aa9720aef9b2a40496a5343 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 27 Oct 2006 06:25:31 +0000 Subject: --- system/libraries/Email.php | 74 ++++++++++++++++++++------------------------- system/libraries/Output.php | 3 +- 2 files changed, 35 insertions(+), 42 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 92f2e73fa..158c82af2 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -321,14 +321,7 @@ class CI_Email { */ function message($body) { - $body = rtrim(str_replace("\r", "", $body)); - - if ($this->wordwrap === TRUE AND $this->mailtype != 'html') - $this->_body = $this->word_wrap($body); - else - $this->_body = $body; - - $this->_body = stripslashes($this->_body); + $this->_body = stripslashes(rtrim(str_replace("\r", "", $body))); } // -------------------------------------------------------------------- @@ -758,59 +751,53 @@ class CI_Email { function word_wrap($str, $chars = '') { if ($chars == '') + { $chars = ($this->wrapchars == "") ? "76" : $this->wrapchars; + } - $lines = split("\n", $str); - - $output = ""; + $str = preg_replace("| +|", " ", $str); - while (list(, $thisline) = each($lines)) + $str = preg_replace("|(\[url.+\])|", "{unwrap}\\1{/unwrap}", $str); + + $output = ""; + foreach (split("\n", $str) as $current_line) { - if (strlen($thisline) > $chars) + if (strlen($current_line) > $chars) { $line = ""; - - $words = split(" ", $thisline); - - while(list(, $thisword) = each($words)) + + foreach (split(" ", $current_line) as $words) { - while((strlen($thisword)) > $chars) + while((strlen($words)) > $chars) { - if (stristr($thisword, '{unwrap}') !== FALSE OR stristr($thisword, '{/unwrap}') !== FALSE) + if (stristr($words, '{unwrap}') !== FALSE OR stristr($words, '{/unwrap}') !== FALSE) { break; } - - $cur_pos = 0; - - for($i=0; $i < $chars - 1; $i++) - { - $output .= $thisword[$i]; - $cur_pos++; - } - - $output .= "\n"; - - $thisword = substr($thisword, $cur_pos, (strlen($thisword) - $cur_pos)); + + $output .= substr($words, 0, $chars-1); + $words = substr($words, $chars-1); + + $output .= $this->newline; } - if ((strlen($line) + strlen($thisword)) > $chars) + if ((strlen($line) + strlen($words)) > $chars) { - $output .= $line."\n"; + $output .= $line.$this->newline; - $line = $thisword." "; - } - else + $line = $words." "; + } + else { - $line .= $thisword." "; + $line .= $words." "; } } - $output .= $line."\n"; - } - else + $output .= $line.$this->newline; + } + else { - $output .= $thisline."\n"; + $output .= $current_line.$this->newline; } } @@ -878,6 +865,11 @@ class CI_Email { */ function _build_message() { + if ($this->wordwrap === TRUE AND $this->mailtype != 'html') + { + $this->_body = $this->word_wrap($this->_body); + } + $this->_set_boundaries(); $this->_write_headers(); diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 0c2620df7..e53627408 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -201,7 +201,8 @@ class CI_Output { { echo $output; log_message('debug', "Final output sent to browser"); - log_message('debug', "Total execution time: ".$elapsed); + log_message('debug', "Total execution time: ".$elapsed); + return TRUE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From d7f88ca118cf1afe0c730e68b35e3693eaf9022e Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 27 Oct 2006 06:34:06 +0000 Subject: --- system/libraries/Ftp.php | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index d61e0aba4..6c1bad8e1 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -129,11 +129,17 @@ class CI_FTP { // -------------------------------------------------------------------- /** - * Change direcotries + * Change direcotry + * + * The second parameter lets us momentarily turn off debugging so that + * this function can be used to test for the existance of a folder + * without throwing an error. There's no FTP equivalent to is_dir() + * so we do it by trying to change to a particular directory. + * Internally, this paramter is only used by the "mirror" function below. * * @access public * @param string - * @param bool lets us momentarily turn off debugging. + * @param bool * @return array */ function changedir($path = '', $supress_debug = FALSE) @@ -203,7 +209,6 @@ class CI_FTP { if ( ! file_exists($locpath)) { $this->_error('ftp_no_source_file'); - return FALSE; } @@ -248,7 +253,17 @@ class CI_FTP { * @return array */ function chmod($path, $perm) - { + { + // Permissions can only be set when running PHP 5 + if ( ! function_exists('ftp_chmod')) + { + if ($this->debug == TRUE) + { + $this->_error('ftp_unable_to_chmod'); + } + return FALSE; + } + $result = @ftp_chmod($this->conn_id, $perm, $path); if ($result === FALSE) @@ -271,7 +286,7 @@ class CI_FTP { * @access public * @return array */ - function filelist($path = '.') + function list_files($path = '.') { return ftp_nlist($this->conn_id, $path); } @@ -286,8 +301,8 @@ class CI_FTP { * is in the original file path will be recreated in the zip file. * * @access public - * @param string path to source - * @param string path to destination + * @param string path to source with trailing slash + * @param string path to destination - include the base folder with trailing slash * @return bool */ function mirror($locpath, $rempath) -- cgit v1.2.3-24-g4f1b From 631f17b88124619dd27a04509970da155a3fc1b7 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 27 Oct 2006 07:41:28 +0000 Subject: --- system/libraries/Ftp.php | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 6c1bad8e1..a0c6895bf 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -31,7 +31,6 @@ class CI_FTP { var $password = ''; var $port = 21; var $passive = TRUE; - var $secure = FALSE; var $debug = FALSE; var $conn_id; @@ -80,11 +79,18 @@ class CI_FTP { * FTP Connect * * @access public + * @param array the connection values + * @param bool whether to use a secure or standard connection * @return bool */ - function connect() - { - $method = ($this->secure == FALSE) ? 'ftp_connect' : 'ftp_ssl_connect'; + function connect($config = array(), $secure = FALSE) + { + if (count($config) > 0) + { + $this->initialize($config); + } + + $method = ($secure == FALSE) ? 'ftp_connect' : 'ftp_ssl_connect'; if (FALSE === ($this->conn_id = @$method($this->hostname, $this->port))) { @@ -112,6 +118,20 @@ class CI_FTP { return TRUE; } + + // -------------------------------------------------------------------- + + /** + * Secure FTP Connect + * + * @access public + * @param array the connection values + * @return bool + */ + function sconnect($config = array()) + { + return $this->connect($config, TRUE); + } // -------------------------------------------------------------------- @@ -297,8 +317,8 @@ class CI_FTP { * Read a directory and recreate it remotely * * This function recursively reads a folder and everything it contains (including - * sub-folders) and creates a mirror via FTP based on it. Whatever directory structure - * is in the original file path will be recreated in the zip file. + * sub-folders) and creates a mirror via FTP based on it. Whatever the directory structure + * of the original file path will be recreated on the server. * * @access public * @param string path to source with trailing slash -- cgit v1.2.3-24-g4f1b From 667da5e418c97f015a700cf61a70dede321436a9 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 27 Oct 2006 15:54:16 +0000 Subject: --- system/libraries/Upload.php | 76 ++++++++++++++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 21 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 1a0b0fc8f..ff0fb1cb9 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -36,7 +36,7 @@ class CI_Upload { var $file_type = ""; var $file_size = ""; var $file_ext = ""; - var $file_path = ""; + var $upload_path = ""; var $overwrite = FALSE; var $encrypt_name = FALSE; var $is_image = FALSE; @@ -76,17 +76,51 @@ class CI_Upload { */ function initialize($config = array()) { - foreach ($config as $key => $val) - { - $method = 'set_'.$key; - if (method_exists($this, $method)) + $defaults = array( + 'max_size' => 0, + 'max_width' => 0, + 'max_height' => 0, + 'allowed_types' => "", + 'file_temp' => "", + 'file_name' => "", + 'orig_name' => "", + 'file_type' => "", + 'file_size' => "", + 'file_ext' => "", + 'upload_path' => "", + 'overwrite' => FALSE, + 'encrypt_name' => FALSE, + 'is_image' => FALSE, + 'image_width' => '', + 'image_height' => '', + 'image_type' => '', + 'image_size_str' => '', + 'error_msg' => array(), + 'mimes' => array(), + 'remove_spaces' => TRUE, + 'xss_clean' => FALSE, + 'temp_prefix' => "temp_file_" + ); + + + foreach ($defaults as $key => $val) + { + if (isset($config[$key])) { - $this->$method($val); + $method = 'set_'.$key; + if (method_exists($this, $method)) + { + $this->$method($config[$key]); + } + else + { + $this->$key = $config[$key]; + } } else { $this->$key = $val; - } + } } } @@ -188,7 +222,7 @@ class CI_Upload { if ($this->overwrite == FALSE) { - $this->file_name = $this->set_filename($this->file_path, $this->file_name); + $this->file_name = $this->set_filename($this->upload_path, $this->file_name); if ($this->file_name === FALSE) { @@ -203,9 +237,9 @@ class CI_Upload { * we'll use move_uploaded_file(). One of the two should * reliably work in most environments */ - if ( ! @copy($this->file_temp, $this->file_path.$this->file_name)) + if ( ! @copy($this->file_temp, $this->upload_path.$this->file_name)) { - if ( ! @move_uploaded_file($this->file_temp, $this->file_path.$this->file_name)) + if ( ! @move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name)) { $this->set_error('upload_destination_error'); return FALSE; @@ -229,7 +263,7 @@ class CI_Upload { * file was an image). We use this information * in the "data" function. */ - $this->set_image_properties($this->file_path.$this->file_name); + $this->set_image_properties($this->upload_path.$this->file_name); return TRUE; } @@ -250,8 +284,8 @@ class CI_Upload { return array ( 'file_name' => $this->file_name, 'file_type' => $this->file_type, - 'file_path' => $this->file_path, - 'full_path' => $this->file_path.$this->file_name, + 'file_path' => $this->upload_path, + 'full_path' => $this->upload_path.$this->file_name, 'raw_name' => str_replace($this->file_ext, '', $this->file_name), 'orig_name' => $this->orig_name, 'file_ext' => $this->file_ext, @@ -275,7 +309,7 @@ class CI_Upload { */ function set_upload_path($path) { - $this->file_path = $path; + $this->upload_path = $path; } // -------------------------------------------------------------------- @@ -564,30 +598,30 @@ class CI_Upload { */ function validate_upload_path() { - if ($this->file_path == '') + if ($this->upload_path == '') { $this->set_error('upload_no_filepath'); return FALSE; } - if (function_exists('realpath') AND @realpath($this->file_path) !== FALSE) + if (function_exists('realpath') AND @realpath($this->upload_path) !== FALSE) { - $this->file_path = str_replace("\\", "/", realpath($this->file_path)); + $this->upload_path = str_replace("\\", "/", realpath($this->upload_path)); } - if ( ! @is_dir($this->file_path)) + if ( ! @is_dir($this->upload_path)) { $this->set_error('upload_no_filepath'); return FALSE; } - if ( ! is_writable($this->file_path)) + if ( ! is_writable($this->upload_path)) { $this->set_error('upload_not_writable'); return FALSE; } - $this->file_path = preg_replace("/(.+?)\/*$/", "\\1/", $this->file_path); + $this->upload_path = preg_replace("/(.+?)\/*$/", "\\1/", $this->upload_path); return TRUE; } @@ -668,7 +702,7 @@ class CI_Upload { */ function do_xss_clean() { - $file = $this->file_path.$this->file_name; + $file = $this->upload_path.$this->file_name; if (filesize($file) == 0) { -- cgit v1.2.3-24-g4f1b From 0e5ca047896c92c490d038f54e4623cb4db4ad76 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 27 Oct 2006 17:57:30 +0000 Subject: --- system/libraries/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Model.php b/system/libraries/Model.php index e0335bf45..1c2b7afce 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -36,7 +36,7 @@ class Model { function 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('__set')) ? FALSE : TRUE ); + $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 -- cgit v1.2.3-24-g4f1b From 6895a4b6045dd3fef3a2e742932721f6ccc2a569 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 27 Oct 2006 22:06:01 +0000 Subject: --- system/libraries/Ftp.php | 214 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 189 insertions(+), 25 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index a0c6895bf..3b2be23d5 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -32,7 +32,7 @@ class CI_FTP { var $port = 21; var $passive = TRUE; var $debug = FALSE; - var $conn_id; + var $conn_id = FALSE; /** @@ -80,19 +80,16 @@ class CI_FTP { * * @access public * @param array the connection values - * @param bool whether to use a secure or standard connection * @return bool */ - function connect($config = array(), $secure = FALSE) + function connect($config = array()) { if (count($config) > 0) { $this->initialize($config); } - $method = ($secure == FALSE) ? 'ftp_connect' : 'ftp_ssl_connect'; - - if (FALSE === ($this->conn_id = @$method($this->hostname, $this->port))) + if (FALSE === ($this->conn_id = @ftp_connect($this->hostname, $this->port))) { if ($this->debug == TRUE) { @@ -122,32 +119,40 @@ class CI_FTP { // -------------------------------------------------------------------- /** - * Secure FTP Connect + * FTP Login * - * @access public - * @param array the connection values + * @access private * @return bool - */ - function sconnect($config = array()) + */ + function _login() { - return $this->connect($config, TRUE); + return @ftp_login($this->conn_id, $this->username, $this->password); } - + // -------------------------------------------------------------------- /** - * FTP Login + * Validates the connection ID * * @access private * @return bool */ - function _login() + function _is_conn() { - return @ftp_login($this->conn_id, $this->username, $this->password); + if ( ! is_resource($this->conn_id)) + { + if ($this->debug == TRUE) + { + $this->_error('ftp_no_connection'); + } + return FALSE; + } + return TRUE; } // -------------------------------------------------------------------- + /** * Change direcotry * @@ -160,11 +165,11 @@ class CI_FTP { * @access public * @param string * @param bool - * @return array + * @return bool */ function changedir($path = '', $supress_debug = FALSE) { - if ($path == '') + if ($path == '' OR ! $this->_is_conn()) { return FALSE; } @@ -190,11 +195,11 @@ class CI_FTP { * * @access public * @param string - * @return array + * @return bool */ - function mkdir($path = '') + function mkdir($path = '', $permissions = NULL) { - if ($path == '') + if ($path == '' OR ! $this->_is_conn()) { return FALSE; } @@ -209,6 +214,12 @@ class CI_FTP { } return FALSE; } + + // Set file permissions if needed + if ( ! is_null($permissions)) + { + $this->chmod($path, (int)$permissions); + } return TRUE; } @@ -222,10 +233,15 @@ class CI_FTP { * @param string * @param string * @param string - * @return array + * @return bool */ function upload($locpath, $rempath, $mode = 'auto', $permissions = NULL) { + if ( ! $this->_is_conn()) + { + return FALSE; + } + if ( ! file_exists($locpath)) { $this->_error('ftp_no_source_file'); @@ -264,16 +280,149 @@ class CI_FTP { // -------------------------------------------------------------------- + /** + * Rename (or move) a file + * + * @access public + * @param string + * @param string + * @param bool + * @return bool + */ + function rename($old_file, $new_file, $move = FALSE) + { + if ( ! $this->_is_conn()) + { + return FALSE; + } + + $result = @ftp_rename($this->conn_id, $old_file, $new_file); + + if ($result === FALSE) + { + if ($this->debug == TRUE) + { + $msg = ($move = FALSE) ? 'ftp_unable_to_remame' : 'ftp_unable_to_move'; + + $this->_error($msg); + } + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Move a file + * + * @access public + * @param string + * @param string + * @return bool + */ + function move($old_file, $new_file) + { + return $this->rename($old_file, $new_file, TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Rename (or move) a file + * + * @access public + * @param string + * @return bool + */ + function delete_file($filepath) + { + if ( ! $this->_is_conn()) + { + return FALSE; + } + + $result = @ftp_delete($this->conn_id, $filepath); + + if ($result === FALSE) + { + if ($this->debug == TRUE) + { + $this->_error('ftp_unable_to_delete'); + } + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Delete a folder and recursively delete everything (including sub-folders) + * containted within it. + * + * @access public + * @param string + * @return bool + */ + function delete_dir($filepath) + { + if ( ! $this->_is_conn()) + { + return FALSE; + } + + // Add a trailing slash to the file path if needed + $filepath = preg_replace("/(.+?)\/*$/", "\\1/", $filepath); + + $list = $this->list_files($filepath); + + if ($list !== FALSE AND count($list) > 0) + { + foreach ($list as $item) + { + // If we can't delete the item it's probaly a folder so + // we'll recursively call delete_dir() + if ( ! @ftp_delete($this->conn_id, $filepath.$item)) + { + $this->delete_dir($filepath.$item); + } + } + } + + $result = @ftp_rmdir($this->conn_id, $filepath); + + if ($result === FALSE) + { + if ($this->debug == TRUE) + { + $this->_error('ftp_unable_to_delete'); + } + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + /** * Set file permissions * * @access public * @param string the file path * @param string the permissions - * @return array + * @return bool */ function chmod($path, $perm) { + if ( ! $this->_is_conn()) + { + return FALSE; + } + // Permissions can only be set when running PHP 5 if ( ! function_exists('ftp_chmod')) { @@ -307,7 +456,12 @@ class CI_FTP { * @return array */ function list_files($path = '.') - { + { + if ( ! $this->_is_conn()) + { + return FALSE; + } + return ftp_nlist($this->conn_id, $path); } @@ -326,7 +480,12 @@ class CI_FTP { * @return bool */ function mirror($locpath, $rempath) - { + { + if ( ! $this->_is_conn()) + { + return FALSE; + } + // Open the local file path if ($fp = @opendir($locpath)) { @@ -427,6 +586,11 @@ class CI_FTP { */ function close() { + if ( ! $this->_is_conn()) + { + return FALSE; + } + @ftp_close($this->conn_id); } -- cgit v1.2.3-24-g4f1b From 86c60398852a299aa4a485c7e9e3c1d45e8c2184 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 28 Oct 2006 02:50:53 +0000 Subject: --- system/libraries/Email.php | 107 ++++++++++++++++++++++++++++----------------- 1 file changed, 67 insertions(+), 40 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 158c82af2..e6dd614f4 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -748,56 +748,83 @@ class CI_Email { * @param integer * @return string */ - function word_wrap($str, $chars = '') - { - if ($chars == '') + function word_wrap($str, $charlim = '') + { + // Se the character limit + if ($charlim == '') { - $chars = ($this->wrapchars == "") ? "76" : $this->wrapchars; + $charlim = ($this->wrapchars == "") ? "76" : $this->wrapchars; } + // Reduce multiple spaces $str = preg_replace("| +|", " ", $str); - - $str = preg_replace("|(\[url.+\])|", "{unwrap}\\1{/unwrap}", $str); - + + // Standardize newlines + $str = preg_replace("/\r\n|\r/", "\n", $str); + + // 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]; + $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 + // 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 (split("\n", $str) as $current_line) + foreach (explode("\n", $str) as $line) { - if (strlen($current_line) > $chars) + // Is the line within the allowed character count? + // If so we'll join it to the output and continue + if (strlen($line) <= $charlim) { - $line = ""; - - foreach (split(" ", $current_line) as $words) + $output .= $line.$this->newline; + continue; + } + + $temp = ''; + while((strlen($line)) > $charlim) + { + // If the over-length word is a URL we won't wrap it + if (preg_match("!\[url.+\]|://|wwww.!", $line)) { - while((strlen($words)) > $chars) - { - if (stristr($words, '{unwrap}') !== FALSE OR stristr($words, '{/unwrap}') !== FALSE) - { - break; - } - - $output .= substr($words, 0, $chars-1); - $words = substr($words, $chars-1); - - $output .= $this->newline; - } - - if ((strlen($line) + strlen($words)) > $chars) - { - $output .= $line.$this->newline; - - $line = $words." "; - } - else - { - $line .= $words." "; - } + break; } - - $output .= $line.$this->newline; - } - else + + // Trim the word down + $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 + // word into smaller chunks so we'll add it back to our current line + if ($temp != '') + { + $output .= $temp.$this->newline.$line; + } + else + { + $output .= $line; + } + + $output .= $this->newline; + } + + // Put our markers back + if (count($unwrap) > 0) + { + foreach ($unwrap as $key => $val) { - $output .= $current_line.$this->newline; + $output = str_replace("{{unwrapped".$key."}}", $val, $output); } } -- cgit v1.2.3-24-g4f1b From 26364b934dc8f7fa25f26e1f172d2a13dd826a15 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 28 Oct 2006 05:22:02 +0000 Subject: --- system/libraries/Table.php | 79 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 65 insertions(+), 14 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index da7bbbecf..01c45c73b 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -28,11 +28,12 @@ */ class CI_Table { - var $rows = array(); - var $heading = array(); - var $template = NULL; - var $newline = "\n"; - var $empty_cells = ""; + var $rows = array(); + var $heading = array(); + var $auto_heading = TRUE; + var $template = NULL; + var $newline = "\n"; + var $empty_cells = ""; function CI_Table() @@ -78,6 +79,55 @@ class CI_Table { // -------------------------------------------------------------------- + /** + * Set columns. Takes a one-dimensional array as input and creates + * a multi-dimensional array with a depth equal to the number of + * columns. This allows a single array with many elements to be + * displayed in a table that has a fixed column count. + * + * @access public + * @param array + * @param int + * @return void + */ + function make_columns($array = array(), $col_limit = 0) + { + if ( ! is_array($array) OR count($array) == 0) + { + return FALSE; + } + + // 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_slice($array, 0, $col_limit); + $array = array_diff($array, $temp); + + if (count($temp) < $col_limit) + { + for ($i = count($temp); $i < $col_limit; $i++) + { + $temp[] = ' '; + } + } + + $new[] = $temp; + } + + return $new; + } + + // -------------------------------------------------------------------- + /** * Set "empty" cells * @@ -130,7 +180,8 @@ class CI_Table { } elseif (is_array($table_data)) { - $this->_set_from_array($table_data); + $set_heading = (count($this->heading) == 0 AND $this->auto_heading == FALSE) ? FALSE : TRUE; + $this->_set_from_array($table_data, $set_heading); } } @@ -178,14 +229,14 @@ class CI_Table { } // We use modulus to alternate the row colors - $alt = (fmod($i++, 2)) ? '' : 'alt_'; + $name = (fmod($i++, 2)) ? '' : 'alt_'; - $out .= $this->template['row_'.$alt.'start']; + $out .= $this->template['row_'.$name.'start']; $out .= $this->newline; foreach($row as $cell) { - $out .= $this->template['cell_'.$alt.'start']; + $out .= $this->template['cell_'.$name.'start']; if ($cell == "") { @@ -196,10 +247,10 @@ class CI_Table { $out .= $cell; } - $out .= $this->template['cell_'.$alt.'end']; + $out .= $this->template['cell_'.$name.'end']; } - $out .= $this->template['row_'.$alt.'end']; + $out .= $this->template['row_'.$name.'end']; $out .= $this->newline; } } @@ -208,7 +259,7 @@ class CI_Table { return $out; } - + // -------------------------------------------------------------------- /** @@ -256,7 +307,7 @@ class CI_Table { * @param array * @return void */ - function _set_from_array($data) + function _set_from_array($data, $set_heading = TRUE) { if ( ! is_array($data) OR count($data) == 0) { @@ -273,7 +324,7 @@ class CI_Table { } // 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) + if ($i == 0 AND count($data) > 1 AND count($this->heading) == 0 AND $set_heading == TRUE) { $this->heading = $row; } -- cgit v1.2.3-24-g4f1b From 41cece9ce497c87aa49bc22a3557441148b99754 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 28 Oct 2006 19:06:45 +0000 Subject: --- system/libraries/Table.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'system/libraries') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 01c45c73b..183e8895a 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -262,6 +262,21 @@ class CI_Table { // -------------------------------------------------------------------- + /** + * Clears the table arrays. Useful if multiple tables are beting generated + * + * @access public + * @return void + */ + function clear_data() + { + $this->rows = array(); + $this->heading = array(); + $this->auto_heading = TRUE; + } + + // -------------------------------------------------------------------- + /** * Set table data from a database result object * -- cgit v1.2.3-24-g4f1b From f3a6204bb0f4538d6a77d9c85c56545be73ecd64 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 29 Oct 2006 20:24:11 +0000 Subject: --- system/libraries/Config.php | 2 +- system/libraries/Exceptions.php | 4 ++-- system/libraries/Language.php | 5 ++--- system/libraries/Loader.php | 20 ++++++++++---------- system/libraries/Router.php | 2 +- system/libraries/Table.php | 2 +- 6 files changed, 17 insertions(+), 18 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Config.php b/system/libraries/Config.php index aa26c9203..c4ea9b4ee 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -75,7 +75,7 @@ class CI_Config { show_error('The configuration file '.$file.EXT.' does not exist.'); } - include_once(APPPATH.'config/'.$file.EXT); + include(APPPATH.'config/'.$file.EXT); if ( ! isset($config) OR ! is_array($config)) { diff --git a/system/libraries/Exceptions.php b/system/libraries/Exceptions.php index 6d58ee6b9..8f90ff8f9 100644 --- a/system/libraries/Exceptions.php +++ b/system/libraries/Exceptions.php @@ -120,7 +120,7 @@ class CI_Exceptions { ob_end_flush(); } ob_start(); - include_once(APPPATH.'errors/'.$template.EXT); + include(APPPATH.'errors/'.$template.EXT); $buffer = ob_get_contents(); ob_end_clean(); return $buffer; @@ -156,7 +156,7 @@ class CI_Exceptions { ob_end_flush(); } ob_start(); - include_once(APPPATH.'errors/error_php'.EXT); + include(APPPATH.'errors/error_php'.EXT); $buffer = ob_get_contents(); ob_end_clean(); echo $buffer; diff --git a/system/libraries/Language.php b/system/libraries/Language.php index 37a5c7e99..faf516ea5 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -66,16 +66,15 @@ class CI_Language { } // Determine where the language file is and load it - if (file_exists(APPPATH.'language/'.$idiom.'/'.$langfile)) { - include_once(APPPATH.'language/'.$idiom.'/'.$langfile); + include(APPPATH.'language/'.$idiom.'/'.$langfile); } else { if (file_exists(BASEPATH.'language/'.$idiom.'/'.$langfile)) { - include_once(BASEPATH.'language/'.$idiom.'/'.$langfile); + include(BASEPATH.'language/'.$idiom.'/'.$langfile); } else { diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index f243a2879..709d9fe3d 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -315,13 +315,13 @@ class CI_Loader { if (file_exists(APPPATH.'helpers/'.$helper.EXT)) { - include_once(APPPATH.'helpers/'.$helper.EXT); + include(APPPATH.'helpers/'.$helper.EXT); } else { if (file_exists(BASEPATH.'helpers/'.$helper.EXT)) { - include_once(BASEPATH.'helpers/'.$helper.EXT); + include(BASEPATH.'helpers/'.$helper.EXT); } else { @@ -381,13 +381,13 @@ class CI_Loader { if (file_exists(APPPATH.'plugins/'.$plugin.EXT)) { - include_once(APPPATH.'plugins/'.$plugin.EXT); + include(APPPATH.'plugins/'.$plugin.EXT); } else { if (file_exists(BASEPATH.'plugins/'.$plugin.EXT)) { - include_once(BASEPATH.'plugins/'.$plugin.EXT); + include(BASEPATH.'plugins/'.$plugin.EXT); } else { @@ -454,7 +454,7 @@ class CI_Loader { show_error('Unable to load the requested script: scripts/'.$script.EXT); } - include_once(APPPATH.'scripts/'.$script.EXT); + include(APPPATH.'scripts/'.$script.EXT); $this->_ci_scripts[$script] = TRUE; } @@ -675,8 +675,8 @@ class CI_Loader { show_error("Unable to load the requested class: ".$class); } - include_once(BASEPATH.'libraries/'.ucfirst($class).EXT); - include_once(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT); + include(BASEPATH.'libraries/'.ucfirst($class).EXT); + include(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT); return $this->_ci_init_class($class, config_item('subclass_prefix'), $params); } @@ -687,7 +687,7 @@ class CI_Loader { $path = ($i % 2) ? APPPATH : BASEPATH; if (file_exists($path.'libraries/'.$class.EXT)) { - include_once($path.'libraries/'.$class.EXT); + include($path.'libraries/'.$class.EXT); return $this->_ci_init_class($class, '', $params); } } @@ -715,7 +715,7 @@ class CI_Loader { $config = NULL; if (file_exists(APPPATH.'config/'.$class.EXT)) { - include_once(APPPATH.'config/'.$class.EXT); + include(APPPATH.'config/'.$class.EXT); } } @@ -758,7 +758,7 @@ class CI_Loader { */ function _ci_autoloader() { - include_once(APPPATH.'config/autoload'.EXT); + include(APPPATH.'config/autoload'.EXT); if ( ! isset($autoload)) { diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 886433f37..6d925a1c0 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -81,7 +81,7 @@ class CI_Router { } // Load the routes.php file. - @include_once(APPPATH.'config/routes'.EXT); + @include(APPPATH.'config/routes'.EXT); $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route; unset($route); diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 183e8895a..1b25a441a 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -268,7 +268,7 @@ class CI_Table { * @access public * @return void */ - function clear_data() + function clear() { $this->rows = array(); $this->heading = array(); -- cgit v1.2.3-24-g4f1b From 49439ff0a4deaac47e078c137216b0c410bd6ec4 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 30 Oct 2006 04:39:12 +0000 Subject: --- system/libraries/Config.php | 2 +- system/libraries/Loader.php | 4 ++-- system/libraries/Log.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Config.php b/system/libraries/Config.php index c4ea9b4ee..28409fbc4 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -44,7 +44,7 @@ class CI_Config { */ function CI_Config() { - $this->config = get_config(); + $this->config =& get_config(); log_message('debug', "Config Class Initialized"); } diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 709d9fe3d..117626567 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -606,7 +606,7 @@ class CI_Loader { // do a little string replacement, changing the short tags // to standard PHP echo statements. - if ((bool) @ini_get('short_open_tag') === FALSE) + if ((bool) @ini_get('short_open_tag') === FALSE AND config_item('rewrite_short_tags') == TRUE) { echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace('log_path = ($config['log_path'] != '') ? $config['log_path'] : BASEPATH.'logs/'; -- cgit v1.2.3-24-g4f1b From cef2106de1c7044072499aa5d4e529a01c3db8a4 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 30 Oct 2006 17:13:13 +0000 Subject: --- system/libraries/Controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 922382ab7..c8fa646c7 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -74,11 +74,11 @@ class Controller extends CI_Base { $this->$var =& load_class($class); } - // In PHP 5 the Controller class is run as a discreet + // In PHP 5 the Loader class is run as a discreet // class. In PHP 4 it extends the Controller if (floor(phpversion()) >= 5) { - $this->load = new CI_Loader(); + $this->load =& load_class('Loader'); $this->load->_ci_autoloader(); } else -- cgit v1.2.3-24-g4f1b From b93464db656fe017fe434b0fc917921ded88a12c Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 31 Oct 2006 00:36:32 +0000 Subject: --- system/libraries/Calendar.php | 11 ++++++++++- system/libraries/Pagination.php | 5 ++++- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 84b096c8b..fdef5dd75 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -45,7 +45,7 @@ class CI_Calendar { * * @access public */ - function CI_Calendar() + function CI_Calendar($config = array()) { $this->CI =& get_instance(); @@ -55,6 +55,12 @@ class CI_Calendar { } $this->local_time = time(); + + if (count($config) > 0) + { + $this->initialize($config); + } + log_message('debug', "Calendar Class Initialized"); } @@ -153,6 +159,9 @@ class CI_Calendar { // "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"; diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index c66d570cd..07ad6a683 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -120,8 +120,11 @@ class CI_Pagination { if ($CI->uri->segment($this->uri_segment) != 0) { $this->cur_page = $CI->uri->segment($this->uri_segment); + + // Prep the current page - no funny business! + $this->cur_page = preg_replace("/[a-z\-]/", "", $this->cur_page); } - + if ( ! is_numeric($this->cur_page)) { $this->cur_page = 0; -- cgit v1.2.3-24-g4f1b From 57b9e5c5350ffb20048d36c508d1e310603b12f8 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 31 Oct 2006 07:11:36 +0000 Subject: --- system/libraries/Ftp.php | 4 ++-- system/libraries/Model.php | 9 ++------- 2 files changed, 4 insertions(+), 9 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 3b2be23d5..1572a587c 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -178,7 +178,7 @@ class CI_FTP { if ($result === FALSE) { - if ($this->debug == TRUE AND $supress_debug != TRUE) + if ($this->debug == TRUE AND $supress_debug == FALSE) { $this->_error('ftp_unable_to_changedir'); } @@ -251,7 +251,7 @@ class CI_FTP { // Set the mode if not specified if ($mode == 'auto') { - // Get the file extension so we can se the upload type + // Get the file extension so we can set the upload type $ext = $this->_getext($locpath); $mode = $this->_settype($ext); } diff --git a/system/libraries/Model.php b/system/libraries/Model.php index 1c2b7afce..6f4f7e7ef 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -40,12 +40,7 @@ class Model { // 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 - $methods = get_class_methods($this); - - if (isset($methods[0])) - { - $this->_parent_name = $methods[0]; - } + $this->_parent_name = ucfirst(get_class($this)); log_message('debug', "Model Class Initialized"); } @@ -65,7 +60,7 @@ class Model { 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) -- cgit v1.2.3-24-g4f1b From 9139b0c4d57a6052b54838aedb54e70eb683f34c Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 31 Oct 2006 17:59:16 +0000 Subject: --- system/libraries/Loader.php | 107 +++++++++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 47 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 117626567..aa1ae8cb4 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -34,6 +34,7 @@ class CI_Loader { var $_ci_is_php5 = FALSE; var $_ci_is_instance = FALSE; // Whether we should use $this or $CI =& get_instance() var $_ci_cached_vars = array(); + var $_ci_classes = array(); var $_ci_models = array(); var $_ci_helpers = array(); var $_ci_plugins = array(); @@ -305,17 +306,17 @@ class CI_Loader { } foreach ($helpers as $helper) - { + { + $helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper'); + if (isset($this->_ci_helpers[$helper])) { continue; } - - $helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper'); - + if (file_exists(APPPATH.'helpers/'.$helper.EXT)) - { - include(APPPATH.'helpers/'.$helper.EXT); + { + include_once(APPPATH.'helpers/'.$helper.EXT); } else { @@ -330,6 +331,7 @@ class CI_Loader { } $this->_ci_helpers[$helper] = TRUE; + } log_message('debug', 'Helpers loaded: '.implode(', ', $helpers)); @@ -371,14 +373,14 @@ class CI_Loader { } foreach ($plugins as $plugin) - { + { + $plugin = strtolower(str_replace(EXT, '', str_replace('_plugin.', '', $plugin)).'_pi'); + if (isset($this->_ci_plugins[$plugin])) { continue; } - - $plugin = strtolower(str_replace(EXT, '', str_replace('_plugin.', '', $plugin)).'_pi'); - + if (file_exists(APPPATH.'plugins/'.$plugin.EXT)) { include(APPPATH.'plugins/'.$plugin.EXT); @@ -441,13 +443,13 @@ class CI_Loader { } foreach ($scripts as $script) - { + { + $script = strtolower(str_replace(EXT, '', $script)); + if (isset($this->_ci_scripts[$script])) { continue; } - - $script = strtolower(str_replace(EXT, '', $script)); if ( ! file_exists(APPPATH.'scripts/'.$script.EXT)) { @@ -455,8 +457,6 @@ class CI_Loader { } include(APPPATH.'scripts/'.$script.EXT); - - $this->_ci_scripts[$script] = TRUE; } log_message('debug', 'Scripts loaded: '.implode(', ', $scripts)); @@ -534,6 +534,30 @@ class CI_Loader { */ function _ci_load($data) { + // Set the default data variables + foreach (array('view', 'vars', 'path', 'return') as $val) + { + $$val = ( ! isset($data[$val])) ? FALSE : $data[$val]; + } + + // Set the path to the requested file + if ($path == '') + { + $ext = pathinfo($view, PATHINFO_EXTENSION); + $file = ($ext == '') ? $view.EXT : $view; + $path = $this->_ci_view_path.$file; + } + else + { + $x = explode('/', $path); + $file = end($x); + } + + if ( ! file_exists($path)) + { + show_error('Unable to load the requested file: '.$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 @@ -550,12 +574,6 @@ class CI_Loader { } } - // Set the default data variables - foreach (array('view', 'vars', 'path', 'return') as $val) - { - $$val = ( ! isset($data[$val])) ? FALSE : $data[$val]; - } - /* * Extract and cache variables * @@ -570,19 +588,6 @@ class CI_Loader { } extract($this->_ci_cached_vars); - // Set the path to the requested file - if ($path == '') - { - $ext = pathinfo($view, PATHINFO_EXTENSION); - $file = ($ext == '') ? $view.EXT : $view; - $path = $this->_ci_view_path.$file; - } - else - { - $x = explode('/', $path); - $file = end($x); - } - /* * Buffer the output * @@ -595,11 +600,6 @@ class CI_Loader { * can intercept the content right before it's sent to * the browser and then stop the timer it won't be accurate. */ - if ( ! file_exists($path)) - { - show_error('Unable to load the requested file: '.$file); - } - ob_start(); // If the PHP installation does not support short tags we'll @@ -682,19 +682,32 @@ class CI_Loader { } // Lets search for the requested library file and load it. + $is_duplicate = FALSE; for ($i = 1; $i < 3; $i++) { - $path = ($i % 2) ? APPPATH : BASEPATH; - if (file_exists($path.'libraries/'.$class.EXT)) + $path = ($i % 2) ? APPPATH : BASEPATH; + + $fp = $path.'libraries/'.$class.EXT; + + // Safety: Was the class already loaded by a previous call? + if (in_array($fp, $this->_ci_classes) OR ! file_exists($fp)) { - include($path.'libraries/'.$class.EXT); - return $this->_ci_init_class($class, '', $params); + $is_duplicate = TRUE; + continue; } + + include($fp); + $this->_ci_classes[] = $fp; + return $this->_ci_init_class($class, '', $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) + { + log_message('error', "Unable to load the requested class: ".$class); + show_error("Unable to load the requested class: ".$class); } - - // If we got this far we were unable to find the requested class - log_message('error', "Unable to load the requested class: ".$class); - show_error("Unable to load the requested class: ".$class); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 69d3984b0b2ee417c98573185edfd47c3087539b Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 31 Oct 2006 18:01:00 +0000 Subject: --- system/libraries/Loader.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index aa1ae8cb4..5db9886b4 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -686,11 +686,16 @@ class CI_Loader { for ($i = 1; $i < 3; $i++) { $path = ($i % 2) ? APPPATH : BASEPATH; - $fp = $path.'libraries/'.$class.EXT; + // Does the file exist? No? Bummer... + if ( ! file_exists($fp)) + { + continue; + } + // Safety: Was the class already loaded by a previous call? - if (in_array($fp, $this->_ci_classes) OR ! file_exists($fp)) + if (in_array($fp, $this->_ci_classes)) { $is_duplicate = TRUE; continue; -- cgit v1.2.3-24-g4f1b From c6317e8747953575d3d4f553de37533889f504d1 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 31 Oct 2006 18:16:12 +0000 Subject: --- system/libraries/Profiler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index e03097ab6..1d78da8a8 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -83,7 +83,7 @@ class CI_Profiler { foreach ($profile as $key => $val) { $key = ucwords(str_replace(array('_', '-'), ' ', $key)); - $output .= "".$key."  ".$val."\n"; + $output .= "".$key."  ".$val."\n"; } $output .= "\n"; @@ -165,7 +165,7 @@ class CI_Profiler { $key = "'".$key."'"; } - $output .= "$_POST[".$key."]  ".htmlspecialchars(stripslashes($val))."\n"; + $output .= "$_POST[".$key."]  ".htmlspecialchars(stripslashes($val))."\n"; } $output .= "\n"; -- cgit v1.2.3-24-g4f1b From afde68a64095e6408f5f28962405c4586d9eb4c6 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 1 Nov 2006 03:44:36 +0000 Subject: --- system/libraries/Input.php | 1 - 1 file changed, 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 8408b16fc..b630bf6b8 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -436,7 +436,6 @@ class CI_Input { * these are the ones that will pose security problems. * */ - if (preg_match_all("/<(.+?)>/si", $str, $matches)) { for ($i = 0; $i < count($matches['0']); $i++) -- cgit v1.2.3-24-g4f1b From be013b3270f751e248efcbe82d5ea28e9386ce05 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 4 Nov 2006 05:07:03 +0000 Subject: --- system/libraries/Loader.php | 106 +++++++++++++++++++++++++------------------- 1 file changed, 61 insertions(+), 45 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 5db9886b4..41c0a9b94 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -71,12 +71,25 @@ class CI_Loader { * @param mixed the optional parameters * @return void */ - function library($class, $params = NULL) + function library($library = '', $params = NULL) { - if ($class == '') - return; - - $this->_ci_load_class($class, $params); + if ($library == '') + { + return FALSE; + } + + if (is_array($library)) + { + foreach ($library as $class) + { + $this->_ci_load_class($class, $params); + } + } + else + { + $this->_ci_load_class($library, $params); + } + $this->_ci_assign_to_models(); } @@ -621,8 +634,7 @@ class CI_Loader { if ($return === TRUE) { $buffer = ob_get_contents(); - ob_end_clean(); - + @ob_end_clean(); return $buffer; } @@ -645,7 +657,7 @@ class CI_Loader { // PHP 4 requires that we use a global global $OUT; $OUT->set_output(ob_get_contents()); - ob_end_clean(); + @ob_end_clean(); } } @@ -663,49 +675,53 @@ class CI_Loader { */ function _ci_load_class($class, $params = NULL) { - // Prep the class name - $class = ucfirst(strtolower(str_replace(EXT, '', $class))); - - // Is this a class extension request? - if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT)) - { - if ( ! file_exists(BASEPATH.'libraries/'.$class.EXT)) - { - log_message('error', "Unable to load the requested class: ".$class); - show_error("Unable to load the requested class: ".$class); - } - - include(BASEPATH.'libraries/'.ucfirst($class).EXT); - include(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT); - - return $this->_ci_init_class($class, config_item('subclass_prefix'), $params); - } + // Get the class name + $class = str_replace(EXT, '', $class); - // Lets search for the requested library file and load it. - $is_duplicate = FALSE; - for ($i = 1; $i < 3; $i++) + // We'll test for both lowercase and capitalized versions of the file name + foreach (array(ucfirst($class), strtolower($class)) as $class) { - $path = ($i % 2) ? APPPATH : BASEPATH; - $fp = $path.'libraries/'.$class.EXT; - - // Does the file exist? No? Bummer... - if ( ! file_exists($fp)) + // Is this a class extension request? + if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT)) { - continue; + if ( ! file_exists(BASEPATH.'libraries/'.ucfirst($class).EXT)) + { + log_message('error', "Unable to load the requested class: ".$class); + show_error("Unable to load the requested class: ".$class); + } + + include(BASEPATH.'libraries/'.ucfirst($class).EXT); + include(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT); + + return $this->_ci_init_class($class, config_item('subclass_prefix'), $params); } - - // Safety: Was the class already loaded by a previous call? - if (in_array($fp, $this->_ci_classes)) + + // Lets search for the requested library file and load it. + $is_duplicate = FALSE; + for ($i = 1; $i < 3; $i++) { - $is_duplicate = TRUE; - continue; + $path = ($i % 2) ? APPPATH : BASEPATH; + $fp = $path.'libraries/'.$class.EXT; + + // Does the file exist? No? Bummer... + if ( ! file_exists($fp)) + { + continue; + } + + // Safety: Was the class already loaded by a previous call? + if (in_array($fp, $this->_ci_classes)) + { + $is_duplicate = TRUE; + continue; + } + + include($fp); + $this->_ci_classes[] = $fp; + return $this->_ci_init_class($class, '', $params); } - - include($fp); - $this->_ci_classes[] = $fp; - return $this->_ci_init_class($class, '', $params); - } - + } // END FOREACH + // 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) -- cgit v1.2.3-24-g4f1b From ebfa686046bb98c757d1b41c81eb867478036e68 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 5 Nov 2006 21:31:00 +0000 Subject: --- system/libraries/Ftp.php | 2 +- system/libraries/Profiler.php | 2 +- system/libraries/User_agent.php | 2 +- system/libraries/Zip.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 1572a587c..f213736fb 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -22,7 +22,7 @@ * @subpackage Libraries * @category Libraries * @author Rick Ellis - * @link http://www.codeigniter.com/user_guide/libraries/encryption.html + * @link http://www.codeigniter.com/user_guide/libraries/ftp.html */ class CI_FTP { diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 1d78da8a8..5b0f6e2b7 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -28,7 +28,7 @@ * @subpackage Libraries * @category Libraries * @author Rick Ellis - * @link http://www.codeigniter.com/user_guide/libraries/benchmark.html + * @link http://www.codeigniter.com/user_guide/general/profiling.html */ class CI_Profiler { diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index b217367fe..8d160672f 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -24,7 +24,7 @@ * @subpackage Libraries * @category User Agent * @author Rick Ellis - * @link http://www.codeigniter.com/user_guide/libraries/uri.html + * @link http://www.codeigniter.com/user_guide/libraries/user_agent.html */ class CI_User_agent { diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 828ef0c25..1ff175fe2 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -28,7 +28,7 @@ * @subpackage Libraries * @category Encryption * @author Rick Ellis - * @link http://www.codeigniter.com/user_guide/general/encryption.html + * @link http://www.codeigniter.com/user_guide/libraries/zip.html */ class CI_Zip { -- cgit v1.2.3-24-g4f1b From 325197e700564f8e4e0ba7c9fc82abfd85f451b0 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 20 Nov 2006 17:29:05 +0000 Subject: --- system/libraries/Exceptions.php | 6 ++++-- system/libraries/Input.php | 6 ++++-- system/libraries/User_agent.php | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Exceptions.php b/system/libraries/Exceptions.php index 8f90ff8f9..839093911 100644 --- a/system/libraries/Exceptions.php +++ b/system/libraries/Exceptions.php @@ -30,6 +30,7 @@ class CI_Exceptions { var $message; var $filename; var $line; + var $ob_level; var $levels = array( E_ERROR => 'Error', @@ -53,6 +54,7 @@ class CI_Exceptions { */ function CI_Exceptions() { + $this->ob_level = ob_get_level(); // Note: Do not log messages from this constructor. } @@ -115,7 +117,7 @@ class CI_Exceptions { { $message = '

'.implode('

', ( ! is_array($message)) ? array($message) : $message).'

'; - if (ob_get_level() > 1) + if (ob_get_level() > $this->ob_level + 1) { ob_end_flush(); } @@ -151,7 +153,7 @@ class CI_Exceptions { $filepath = $x[count($x)-2].'/'.end($x); } - if (ob_get_level() > 1) + if (ob_get_level() > $this->ob_level + 1) { ob_end_flush(); } diff --git a/system/libraries/Input.php b/system/libraries/Input.php index b630bf6b8..801762073 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -73,13 +73,15 @@ class CI_Input { { if ( ! is_array($global)) { - unset($$global); + global $global; + $$global = NULL; } else { foreach ($global as $key => $val) { - unset($$key); + global $$key; + $$key = NULL; } } } diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 8d160672f..95eccd124 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -186,6 +186,7 @@ class CI_User_agent { $this->is_browser = TRUE; $this->version = $match[1]; $this->browser = $val; + $this->_set_mobile(); return TRUE; } } -- cgit v1.2.3-24-g4f1b From 6f62816ef1212a501d5f6c27110e2e5d81a6ebe2 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 24 Nov 2006 01:17:45 +0000 Subject: --- system/libraries/Loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 41c0a9b94..0947046ed 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -146,7 +146,7 @@ class CI_Loader { show_error('Unable to locate the model you have specified: '.$model); } - if ($db_conn !== FALSE) + if ($db_conn !== FALSE AND ! class_exists('CI_DB')) { if ($db_conn === TRUE) $db_conn = ''; -- cgit v1.2.3-24-g4f1b From 40a7c6805f4a65605963f10dc2db0fc748710779 Mon Sep 17 00:00:00 2001 From: paulburdick Date: Sat, 13 Jan 2007 00:03:37 +0000 Subject: --- system/libraries/Input.php | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 801762073..4fd2061c7 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -366,14 +366,14 @@ class CI_Input { * XSS Clean * * Sanitizes data so that Cross Site Scripting Hacks can be - * prevented.Ê This function does a fair amount of work but + * prevented.  This function does a fair amount of work but * it is extremely thorough, designed to prevent even the - * most obscure XSS attempts.Ê Nothing is ever 100% foolproof, + * most obscure XSS attempts.  Nothing is ever 100% foolproof, * of course, but I haven't been able to get anything passed * the filter. * * Note: This function should only be used to deal with data - * upon submission.Ê It's not something that should + * upon submission.  It's not something that should * be used for general runtime processing. * * This function was based in part on some code and ideas I @@ -447,6 +447,24 @@ class CI_Input { $str); } } + + /* + * Not Allowed Under Any Conditions + */ + $bad = array( + 'document.cookie' => '[removed]', + 'document.write' => '[removed]', + 'window.location' => '[removed]', + "javascript\s*:" => '[removed]', + "Redirect\s+302" => '[removed]', + '' => '-->' + ); + + foreach ($bad as $key => $val) + { + $str = preg_replace("#".$key."#i", $val, $str); + } /* * Convert all tabs to spaces @@ -542,11 +560,11 @@ class CI_Input { * */ $bad = array( - 'document.cookie' => '', - 'document.write' => '', - 'window.location' => '', - "javascript\s*:" => '', - "Redirect\s+302" => '', + 'document.cookie' => '[removed]', + 'document.write' => '[removed]', + 'window.location' => '[removed]', + "javascript\s*:" => '[removed]', + "Redirect\s+302" => '[removed]', '' => '-->' ); -- cgit v1.2.3-24-g4f1b From 5932c867a10ed38d58a51b40a3898ea70605f3cd Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 27 Jan 2007 17:44:54 +0000 Subject: added set_caption() --- system/libraries/Table.php | 853 +++++++++++++++++++++++---------------------- 1 file changed, 438 insertions(+), 415 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 1b25a441a..b8ce9491a 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -1,416 +1,439 @@ -template = $template; - } - - // -------------------------------------------------------------------- - - /** - * Set the table heading - * - * Can be passed as an array or discreet params - * - * @access public - * @param mixed - * @return void - */ - function set_heading() - { - $args = func_get_args(); - $this->heading = (is_array($args[0])) ? $args[0] : $args; - } - - // -------------------------------------------------------------------- - - /** - * Set columns. Takes a one-dimensional array as input and creates - * a multi-dimensional array with a depth equal to the number of - * columns. This allows a single array with many elements to be - * displayed in a table that has a fixed column count. - * - * @access public - * @param array - * @param int - * @return void - */ - function make_columns($array = array(), $col_limit = 0) - { - if ( ! is_array($array) OR count($array) == 0) - { - return FALSE; - } - - // 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_slice($array, 0, $col_limit); - $array = array_diff($array, $temp); - - if (count($temp) < $col_limit) - { - for ($i = count($temp); $i < $col_limit; $i++) - { - $temp[] = ' '; - } - } - - $new[] = $temp; - } - - return $new; - } - - // -------------------------------------------------------------------- - - /** - * Set "empty" cells - * - * Can be passed as an array or discreet params - * - * @access public - * @param mixed - * @return void - */ - function set_empty($value) - { - $this->empty_cells = $value; - } - - // -------------------------------------------------------------------- - - /** - * Add a table row - * - * Can be passed as an array or discreet params - * - * @access public - * @param mixed - * @return void - */ - function add_row() - { - $args = func_get_args(); - $this->rows[] = (is_array($args[0])) ? $args[0] : $args; - } - - // -------------------------------------------------------------------- - - /** - * Generate the table - * - * @access public - * @param mixed - * @return string - */ - function generate($table_data = NULL) - { - // The table data can optionally be passed to this function - // either as a database result object or an array - if ( ! is_null($table_data)) - { - if (is_object($table_data)) - { - $this->_set_from_object($table_data); - } - elseif (is_array($table_data)) - { - $set_heading = (count($this->heading) == 0 AND $this->auto_heading == FALSE) ? FALSE : TRUE; - $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(); - - - // Build the table! - - $out = $this->template['table_open']; - $out .= $this->newline; - - // Is there a table heading to display? - if (count($this->heading) > 0) - { - $out .= $this->template['heading_row_start']; - $out .= $this->newline; - - foreach($this->heading as $heading) - { - $out .= $this->template['heading_cell_start']; - $out .= $heading; - $out .= $this->template['heading_cell_end']; - } - - $out .= $this->template['heading_row_end']; - $out .= $this->newline; - } - - // Build the table rows - if (count($this->rows) > 0) - { - $i = 1; - foreach($this->rows as $row) - { - if ( ! is_array($row)) - { - break; - } - - // We use modulus to alternate the row colors - $name = (fmod($i++, 2)) ? '' : 'alt_'; - - $out .= $this->template['row_'.$name.'start']; - $out .= $this->newline; - - foreach($row as $cell) - { - $out .= $this->template['cell_'.$name.'start']; - - if ($cell == "") - { - $out .= $this->empty_cells; - } - else - { - $out .= $cell; - } - - $out .= $this->template['cell_'.$name.'end']; - } - - $out .= $this->template['row_'.$name.'end']; - $out .= $this->newline; - } - } - - $out .= $this->template['table_close']; - - return $out; - } - - // -------------------------------------------------------------------- - - /** - * Clears the table arrays. Useful if multiple tables are beting generated - * - * @access public - * @return void - */ - function clear() - { - $this->rows = array(); - $this->heading = array(); - $this->auto_heading = TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set table data from a database result object - * - * @access public - * @param object - * @return void - */ - function _set_from_object($query) - { - if ( ! is_object($query)) - { - return FALSE; - } - - // First generate the headings from the table column names - if (count($this->heading) == 0) - { - if ( ! method_exists($query, 'list_fields')) - { - return FALSE; - } - - $this->heading = $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) - { - $this->rows[] = $row; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Set table data from an array - * - * @access public - * @param array - * @return void - */ - function _set_from_array($data, $set_heading = TRUE) - { - if ( ! is_array($data) OR count($data) == 0) - { - return FALSE; - } - - $i = 0; - foreach ($data as $row) - { - if ( ! is_array($row)) - { - $this->rows[] = $data; - break; - } - - // 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) - { - $this->heading = $row; - } - else - { - $this->rows[] = $row; - } - - $i++; - } - } - - // -------------------------------------------------------------------- - - /** - * Compile Template - * - * @access private - * @return void - */ - function _compile_template() - { - if ($this->template == NULL) - { - $this->template = $this->_default_template(); - return; - } - - $this->temp = $this->_default_template(); - foreach (array('table_open','heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end', 'row_start', 'row_end', 'cell_start', 'cell_end', 'row_alt_start', 'row_alt_end', 'cell_alt_start', 'cell_alt_end', 'table_close') as $val) - { - if ( ! isset($this->template[$val])) - { - $this->template[$val] = $this->temp[$val]; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Default Template - * - * @access private - * @return void - */ - function _default_template() - { - return array ( - 'table_open' => '', - - 'heading_row_start' => '', - 'heading_row_end' => '', - 'heading_cell_start' => '', - - 'row_start' => '', - 'row_end' => '', - 'cell_start' => '', - - 'row_alt_start' => '', - 'row_alt_end' => '', - 'cell_alt_start' => '', - - 'table_close' => '
', - 'heading_cell_end' => '
', - 'cell_end' => '
', - 'cell_alt_end' => '
' - ); - } - - -} - +template = $template; + } + + // -------------------------------------------------------------------- + + /** + * Set the table heading + * + * Can be passed as an array or discreet params + * + * @access public + * @param mixed + * @return void + */ + function set_heading() + { + $args = func_get_args(); + $this->heading = (is_array($args[0])) ? $args[0] : $args; + } + + // -------------------------------------------------------------------- + + /** + * Set columns. Takes a one-dimensional array as input and creates + * a multi-dimensional array with a depth equal to the number of + * columns. This allows a single array with many elements to be + * displayed in a table that has a fixed column count. + * + * @access public + * @param array + * @param int + * @return void + */ + function make_columns($array = array(), $col_limit = 0) + { + if ( ! is_array($array) OR count($array) == 0) + { + return FALSE; + } + + // 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_slice($array, 0, $col_limit); + $array = array_diff($array, $temp); + + if (count($temp) < $col_limit) + { + for ($i = count($temp); $i < $col_limit; $i++) + { + $temp[] = ' '; + } + } + + $new[] = $temp; + } + + return $new; + } + + // -------------------------------------------------------------------- + + /** + * Set "empty" cells + * + * Can be passed as an array or discreet params + * + * @access public + * @param mixed + * @return void + */ + function set_empty($value) + { + $this->empty_cells = $value; + } + + // -------------------------------------------------------------------- + + /** + * Add a table row + * + * Can be passed as an array or discreet params + * + * @access public + * @param mixed + * @return void + */ + function add_row() + { + $args = func_get_args(); + $this->rows[] = (is_array($args[0])) ? $args[0] : $args; + } + + // -------------------------------------------------------------------- + + /** + * Add a table caption + * + * @access public + * @param string + * @return void + */ + function set_caption($caption) + { + $this->caption = $caption; + } + + // -------------------------------------------------------------------- + + /** + * Generate the table + * + * @access public + * @param mixed + * @return string + */ + function generate($table_data = NULL) + { + // The table data can optionally be passed to this function + // either as a database result object or an array + if ( ! is_null($table_data)) + { + if (is_object($table_data)) + { + $this->_set_from_object($table_data); + } + elseif (is_array($table_data)) + { + $set_heading = (count($this->heading) == 0 AND $this->auto_heading == FALSE) ? FALSE : TRUE; + $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(); + + + // Build the table! + + $out = $this->template['table_open']; + $out .= $this->newline; + + // Add any caption here + if ($this->caption) + { + $out .= $this->newline; + $out .= '' . $this->caption . ''; + $out .= $this->newline; + } + + // Is there a table heading to display? + if (count($this->heading) > 0) + { + $out .= $this->template['heading_row_start']; + $out .= $this->newline; + + foreach($this->heading as $heading) + { + $out .= $this->template['heading_cell_start']; + $out .= $heading; + $out .= $this->template['heading_cell_end']; + } + + $out .= $this->template['heading_row_end']; + $out .= $this->newline; + } + + // Build the table rows + if (count($this->rows) > 0) + { + $i = 1; + foreach($this->rows as $row) + { + if ( ! is_array($row)) + { + break; + } + + // We use modulus to alternate the row colors + $name = (fmod($i++, 2)) ? '' : 'alt_'; + + $out .= $this->template['row_'.$name.'start']; + $out .= $this->newline; + + foreach($row as $cell) + { + $out .= $this->template['cell_'.$name.'start']; + + if ($cell == "") + { + $out .= $this->empty_cells; + } + else + { + $out .= $cell; + } + + $out .= $this->template['cell_'.$name.'end']; + } + + $out .= $this->template['row_'.$name.'end']; + $out .= $this->newline; + } + } + + $out .= $this->template['table_close']; + + return $out; + } + + // -------------------------------------------------------------------- + + /** + * Clears the table arrays. Useful if multiple tables are beting generated + * + * @access public + * @return void + */ + function clear() + { + $this->rows = array(); + $this->heading = array(); + $this->auto_heading = TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Set table data from a database result object + * + * @access public + * @param object + * @return void + */ + function _set_from_object($query) + { + if ( ! is_object($query)) + { + return FALSE; + } + + // First generate the headings from the table column names + if (count($this->heading) == 0) + { + if ( ! method_exists($query, 'list_fields')) + { + return FALSE; + } + + $this->heading = $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) + { + $this->rows[] = $row; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Set table data from an array + * + * @access public + * @param array + * @return void + */ + function _set_from_array($data, $set_heading = TRUE) + { + if ( ! is_array($data) OR count($data) == 0) + { + return FALSE; + } + + $i = 0; + foreach ($data as $row) + { + if ( ! is_array($row)) + { + $this->rows[] = $data; + break; + } + + // 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) + { + $this->heading = $row; + } + else + { + $this->rows[] = $row; + } + + $i++; + } + } + + // -------------------------------------------------------------------- + + /** + * Compile Template + * + * @access private + * @return void + */ + function _compile_template() + { + if ($this->template == NULL) + { + $this->template = $this->_default_template(); + return; + } + + $this->temp = $this->_default_template(); + foreach (array('table_open','heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end', 'row_start', 'row_end', 'cell_start', 'cell_end', 'row_alt_start', 'row_alt_end', 'cell_alt_start', 'cell_alt_end', 'table_close') as $val) + { + if ( ! isset($this->template[$val])) + { + $this->template[$val] = $this->temp[$val]; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Default Template + * + * @access private + * @return void + */ + function _default_template() + { + return array ( + 'table_open' => '', + + 'heading_row_start' => '', + 'heading_row_end' => '', + 'heading_cell_start' => '', + + 'row_start' => '', + 'row_end' => '', + 'cell_start' => '', + + 'row_alt_start' => '', + 'row_alt_end' => '', + 'cell_alt_start' => '', + + 'table_close' => '
', + 'heading_cell_end' => '
', + 'cell_end' => '
', + 'cell_alt_end' => '
' + ); + } + + +} + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c250b144dcfab2c2667b6eec3fcb1b396cdf3c28 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 27 Jan 2007 17:56:40 +0000 Subject: fixed $moble to $mobile --- system/libraries/User_agent.php | 998 ++++++++++++++++++++-------------------- 1 file changed, 499 insertions(+), 499 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 95eccd124..afd012e30 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -1,500 +1,500 @@ -agent = trim($_SERVER['HTTP_USER_AGENT']); - } - - if ( ! is_null($this->agent)) - { - if ($this->_load_agent_file()) - { - $this->_compile_data(); - } - } - - log_message('debug', "Table 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; - unset($platforms); - $return = TRUE; - } - - if (isset($browsers)) - { - $this->browsers = $browsers; - unset($browsers); - $return = TRUE; - } - - if (isset($mobiles)) - { - $this->mobiles = $mobiles; - unset($mobiles); - $return = TRUE; - } - - if (isset($robots)) - { - $this->robots = $robots; - unset($robots); - $return = TRUE; - } - - 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) - { - foreach ($this->platforms as $key => $val) - { - if (preg_match("|".preg_quote($key)."|i", $this->agent)) - { - $this->platform = $val; - return TRUE; - } - } - } - $this->platform = 'Unknown Platform'; - } - - // -------------------------------------------------------------------- - - /** - * 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; - $this->version = $match[1]; - $this->browser = $val; - $this->_set_mobile(); - return TRUE; - } - } - } - 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)) - { - $this->is_robot = TRUE; - $this->robot = $val; - return TRUE; - } - } - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * 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))) - { - $this->is_mobile = TRUE; - $this->mobile = $val; - 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=.+)/i', '', 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', '', 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; - } - - -} - +agent = trim($_SERVER['HTTP_USER_AGENT']); + } + + if ( ! is_null($this->agent)) + { + if ($this->_load_agent_file()) + { + $this->_compile_data(); + } + } + + log_message('debug', "Table 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; + unset($platforms); + $return = TRUE; + } + + if (isset($browsers)) + { + $this->browsers = $browsers; + unset($browsers); + $return = TRUE; + } + + if (isset($mobiles)) + { + $this->mobiles = $mobiles; + unset($mobiles); + $return = TRUE; + } + + if (isset($robots)) + { + $this->robots = $robots; + unset($robots); + $return = TRUE; + } + + 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) + { + foreach ($this->platforms as $key => $val) + { + if (preg_match("|".preg_quote($key)."|i", $this->agent)) + { + $this->platform = $val; + return TRUE; + } + } + } + $this->platform = 'Unknown Platform'; + } + + // -------------------------------------------------------------------- + + /** + * 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; + $this->version = $match[1]; + $this->browser = $val; + $this->_set_mobile(); + return TRUE; + } + } + } + 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)) + { + $this->is_robot = TRUE; + $this->robot = $val; + return TRUE; + } + } + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * 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))) + { + $this->is_mobile = TRUE; + $this->mobile = $val; + 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=.+)/i', '', 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', '', 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; + } + + +} + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b29d37c1d070b1e3790c7ce7429c59d789a5ed4b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 28 Jan 2007 16:05:51 +0000 Subject: log_exception() printed severity twice... fixed. --- system/libraries/Exceptions.php | 338 ++++++++++++++++++++-------------------- 1 file changed, 169 insertions(+), 169 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Exceptions.php b/system/libraries/Exceptions.php index 839093911..03588acb3 100644 --- a/system/libraries/Exceptions.php +++ b/system/libraries/Exceptions.php @@ -1,170 +1,170 @@ - 'Error', - E_WARNING => 'Warning', - E_PARSE => 'Parsing Error', - E_NOTICE => 'Notice', - E_CORE_ERROR => 'Core Error', - E_CORE_WARNING => 'Core Warning', - E_COMPILE_ERROR => 'Compile Error', - E_COMPILE_WARNING => 'Compile Warning', - E_USER_ERROR => 'User Error', - E_USER_WARNING => 'User Warning', - E_USER_NOTICE => 'User Notice', - E_STRICT => 'Runtime Notice' - ); - - - /** - * Constructor - * - */ - function CI_Exceptions() - { - $this->ob_level = ob_get_level(); - // Note: Do not log messages from this constructor. - } - - // -------------------------------------------------------------------- - - /** - * Exception Logger - * - * This function logs PHP generated error messages - * - * @access private - * @param string the error severity - * @param string the error string - * @param string the error filepath - * @param string the error line number - * @return string - */ - function log_exception($severity, $message, $filepath, $line) - { - $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; - - log_message('error', 'Severity: '.$severity.' '.$severity.' --> '.$message. ' '.$filepath.' '.$line, TRUE); - } - - // -------------------------------------------------------------------- - - /** - * 404 Page Not Found Handler - * - * @access private - * @param string - * @return string - */ - function show_404($page = '') - { - $heading = "404 Page Not Found"; - $message = "The page you requested was not found."; - - log_message('error', '404 Page Not Found --> '.$page); - echo $this->show_error($heading, $message, 'error_404'); - exit; - } - - // -------------------------------------------------------------------- - - /** - * General Error Page - * - * This function takes an error message as input - * (either as a string or an array) and displays - * it using the specified template. - * - * @access private - * @param string the heading - * @param string the message - * @param string the template name - * @return string - */ - function show_error($heading, $message, $template = 'error_general') - { - $message = '

'.implode('

', ( ! is_array($message)) ? array($message) : $message).'

'; - - if (ob_get_level() > $this->ob_level + 1) - { - ob_end_flush(); - } - ob_start(); - include(APPPATH.'errors/'.$template.EXT); - $buffer = ob_get_contents(); - ob_end_clean(); - return $buffer; - } - - // -------------------------------------------------------------------- - - /** - * Native PHP error handler - * - * @access private - * @param string the error severity - * @param string the error string - * @param string the error filepath - * @param string the error line number - * @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_start(); - include(APPPATH.'errors/error_php'.EXT); - $buffer = ob_get_contents(); - ob_end_clean(); - echo $buffer; - } - - -} -// END Exceptions Class + 'Error', + E_WARNING => 'Warning', + E_PARSE => 'Parsing Error', + E_NOTICE => 'Notice', + E_CORE_ERROR => 'Core Error', + E_CORE_WARNING => 'Core Warning', + E_COMPILE_ERROR => 'Compile Error', + E_COMPILE_WARNING => 'Compile Warning', + E_USER_ERROR => 'User Error', + E_USER_WARNING => 'User Warning', + E_USER_NOTICE => 'User Notice', + E_STRICT => 'Runtime Notice' + ); + + + /** + * Constructor + * + */ + function CI_Exceptions() + { + $this->ob_level = ob_get_level(); + // Note: Do not log messages from this constructor. + } + + // -------------------------------------------------------------------- + + /** + * Exception Logger + * + * This function logs PHP generated error messages + * + * @access private + * @param string the error severity + * @param string the error string + * @param string the error filepath + * @param string the error line number + * @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); + } + + // -------------------------------------------------------------------- + + /** + * 404 Page Not Found Handler + * + * @access private + * @param string + * @return string + */ + function show_404($page = '') + { + $heading = "404 Page Not Found"; + $message = "The page you requested was not found."; + + log_message('error', '404 Page Not Found --> '.$page); + echo $this->show_error($heading, $message, 'error_404'); + exit; + } + + // -------------------------------------------------------------------- + + /** + * General Error Page + * + * This function takes an error message as input + * (either as a string or an array) and displays + * it using the specified template. + * + * @access private + * @param string the heading + * @param string the message + * @param string the template name + * @return string + */ + function show_error($heading, $message, $template = 'error_general') + { + $message = '

'.implode('

', ( ! is_array($message)) ? array($message) : $message).'

'; + + if (ob_get_level() > $this->ob_level + 1) + { + ob_end_flush(); + } + ob_start(); + include(APPPATH.'errors/'.$template.EXT); + $buffer = ob_get_contents(); + ob_end_clean(); + return $buffer; + } + + // -------------------------------------------------------------------- + + /** + * Native PHP error handler + * + * @access private + * @param string the error severity + * @param string the error string + * @param string the error filepath + * @param string the error line number + * @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_start(); + include(APPPATH.'errors/error_php'.EXT); + $buffer = ob_get_contents(); + ob_end_clean(); + echo $buffer; + } + + +} +// END Exceptions Class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From a72b60d96cbdbfc10fbe20d2c4a3c4a62358b4d3 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 31 Jan 2007 23:56:11 +0000 Subject: removed unescaped variable that could be used in XSS --- system/libraries/Input.php | 1278 +++++++++++++++++++++---------------------- system/libraries/Router.php | 1120 ++++++++++++++++++------------------- 2 files changed, 1199 insertions(+), 1199 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 4fd2061c7..f346cabaa 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -1,640 +1,640 @@ -use_xss_clean = ($CFG->item('global_xss_filtering') === TRUE) ? TRUE : FALSE; - $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; - $this->_sanitize_globals(); - } - - // -------------------------------------------------------------------- - - /** - * Sanitize Globals - * - * This function does the following: - * - * Unsets $_GET data (if query strings are not enabled) - * - * Unsets all globals if register_globals is enabled - * - * Standardizes newline characters to \n - * - * @access private - * @return void - */ - function _sanitize_globals() - { - // Unset globals. This is effectively the same as register_globals = off - foreach (array($_GET, $_POST, $_COOKIE) as $global) - { - if ( ! is_array($global)) - { - global $global; - $$global = NULL; - } - else - { - foreach ($global as $key => $val) - { - global $$key; - $$key = NULL; - } - } - } - - // Is $_GET data allowed? If not we'll set the $_GET to an empty array - if ($this->allow_get_array == FALSE) - { - $_GET = array(); - } - - // Clean $_POST Data - if (is_array($_POST) AND count($_POST) > 0) - { - foreach($_POST as $key => $val) - { - $_POST[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); - } - } - - // Clean $_COOKIE Data - if (is_array($_COOKIE) AND count($_COOKIE) > 0) - { - foreach($_COOKIE as $key => $val) - { - $_COOKIE[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); - } - } - - log_message('debug', "Global POST and COOKIE data sanitized"); - } - - // -------------------------------------------------------------------- - - /** - * Clean Input Data - * - * This is a helper function. It escapes data and - * standardizes newline characters to \n - * - * @access private - * @param string - * @return string - */ - function _clean_input_data($str) - { - if (is_array($str)) - { - $new_array = array(); - foreach ($str as $key => $val) - { - $new_array[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); - } - return $new_array; - } - - if ($this->use_xss_clean === TRUE) - { - $str = $this->xss_clean($str); - } - - // Standardize newlines - return preg_replace("/\015\012|\015|\012/", "\n", $str); - } - - // -------------------------------------------------------------------- - - /** - * Clean Keys - * - * This is a helper function. To prevent malicious users - * from trying to exploit keys we make sure that keys are - * only named with alpha-numeric text and a few other items. - * - * @access private - * @param string - * @return string - */ - function _clean_input_keys($str) - { - if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str)) - { - exit('Disallowed Key Characters: '.$str); - } - - if ( ! get_magic_quotes_gpc()) - { - return addslashes($str); - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Fetch an item from the POST array - * - * @access public - * @param string - * @param bool - * @return string - */ - function post($index = '', $xss_clean = FALSE) - { - if ( ! isset($_POST[$index])) - { - return FALSE; - } - - if ($xss_clean === TRUE) - { - if (is_array($_POST[$index])) - { - foreach($_POST[$index] as $key => $val) - { - $_POST[$index][$key] = $this->xss_clean($val); - } - } - else - { - return $this->xss_clean($_POST[$index]); - } - } - - return $_POST[$index]; - } - - // -------------------------------------------------------------------- - - /** - * Fetch an item from the COOKIE array - * - * @access public - * @param string - * @param bool - * @return string - */ - function cookie($index = '', $xss_clean = FALSE) - { - if ( ! isset($_COOKIE[$index])) - { - return FALSE; - } - - if ($xss_clean === TRUE) - { - if (is_array($_COOKIE[$index])) - { - $cookie = array(); - foreach($_COOKIE[$index] as $key => $val) - { - $cookie[$key] = $this->xss_clean($val); - } - - return $cookie; - } - else - { - return $this->xss_clean($_COOKIE[$index]); - } - } - else - { - return $_COOKIE[$index]; - } - } - - // -------------------------------------------------------------------- - - /** - * Fetch an item from the SERVER array - * - * @access public - * @param string - * @param bool - * @return string - */ - function server($index = '', $xss_clean = FALSE) - { - if ( ! isset($_SERVER[$index])) - { - return FALSE; - } - - if ($xss_clean === TRUE) - { - return $this->xss_clean($_SERVER[$index]); - } - - return $_SERVER[$index]; - } - - // -------------------------------------------------------------------- - - /** - * Fetch the IP Address - * - * @access public - * @return string - */ - function ip_address() - { - if ($this->ip_address !== FALSE) - { - return $this->ip_address; - } - - if ($this->server('REMOTE_ADDR') AND $this->server('HTTP_CLIENT_IP')) - { - $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; - } - elseif ($this->server('REMOTE_ADDR')) - { - $this->ip_address = $_SERVER['REMOTE_ADDR']; - } - elseif ($this->server('HTTP_CLIENT_IP')) - { - $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; - } - elseif ($this->server('HTTP_X_FORWARDED_FOR')) - { - $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; - } - - if ($this->ip_address === FALSE) - { - $this->ip_address = '0.0.0.0'; - return $this->ip_address; - } - - if (strstr($this->ip_address, ',')) - { - $x = explode(',', $this->ip_address); - $this->ip_address = end($x); - } - - if ( ! $this->valid_ip($this->ip_address)) - { - $this->ip_address = '0.0.0.0'; - } - - return $this->ip_address; - } - - // -------------------------------------------------------------------- - - /** - * Validate IP Address - * - * @access public - * @param string - * @return string - */ - function valid_ip($ip) - { - return ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * User Agent - * - * @access public - * @return string - */ - function user_agent() - { - if ($this->user_agent !== FALSE) - { - return $this->user_agent; - } - - $this->user_agent = ( ! isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT']; - - return $this->user_agent; - } - - // -------------------------------------------------------------------- - - /** - * XSS Clean - * - * Sanitizes data so that Cross Site Scripting Hacks can be - * prevented.  This function does a fair amount of work but - * it is extremely thorough, designed to prevent even the - * most obscure XSS attempts.  Nothing is ever 100% foolproof, - * of course, but I haven't been able to get anything passed - * the filter. - * - * Note: This function should only be used to deal with data - * upon submission.  It's not something that should - * be used for general runtime processing. - * - * This function was based in part on some code and ideas I - * got from Bitflux: http://blog.bitflux.ch/wiki/XSS_Prevention - * - * To help develop this script I used this great list of - * vulnerabilities along with a few other hacks I've - * harvested from examining vulnerabilities in other programs: - * http://ha.ckers.org/xss.html - * - * @access public - * @param string - * @return string - */ - function xss_clean($str, $charset = 'ISO-8859-1') - { - /* - * Remove Null Characters - * - * This prevents sandwiching null characters - * between ascii characters, like Java\0script. - * - */ - $str = preg_replace('/\0+/', '', $str); - $str = preg_replace('/(\\\\0)+/', '', $str); - - /* - * Validate standard character entities - * - * Add a semicolon if missing. We do this to enable - * the conversion of entities to ASCII later. - * - */ - $str = preg_replace('#(&\#*\w+)[\x00-\x20]+;#u',"\\1;",$str); - - /* - * Validate UTF16 two byte encoding (x00) - * - * Just as above, adds a semicolon if missing. - * - */ - $str = preg_replace('#(&\#x*)([0-9A-F]+);*#iu',"\\1\\2;",$str); - - /* - * URL Decode - * - * Just in case stuff like this is submitted: - * - * Google - * - * Note: Normally urldecode() would be easier but it removes plus signs - * - */ - $str = preg_replace("/%u0([a-z0-9]{3})/i", "&#x\\1;", $str); - $str = preg_replace("/%([a-z0-9]{2})/i", "&#x\\1;", $str); - - /* - * Convert character entities to ASCII - * - * This permits our tests below to work reliably. - * We only convert entities that are within tags since - * these are the ones that will pose security problems. - * - */ - if (preg_match_all("/<(.+?)>/si", $str, $matches)) - { - for ($i = 0; $i < count($matches['0']); $i++) - { - $str = str_replace($matches['1'][$i], - $this->_html_entity_decode($matches['1'][$i], $charset), - $str); - } - } - - /* - * Not Allowed Under Any Conditions - */ - $bad = array( - 'document.cookie' => '[removed]', - 'document.write' => '[removed]', - 'window.location' => '[removed]', - "javascript\s*:" => '[removed]', - "Redirect\s+302" => '[removed]', - '' => '-->' - ); - - foreach ($bad as $key => $val) - { - $str = preg_replace("#".$key."#i", $val, $str); - } - - /* - * Convert all tabs to spaces - * - * This prevents strings like this: ja vascript - * Note: we deal with spaces between characters later. - * - */ - $str = preg_replace("#\t+#", " ", $str); - - /* - * Makes PHP tags safe - * - * Note: XML tags are inadvertently replaced too: - * - * '), array('<?php', '<?PHP', '<?', '?>'), $str); - - /* - * Compact any exploded words - * - * This corrects words like: j a v a s c r i p t - * These words are compacted back to their correct state. - * - */ - $words = array('javascript', 'vbscript', 'script', 'applet', 'alert', 'document', 'write', 'cookie', 'window'); - foreach ($words as $word) - { - $temp = ''; - for ($i = 0; $i < strlen($word); $i++) - { - $temp .= substr($word, $i, 1)."\s*"; - } - - $temp = substr($temp, 0, -3); - $str = preg_replace('#'.$temp.'#s', $word, $str); - $str = preg_replace('#'.ucfirst($temp).'#s', ucfirst($word), $str); - } - - /* - * Remove disallowed Javascript in links or img tags - */ - $str = preg_replace("#.*?#si", "", $str); - $str = preg_replace("##si", "", $str); - $str = preg_replace("#<(script|xss).*?\>#si", "", $str); - - /* - * Remove JavaScript Event Handlers - * - * Note: This code is a little blunt. It removes - * the event handler and anything up to the closing >, - * but it's unlikely to be a problem. - * - */ - $str = preg_replace('#(<[^>]+.*?)(onblur|onchange|onclick|onfocus|onload|onmouseover|onmouseup|onmousedown|onselect|onsubmit|onunload|onkeypress|onkeydown|onkeyup|onresize)[^>]*>#iU',"\\1>",$str); - - /* - * Sanitize naughty HTML elements - * - * If a tag containing any of the words in the list - * below is found, the tag gets converted to entities. - * - * So this: - * Becomes: <blink> - * - */ - $str = preg_replace('#<(/*\s*)(alert|applet|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|layer|link|meta|object|plaintext|style|script|textarea|title|xml|xss)([^>]*)>#is', "<\\1\\2\\3>", $str); - - /* - * Sanitize naughty scripting elements - * - * Similar to above, only instead of looking for - * tags it looks for PHP and JavaScript commands - * that are disallowed. Rather than removing the - * code, it simply converts the parenthesis to entities - * rendering the code un-executable. - * - * For example: eval('some code') - * Becomes: eval('some code') - * - */ - $str = preg_replace('#(alert|cmd|passthru|eval|exec|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)\((.*?)\)#si', "\\1\\2(\\3)", $str); - - /* - * Final clean up - * - * This adds a bit of extra precaution in case - * something got through the above filters - * - */ - $bad = array( - 'document.cookie' => '[removed]', - 'document.write' => '[removed]', - 'window.location' => '[removed]', - "javascript\s*:" => '[removed]', - "Redirect\s+302" => '[removed]', - '' => '-->' - ); - - foreach ($bad as $key => $val) - { - $str = preg_replace("#".$key."#i", $val, $str); - } - - - log_message('debug', "XSS Filtering completed"); - return $str; - } - - // -------------------------------------------------------------------- - - /** - * HTML Entities Decode - * - * This function is a replacement for html_entity_decode() - * - * In some versions of PHP the native function does not work - * when UTF-8 is the specified character set, so this gives us - * a work-around. More info here: - * http://bugs.php.net/bug.php?id=25670 - * - * @access private - * @param string - * @param string - * @return string - */ - /* ------------------------------------------------- - /* Replacement for html_entity_decode() - /* -------------------------------------------------*/ - - /* - NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the - character set, and the PHP developers said they were not back porting the - fix to versions other than PHP 5.x. - */ - function _html_entity_decode($str, $charset='ISO-8859-1') - { - 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 version_compare(phpversion(), '5.0.0', '>='))) - { - $str = html_entity_decode($str, ENT_COMPAT, $charset); - $str = preg_replace('~&#x([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-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; - } - -} -// END Input class +use_xss_clean = ($CFG->item('global_xss_filtering') === TRUE) ? TRUE : FALSE; + $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; + $this->_sanitize_globals(); + } + + // -------------------------------------------------------------------- + + /** + * Sanitize Globals + * + * This function does the following: + * + * Unsets $_GET data (if query strings are not enabled) + * + * Unsets all globals if register_globals is enabled + * + * Standardizes newline characters to \n + * + * @access private + * @return void + */ + function _sanitize_globals() + { + // Unset globals. This is effectively the same as register_globals = off + foreach (array($_GET, $_POST, $_COOKIE) as $global) + { + if ( ! is_array($global)) + { + global $global; + $$global = NULL; + } + else + { + foreach ($global as $key => $val) + { + global $$key; + $$key = NULL; + } + } + } + + // Is $_GET data allowed? If not we'll set the $_GET to an empty array + if ($this->allow_get_array == FALSE) + { + $_GET = array(); + } + + // Clean $_POST Data + if (is_array($_POST) AND count($_POST) > 0) + { + foreach($_POST as $key => $val) + { + $_POST[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); + } + } + + // Clean $_COOKIE Data + if (is_array($_COOKIE) AND count($_COOKIE) > 0) + { + foreach($_COOKIE as $key => $val) + { + $_COOKIE[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); + } + } + + log_message('debug', "Global POST and COOKIE data sanitized"); + } + + // -------------------------------------------------------------------- + + /** + * Clean Input Data + * + * This is a helper function. It escapes data and + * standardizes newline characters to \n + * + * @access private + * @param string + * @return string + */ + function _clean_input_data($str) + { + if (is_array($str)) + { + $new_array = array(); + foreach ($str as $key => $val) + { + $new_array[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); + } + return $new_array; + } + + if ($this->use_xss_clean === TRUE) + { + $str = $this->xss_clean($str); + } + + // Standardize newlines + return preg_replace("/\015\012|\015|\012/", "\n", $str); + } + + // -------------------------------------------------------------------- + + /** + * Clean Keys + * + * This is a helper function. To prevent malicious users + * from trying to exploit keys we make sure that keys are + * only named with alpha-numeric text and a few other items. + * + * @access private + * @param string + * @return string + */ + function _clean_input_keys($str) + { + if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str)) + { + exit('Disallowed Key Characters.'); + } + + if ( ! get_magic_quotes_gpc()) + { + return addslashes($str); + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Fetch an item from the POST array + * + * @access public + * @param string + * @param bool + * @return string + */ + function post($index = '', $xss_clean = FALSE) + { + if ( ! isset($_POST[$index])) + { + return FALSE; + } + + if ($xss_clean === TRUE) + { + if (is_array($_POST[$index])) + { + foreach($_POST[$index] as $key => $val) + { + $_POST[$index][$key] = $this->xss_clean($val); + } + } + else + { + return $this->xss_clean($_POST[$index]); + } + } + + return $_POST[$index]; + } + + // -------------------------------------------------------------------- + + /** + * Fetch an item from the COOKIE array + * + * @access public + * @param string + * @param bool + * @return string + */ + function cookie($index = '', $xss_clean = FALSE) + { + if ( ! isset($_COOKIE[$index])) + { + return FALSE; + } + + if ($xss_clean === TRUE) + { + if (is_array($_COOKIE[$index])) + { + $cookie = array(); + foreach($_COOKIE[$index] as $key => $val) + { + $cookie[$key] = $this->xss_clean($val); + } + + return $cookie; + } + else + { + return $this->xss_clean($_COOKIE[$index]); + } + } + else + { + return $_COOKIE[$index]; + } + } + + // -------------------------------------------------------------------- + + /** + * Fetch an item from the SERVER array + * + * @access public + * @param string + * @param bool + * @return string + */ + function server($index = '', $xss_clean = FALSE) + { + if ( ! isset($_SERVER[$index])) + { + return FALSE; + } + + if ($xss_clean === TRUE) + { + return $this->xss_clean($_SERVER[$index]); + } + + return $_SERVER[$index]; + } + + // -------------------------------------------------------------------- + + /** + * Fetch the IP Address + * + * @access public + * @return string + */ + function ip_address() + { + if ($this->ip_address !== FALSE) + { + return $this->ip_address; + } + + if ($this->server('REMOTE_ADDR') AND $this->server('HTTP_CLIENT_IP')) + { + $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; + } + elseif ($this->server('REMOTE_ADDR')) + { + $this->ip_address = $_SERVER['REMOTE_ADDR']; + } + elseif ($this->server('HTTP_CLIENT_IP')) + { + $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; + } + elseif ($this->server('HTTP_X_FORWARDED_FOR')) + { + $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; + } + + if ($this->ip_address === FALSE) + { + $this->ip_address = '0.0.0.0'; + return $this->ip_address; + } + + if (strstr($this->ip_address, ',')) + { + $x = explode(',', $this->ip_address); + $this->ip_address = end($x); + } + + if ( ! $this->valid_ip($this->ip_address)) + { + $this->ip_address = '0.0.0.0'; + } + + return $this->ip_address; + } + + // -------------------------------------------------------------------- + + /** + * Validate IP Address + * + * @access public + * @param string + * @return string + */ + function valid_ip($ip) + { + return ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * User Agent + * + * @access public + * @return string + */ + function user_agent() + { + if ($this->user_agent !== FALSE) + { + return $this->user_agent; + } + + $this->user_agent = ( ! isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT']; + + return $this->user_agent; + } + + // -------------------------------------------------------------------- + + /** + * XSS Clean + * + * Sanitizes data so that Cross Site Scripting Hacks can be + * prevented.  This function does a fair amount of work but + * it is extremely thorough, designed to prevent even the + * most obscure XSS attempts.  Nothing is ever 100% foolproof, + * of course, but I haven't been able to get anything passed + * the filter. + * + * Note: This function should only be used to deal with data + * upon submission.  It's not something that should + * be used for general runtime processing. + * + * This function was based in part on some code and ideas I + * got from Bitflux: http://blog.bitflux.ch/wiki/XSS_Prevention + * + * To help develop this script I used this great list of + * vulnerabilities along with a few other hacks I've + * harvested from examining vulnerabilities in other programs: + * http://ha.ckers.org/xss.html + * + * @access public + * @param string + * @return string + */ + function xss_clean($str, $charset = 'ISO-8859-1') + { + /* + * Remove Null Characters + * + * This prevents sandwiching null characters + * between ascii characters, like Java\0script. + * + */ + $str = preg_replace('/\0+/', '', $str); + $str = preg_replace('/(\\\\0)+/', '', $str); + + /* + * Validate standard character entities + * + * Add a semicolon if missing. We do this to enable + * the conversion of entities to ASCII later. + * + */ + $str = preg_replace('#(&\#*\w+)[\x00-\x20]+;#u',"\\1;",$str); + + /* + * Validate UTF16 two byte encoding (x00) + * + * Just as above, adds a semicolon if missing. + * + */ + $str = preg_replace('#(&\#x*)([0-9A-F]+);*#iu',"\\1\\2;",$str); + + /* + * URL Decode + * + * Just in case stuff like this is submitted: + * + * Google + * + * Note: Normally urldecode() would be easier but it removes plus signs + * + */ + $str = preg_replace("/%u0([a-z0-9]{3})/i", "&#x\\1;", $str); + $str = preg_replace("/%([a-z0-9]{2})/i", "&#x\\1;", $str); + + /* + * Convert character entities to ASCII + * + * This permits our tests below to work reliably. + * We only convert entities that are within tags since + * these are the ones that will pose security problems. + * + */ + if (preg_match_all("/<(.+?)>/si", $str, $matches)) + { + for ($i = 0; $i < count($matches['0']); $i++) + { + $str = str_replace($matches['1'][$i], + $this->_html_entity_decode($matches['1'][$i], $charset), + $str); + } + } + + /* + * Not Allowed Under Any Conditions + */ + $bad = array( + 'document.cookie' => '[removed]', + 'document.write' => '[removed]', + 'window.location' => '[removed]', + "javascript\s*:" => '[removed]', + "Redirect\s+302" => '[removed]', + '' => '-->' + ); + + foreach ($bad as $key => $val) + { + $str = preg_replace("#".$key."#i", $val, $str); + } + + /* + * Convert all tabs to spaces + * + * This prevents strings like this: ja vascript + * Note: we deal with spaces between characters later. + * + */ + $str = preg_replace("#\t+#", " ", $str); + + /* + * Makes PHP tags safe + * + * Note: XML tags are inadvertently replaced too: + * + * '), array('<?php', '<?PHP', '<?', '?>'), $str); + + /* + * Compact any exploded words + * + * This corrects words like: j a v a s c r i p t + * These words are compacted back to their correct state. + * + */ + $words = array('javascript', 'vbscript', 'script', 'applet', 'alert', 'document', 'write', 'cookie', 'window'); + foreach ($words as $word) + { + $temp = ''; + for ($i = 0; $i < strlen($word); $i++) + { + $temp .= substr($word, $i, 1)."\s*"; + } + + $temp = substr($temp, 0, -3); + $str = preg_replace('#'.$temp.'#s', $word, $str); + $str = preg_replace('#'.ucfirst($temp).'#s', ucfirst($word), $str); + } + + /* + * Remove disallowed Javascript in links or img tags + */ + $str = preg_replace("#.*?#si", "", $str); + $str = preg_replace("##si", "", $str); + $str = preg_replace("#<(script|xss).*?\>#si", "", $str); + + /* + * Remove JavaScript Event Handlers + * + * Note: This code is a little blunt. It removes + * the event handler and anything up to the closing >, + * but it's unlikely to be a problem. + * + */ + $str = preg_replace('#(<[^>]+.*?)(onblur|onchange|onclick|onfocus|onload|onmouseover|onmouseup|onmousedown|onselect|onsubmit|onunload|onkeypress|onkeydown|onkeyup|onresize)[^>]*>#iU',"\\1>",$str); + + /* + * Sanitize naughty HTML elements + * + * If a tag containing any of the words in the list + * below is found, the tag gets converted to entities. + * + * So this: + * Becomes: <blink> + * + */ + $str = preg_replace('#<(/*\s*)(alert|applet|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|layer|link|meta|object|plaintext|style|script|textarea|title|xml|xss)([^>]*)>#is', "<\\1\\2\\3>", $str); + + /* + * Sanitize naughty scripting elements + * + * Similar to above, only instead of looking for + * tags it looks for PHP and JavaScript commands + * that are disallowed. Rather than removing the + * code, it simply converts the parenthesis to entities + * rendering the code un-executable. + * + * For example: eval('some code') + * Becomes: eval('some code') + * + */ + $str = preg_replace('#(alert|cmd|passthru|eval|exec|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)\((.*?)\)#si', "\\1\\2(\\3)", $str); + + /* + * Final clean up + * + * This adds a bit of extra precaution in case + * something got through the above filters + * + */ + $bad = array( + 'document.cookie' => '[removed]', + 'document.write' => '[removed]', + 'window.location' => '[removed]', + "javascript\s*:" => '[removed]', + "Redirect\s+302" => '[removed]', + '' => '-->' + ); + + foreach ($bad as $key => $val) + { + $str = preg_replace("#".$key."#i", $val, $str); + } + + + log_message('debug', "XSS Filtering completed"); + return $str; + } + + // -------------------------------------------------------------------- + + /** + * HTML Entities Decode + * + * This function is a replacement for html_entity_decode() + * + * In some versions of PHP the native function does not work + * when UTF-8 is the specified character set, so this gives us + * a work-around. More info here: + * http://bugs.php.net/bug.php?id=25670 + * + * @access private + * @param string + * @param string + * @return string + */ + /* ------------------------------------------------- + /* Replacement for html_entity_decode() + /* -------------------------------------------------*/ + + /* + NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the + character set, and the PHP developers said they were not back porting the + fix to versions other than PHP 5.x. + */ + function _html_entity_decode($str, $charset='ISO-8859-1') + { + 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 version_compare(phpversion(), '5.0.0', '>='))) + { + $str = html_entity_decode($str, ENT_COMPAT, $charset); + $str = preg_replace('~&#x([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-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; + } + +} +// END Input class ?> \ No newline at end of file diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 6d925a1c0..8dfc82580 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -1,561 +1,561 @@ -config =& load_class('Config'); - $this->_set_route_mapping(); - log_message('debug', "Router Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Set the route mapping - * - * This function determines what should be served based on the URI request, - * as well as any "routes" that have been set in the routing config file. - * - * @access private - * @return void - */ - function _set_route_mapping() - { - // Are query strings enabled in the config file? - // If so, we're done since segment based URIs are not used with query strings. - if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) - { - $this->set_class($_GET[$this->config->item('controller_trigger')]); - - if (isset($_GET[$this->config->item('function_trigger')])) - { - $this->set_method($_GET[$this->config->item('function_trigger')]); - } - - return; - } - - // 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']); - - // Fetch the complete URI string - $this->uri_string = $this->_get_uri_string(); - - // If the URI contains only a slash we'll kill it - if ($this->uri_string == '/') - { - $this->uri_string = ''; - } - - // Is there a URI string? If not, the default controller specified in the "routes" file will be shown. - if ($this->uri_string == '') - { - if ($this->default_controller === FALSE) - { - show_error("Unable to determine what should be displayed. A default route has not been specified in the routing file."); - } - - $this->set_class($this->default_controller); - $this->set_method('index'); - - log_message('debug', "No URI present. Default controller set."); - return; - } - unset($this->routes['default_controller']); - - // Do we need to remove the suffix specified in the config file? - if ($this->config->item('url_suffix') != "") - { - $this->uri_string = preg_replace("|".preg_quote($this->config->item('url_suffix'))."$|", "", $this->uri_string); - } - - // Explode the URI Segments. The individual segments will - // be stored in the $this->segments array. - foreach(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val) - { - // Filter segments for security - $val = trim($this->_filter_uri($val)); - - if ($val != '') - $this->segments[] = $val; - } - - // Parse any custom routing that may exist - $this->_parse_routes(); - - // Re-index the segment array so that it starts with 1 rather than 0 - $this->_reindex_segments(); - } - - // -------------------------------------------------------------------- - - /** - * Compile Segments - * - * This function takes an array of URI segments as - * input, and puts it into the $this->segments array. - * It also sets the current class/method - * - * @access private - * @param array - * @param bool - * @return void - */ - function _compile_segments($segments = array()) - { - $segments = $this->_validate_segments($segments); - - if (count($segments) == 0) - { - return; - } - - $this->set_class($segments[0]); - - if (isset($segments[1])) - { - // A scaffolding request. No funny business with the URL - if ($this->routes['scaffolding_trigger'] == $segments[1] AND $segments[1] != '_ci_scaffolding') - { - $this->scaffolding_request = TRUE; - unset($this->routes['scaffolding_trigger']); - } - else - { - // A standard method request - $this->set_method($segments[1]); - } - } - - // Update our "routed" segment array to contain the segments. - // Note: If there is no custom routing, this array will be - // identical to $this->segments - $this->rsegments = $segments; - } - - // -------------------------------------------------------------------- - - /** - * Validates the supplied segments. Attempts to determine the path to - * the controller. - * - * @access private - * @param array - * @return array - */ - function _validate_segments($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(); - } - } - 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; - } - - // Can't find the requested controller... - show_404(); - } - - // -------------------------------------------------------------------- - /** - * Re-index Segments - * - * This function re-indexes the $this->segment array so that it - * starts at 1 rather then 0. Doing so makes it simpler to - * use functions like $this->uri->segment(n) since there is - * a 1:1 relationship between the segment array and the actual segments. - * - * @access private - * @return void - */ - function _reindex_segments() - { - // Is the routed segment array different then the main segment array? - $diff = (count(array_diff($this->rsegments, $this->segments)) == 0) ? FALSE : TRUE; - - $i = 1; - foreach ($this->segments as $val) - { - $this->segments[$i++] = $val; - } - unset($this->segments[0]); - - if ($diff == FALSE) - { - $this->rsegments = $this->segments; - } - else - { - $i = 1; - foreach ($this->rsegments as $val) - { - $this->rsegments[$i++] = $val; - } - unset($this->rsegments[0]); - } - } - - // -------------------------------------------------------------------- - - /** - * Get the URI String - * - * @access private - * @return string - */ - function _get_uri_string() - { - if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') - { - // If the URL has a question mark then it's simplest to just - // build the URI string from the zero index of the $_GET array. - // This avoids having to deal with $_SERVER variables, which - // can be unreliable in some environments - if (is_array($_GET) AND count($_GET) == 1) - { - // Note: Due to a bug in current() that affects some versions - // of PHP we can not pass function call directly into it - $keys = array_keys($_GET); - return current($keys); - } - - // Is there a PATH_INFO variable? - // Note: some servers seem to have trouble with getenv() so we'll test it two ways - $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); - if ($path != '' AND $path != "/".SELF) - { - return $path; - } - - // No PATH_INFO?... What about QUERY_STRING? - $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); - if ($path != '') - { - return $path; - } - - // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists? - $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); - if ($path != '' AND $path != "/".SELF) - { - return $path; - } - - // We've exhausted all our options... - return ''; - } - else - { - $uri = strtoupper($this->config->item('uri_protocol')); - - if ($uri == 'REQUEST_URI') - { - return $this->_parse_request_uri(); - } - - return (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); - } - } - - // -------------------------------------------------------------------- - - /** - * Parse the REQUEST_URI - * - * Due to the way REQUEST_URI works it usually contains path info - * that makes it unusable as URI data. We'll trim off the unnecessary - * data, hopefully arriving at a valid URI that we can use. - * - * @access private - * @return string - */ - function _parse_request_uri() - { - if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '') - { - return ''; - } - - $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI'])); - - if ($request_uri == '' OR $request_uri == SELF) - { - return ''; - } - - $fc_path = FCPATH; - if (strpos($request_uri, '?') !== FALSE) - { - $fc_path .= '?'; - } - - $parsed_uri = explode("/", $request_uri); - - $i = 0; - foreach(explode("/", $fc_path) as $segment) - { - if (isset($parsed_uri[$i]) AND $segment == $parsed_uri[$i]) - { - $i++; - } - } - - $parsed_uri = implode("/", array_slice($parsed_uri, $i)); - - if ($parsed_uri != '') - { - $parsed_uri = '/'.$parsed_uri; - } - - return $parsed_uri; - } - - // -------------------------------------------------------------------- - - /** - * Filter segments for malicious characters - * - * @access private - * @param string - * @return string - */ - function _filter_uri($str) - { - if ($this->config->item('permitted_uri_chars') != '') - { - if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) - { - exit('The URI you submitted has disallowed characters: '.$str); - } - } - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Parse Routes - * - * This function matches any routes that may exist in - * the config/routes.php file against the URI to - * determine if the class/method need to be remapped. - * - * @access private - * @return void - */ - function _parse_routes() - { - // Do we even have any custom routing to deal with? - if (count($this->routes) == 0) - { - $this->_compile_segments($this->segments); - return; - } - - // Turn the segment array into a URI string - $uri = implode('/', $this->segments); - $num = count($this->segments); - - // Is there a literal match? If so we're done - if (isset($this->routes[$uri])) - { - $this->_compile_segments(explode('/', $this->routes[$uri])); - return; - } - - // Loop through the route array looking for wild-cards - foreach (array_slice($this->routes, 1) as $key => $val) - { - // Convert wild-cards to RegEx - $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); - - // Does the RegEx match? - if (preg_match('#^'.$key.'$#', $uri)) - { - // Do we have a back-reference? - if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) - { - $val = preg_replace('#^'.$key.'$#', $val, $uri); - } - - $this->_compile_segments(explode('/', $val)); - return; - } - } - - // If we got this far it means we didn't encounter a - // matching route so we'll set the site default route - $this->_compile_segments($this->segments); - } - - // -------------------------------------------------------------------- - - /** - * Set the class name - * - * @access public - * @param string - * @return void - */ - function set_class($class) - { - $this->class = $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()) - { - return 'index'; - } - - return $this->method; - } - - // -------------------------------------------------------------------- - - /** - * Set the directory name - * - * @access public - * @param string - * @return void - */ - function set_directory($dir) - { - $this->directory = $dir.'/'; - } - - // -------------------------------------------------------------------- - - /** - * Fetch the sub-directory (if any) that contains the requested controller class - * - * @access public - * @return string - */ - function fetch_directory() - { - return $this->directory; - } - -} -// END Router Class +config =& load_class('Config'); + $this->_set_route_mapping(); + log_message('debug', "Router Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Set the route mapping + * + * This function determines what should be served based on the URI request, + * as well as any "routes" that have been set in the routing config file. + * + * @access private + * @return void + */ + function _set_route_mapping() + { + // Are query strings enabled in the config file? + // If so, we're done since segment based URIs are not used with query strings. + if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) + { + $this->set_class($_GET[$this->config->item('controller_trigger')]); + + if (isset($_GET[$this->config->item('function_trigger')])) + { + $this->set_method($_GET[$this->config->item('function_trigger')]); + } + + return; + } + + // 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']); + + // Fetch the complete URI string + $this->uri_string = $this->_get_uri_string(); + + // If the URI contains only a slash we'll kill it + if ($this->uri_string == '/') + { + $this->uri_string = ''; + } + + // Is there a URI string? If not, the default controller specified in the "routes" file will be shown. + if ($this->uri_string == '') + { + if ($this->default_controller === FALSE) + { + show_error("Unable to determine what should be displayed. A default route has not been specified in the routing file."); + } + + $this->set_class($this->default_controller); + $this->set_method('index'); + + log_message('debug', "No URI present. Default controller set."); + return; + } + unset($this->routes['default_controller']); + + // Do we need to remove the suffix specified in the config file? + if ($this->config->item('url_suffix') != "") + { + $this->uri_string = preg_replace("|".preg_quote($this->config->item('url_suffix'))."$|", "", $this->uri_string); + } + + // Explode the URI Segments. The individual segments will + // be stored in the $this->segments array. + foreach(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val) + { + // Filter segments for security + $val = trim($this->_filter_uri($val)); + + if ($val != '') + $this->segments[] = $val; + } + + // Parse any custom routing that may exist + $this->_parse_routes(); + + // Re-index the segment array so that it starts with 1 rather than 0 + $this->_reindex_segments(); + } + + // -------------------------------------------------------------------- + + /** + * Compile Segments + * + * This function takes an array of URI segments as + * input, and puts it into the $this->segments array. + * It also sets the current class/method + * + * @access private + * @param array + * @param bool + * @return void + */ + function _compile_segments($segments = array()) + { + $segments = $this->_validate_segments($segments); + + if (count($segments) == 0) + { + return; + } + + $this->set_class($segments[0]); + + if (isset($segments[1])) + { + // A scaffolding request. No funny business with the URL + if ($this->routes['scaffolding_trigger'] == $segments[1] AND $segments[1] != '_ci_scaffolding') + { + $this->scaffolding_request = TRUE; + unset($this->routes['scaffolding_trigger']); + } + else + { + // A standard method request + $this->set_method($segments[1]); + } + } + + // Update our "routed" segment array to contain the segments. + // Note: If there is no custom routing, this array will be + // identical to $this->segments + $this->rsegments = $segments; + } + + // -------------------------------------------------------------------- + + /** + * Validates the supplied segments. Attempts to determine the path to + * the controller. + * + * @access private + * @param array + * @return array + */ + function _validate_segments($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(); + } + } + 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; + } + + // Can't find the requested controller... + show_404(); + } + + // -------------------------------------------------------------------- + /** + * Re-index Segments + * + * This function re-indexes the $this->segment array so that it + * starts at 1 rather then 0. Doing so makes it simpler to + * use functions like $this->uri->segment(n) since there is + * a 1:1 relationship between the segment array and the actual segments. + * + * @access private + * @return void + */ + function _reindex_segments() + { + // Is the routed segment array different then the main segment array? + $diff = (count(array_diff($this->rsegments, $this->segments)) == 0) ? FALSE : TRUE; + + $i = 1; + foreach ($this->segments as $val) + { + $this->segments[$i++] = $val; + } + unset($this->segments[0]); + + if ($diff == FALSE) + { + $this->rsegments = $this->segments; + } + else + { + $i = 1; + foreach ($this->rsegments as $val) + { + $this->rsegments[$i++] = $val; + } + unset($this->rsegments[0]); + } + } + + // -------------------------------------------------------------------- + + /** + * Get the URI String + * + * @access private + * @return string + */ + function _get_uri_string() + { + if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') + { + // If the URL has a question mark then it's simplest to just + // build the URI string from the zero index of the $_GET array. + // This avoids having to deal with $_SERVER variables, which + // can be unreliable in some environments + if (is_array($_GET) AND count($_GET) == 1) + { + // Note: Due to a bug in current() that affects some versions + // of PHP we can not pass function call directly into it + $keys = array_keys($_GET); + return current($keys); + } + + // Is there a PATH_INFO variable? + // Note: some servers seem to have trouble with getenv() so we'll test it two ways + $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); + if ($path != '' AND $path != "/".SELF) + { + return $path; + } + + // No PATH_INFO?... What about QUERY_STRING? + $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); + if ($path != '') + { + return $path; + } + + // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists? + $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); + if ($path != '' AND $path != "/".SELF) + { + return $path; + } + + // We've exhausted all our options... + return ''; + } + else + { + $uri = strtoupper($this->config->item('uri_protocol')); + + if ($uri == 'REQUEST_URI') + { + return $this->_parse_request_uri(); + } + + return (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); + } + } + + // -------------------------------------------------------------------- + + /** + * Parse the REQUEST_URI + * + * Due to the way REQUEST_URI works it usually contains path info + * that makes it unusable as URI data. We'll trim off the unnecessary + * data, hopefully arriving at a valid URI that we can use. + * + * @access private + * @return string + */ + function _parse_request_uri() + { + if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '') + { + return ''; + } + + $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI'])); + + if ($request_uri == '' OR $request_uri == SELF) + { + return ''; + } + + $fc_path = FCPATH; + if (strpos($request_uri, '?') !== FALSE) + { + $fc_path .= '?'; + } + + $parsed_uri = explode("/", $request_uri); + + $i = 0; + foreach(explode("/", $fc_path) as $segment) + { + if (isset($parsed_uri[$i]) AND $segment == $parsed_uri[$i]) + { + $i++; + } + } + + $parsed_uri = implode("/", array_slice($parsed_uri, $i)); + + if ($parsed_uri != '') + { + $parsed_uri = '/'.$parsed_uri; + } + + return $parsed_uri; + } + + // -------------------------------------------------------------------- + + /** + * Filter segments for malicious characters + * + * @access private + * @param string + * @return string + */ + function _filter_uri($str) + { + if ($this->config->item('permitted_uri_chars') != '') + { + if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) + { + exit('The URI you submitted has disallowed characters.'); + } + } + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Parse Routes + * + * This function matches any routes that may exist in + * the config/routes.php file against the URI to + * determine if the class/method need to be remapped. + * + * @access private + * @return void + */ + function _parse_routes() + { + // Do we even have any custom routing to deal with? + if (count($this->routes) == 0) + { + $this->_compile_segments($this->segments); + return; + } + + // Turn the segment array into a URI string + $uri = implode('/', $this->segments); + $num = count($this->segments); + + // Is there a literal match? If so we're done + if (isset($this->routes[$uri])) + { + $this->_compile_segments(explode('/', $this->routes[$uri])); + return; + } + + // Loop through the route array looking for wild-cards + foreach (array_slice($this->routes, 1) as $key => $val) + { + // Convert wild-cards to RegEx + $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); + + // Does the RegEx match? + if (preg_match('#^'.$key.'$#', $uri)) + { + // Do we have a back-reference? + if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) + { + $val = preg_replace('#^'.$key.'$#', $val, $uri); + } + + $this->_compile_segments(explode('/', $val)); + return; + } + } + + // If we got this far it means we didn't encounter a + // matching route so we'll set the site default route + $this->_compile_segments($this->segments); + } + + // -------------------------------------------------------------------- + + /** + * Set the class name + * + * @access public + * @param string + * @return void + */ + function set_class($class) + { + $this->class = $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()) + { + return 'index'; + } + + return $this->method; + } + + // -------------------------------------------------------------------- + + /** + * Set the directory name + * + * @access public + * @param string + * @return void + */ + function set_directory($dir) + { + $this->directory = $dir.'/'; + } + + // -------------------------------------------------------------------- + + /** + * Fetch the sub-directory (if any) that contains the requested controller class + * + * @access public + * @return string + */ + function fetch_directory() + { + return $this->directory; + } + +} +// END Router Class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c5d887941fac6754972e87979e180cc043c4d0fe Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 1 Feb 2007 03:12:32 +0000 Subject: fixed resize bug that was comparing height to width instead of height to original height --- system/libraries/Image_lib.php | 3052 ++++++++++++++++++++-------------------- 1 file changed, 1526 insertions(+), 1526 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 561c5c03a..28e1bfbbc 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1,1527 +1,1527 @@ - 0) - { - $this->initialize($props); - } - - log_message('debug', "Image Lib Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize image properties - * - * Resets values in case this class is used in a loop - * - * @access public - * @return void - */ - function clear() - { - $props = array('source_folder', 'dest_folder', 'source_image', 'full_src_path', 'full_dst_path', 'new_image', 'image_type', 'size_str', 'quality', 'orig_width', 'orig_height', 'rotation_angle', 'x_axis', 'y_axis', 'create_fnc', 'copy_fnc', 'wm_overlay_path', 'wm_use_truetype', 'dynamic_output', 'wm_font_size', 'wm_text', 'wm_vrt_alignment', 'wm_hor_alignment', 'wm_padding', 'wm_hor_offset', 'wm_vrt_offset', 'wm_font_color', 'wm_use_drop_shadow', 'wm_shadow_color', 'wm_shadow_distance', 'wm_opacity'); - - foreach ($props as $val) - { - $this->$val = ''; - } - } - - // -------------------------------------------------------------------- - - /** - * initialize image preferences - * - * @access public - * @param array - * @return void - */ - function initialize($props = array()) - { - /* - * Convert array elements into class variables - */ - if (count($props) > 0) - { - foreach ($props as $key => $val) - { - $this->$key = $val; - } - } - - /* - * Is there a source image? - * - * If not, there's no reason to continue - * - */ - if ($this->source_image == '') - { - $this->set_error('imglib_source_image_required'); - return FALSE; - } - - /* - * Is getimagesize() Available? - * - * We use it to determine the image properties (width/height). - * Note: We need to figure out how to determine image - * properties using ImageMagick and NetPBM - * - */ - if ( ! function_exists('getimagesize')) - { - $this->set_error('imglib_gd_required_for_props'); - return FALSE; - } - - $this->image_library = strtolower($this->image_library); - - /* - * Set the full server path - * - * The source image may or may not contain a path. - * Either way, we'll try use realpath to generate the - * full server path in order to more reliably read it. - * - */ - if (function_exists('realpath') AND @realpath($this->source_image) !== FALSE) - { - $full_source_path = str_replace("\\", "/", realpath($this->source_image)); - } - else - { - $full_source_path = $this->source_image; - } - - $x = explode('/', $full_source_path); - $this->source_image = end($x); - $this->source_folder = str_replace($this->source_image, '', $full_source_path); - - // Set the Image Properties - if ( ! $this->get_image_properties($this->source_folder.$this->source_image)) - { - return FALSE; - } - - /* - * Assign the "new" image name/path - * - * If the user has set a "new_image" name it means - * we are making a copy of the source image. If not - * it means we are altering the original. We'll - * set the destination filename and path accordingly. - * - */ - if ($this->new_image == '') - { - $this->dest_image = $this->source_image; - $this->dest_folder = $this->source_folder; - } - else - { - if (strpos($this->new_image, '/') === FALSE) - { - $this->dest_folder = $this->source_folder; - $this->dest_image = $this->new_image; - } - else - { - if (function_exists('realpath') AND @realpath($this->new_image) !== FALSE) - { - $full_dest_path = str_replace("\\", "/", realpath($this->new_image)); - } - else - { - $full_dest_path = $this->new_image; - } - - // Is there a file name? - if ( ! preg_match("#[\.jpg|\.jpeg|\.gif|\.png]$#i", $full_dest_path)) - { - $this->dest_folder = $full_dest_path.'/'; - $this->dest_image = $this->source_image; - } - else - { - $x = explode('/', $full_dest_path); - $this->dest_image = end($x); - $this->dest_folder = str_replace($this->dest_image, '', $full_dest_path); - } - } - } - - /* - * Compile the finalized filenames/paths - * - * We'll create two master strings containing the - * full server path to the source image and the - * full server path to the destination image. - * We'll also split the destination image name - * so we can insert the thumbnail marker if needed. - * - */ - if ($this->create_thumb === FALSE OR $this->thumb_marker == '') - { - $this->thumb_marker = ''; - } - - $xp = $this->explode_name($this->dest_image); - - $filename = $xp['name']; - $file_ext = $xp['ext']; - - $this->full_src_path = $this->source_folder.$this->source_image; - $this->full_dst_path = $this->dest_folder.$filename.$this->thumb_marker.$file_ext; - - /* - * Should we maintain image proportions? - * - * When creating thumbs or copies, the target width/height - * might not be in correct proportion with the source - * image's width/height. We'll recalculate it here. - * - */ - if ($this->maintain_ratio === TRUE && ($this->width != '' AND $this->height != '')) - { - $this->image_reproportion(); - } - - /* - * Was a width and height specified? - * - * If the destination width/height was - * not submitted we will use the values - * from the actual file - * - */ - if ($this->width == '') - $this->width = $this->orig_width; - - if ($this->height == '') - $this->height = $this->orig_height; - - // Set the quality - $this->quality = trim(str_replace("%", "", $this->quality)); - - if ($this->quality == '' OR $this->quality == 0 OR ! is_numeric($this->quality)) - $this->quality = 90; - - // Set the x/y coordinates - $this->x_axis = ($this->x_axis == '' OR ! is_numeric($this->x_axis)) ? 0 : $this->x_axis; - $this->y_axis = ($this->y_axis == '' OR ! is_numeric($this->y_axis)) ? 0 : $this->y_axis; - - // Watermark-related Stuff... - if ($this->wm_font_color != '') - { - if (strlen($this->wm_font_color) == 6) - { - $this->wm_font_color = '#'.$this->wm_font_color; - } - } - - if ($this->wm_shadow_color != '') - { - if (strlen($this->wm_shadow_color) == 6) - { - $this->wm_shadow_color = '#'.$this->wm_shadow_color; - } - } - - if ($this->wm_overlay_path != '') - { - $this->wm_overlay_path = str_replace("\\", "/", realpath($this->wm_overlay_path)); - } - - if ($this->wm_shadow_color != '') - { - $this->wm_use_drop_shadow = TRUE; - } - - if ($this->wm_font_path != '') - { - $this->wm_use_truetype = TRUE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Image Resize - * - * This is a wrapper function that chooses the proper - * resize function based on the protocol specified - * - * @access public - * @return bool - */ - function resize() - { - $protocol = 'image_process_'.$this->image_library; - - if (eregi("gd2$", $protocol)) - { - $protocol = 'image_process_gd'; - } - - return $this->$protocol('resize'); - } - - // -------------------------------------------------------------------- - - /** - * Image Crop - * - * This is a wrapper function that chooses the proper - * cropping function based on the protocol specified - * - * @access public - * @return bool - */ - function crop() - { - $protocol = 'image_process_'.$this->image_library; - - if (eregi("gd2$", $protocol)) - { - $protocol = 'image_process_gd'; - } - - return $this->$protocol('crop'); - } - - // -------------------------------------------------------------------- - - /** - * Image Rotate - * - * This is a wrapper function that chooses the proper - * rotation function based on the protocol specified - * - * @access public - * @return bool - */ - function rotate() - { - // Allowed rotation values - $degs = array(90, 180, 270, 'vrt', 'hor'); - - if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs, TRUE)) - { - $this->set_error('imglib_rotation_angle_required'); - return FALSE; - } - - // Reassign the width and height - if ($this->rotation_angle == 90 OR $this->rotation_angle == 270) - { - $this->width = $this->orig_height; - $this->height = $this->orig_width; - } - else - { - $this->width = $this->orig_width; - $this->height = $this->orig_height; - } - - - // Choose resizing function - if ($this->image_library == 'imagemagick' OR $this->image_library == 'netpbm') - { - $protocol = 'image_process_'.$this->image_library; - - return $this->$protocol('rotate'); - } - - if ($this->rotation_angle == 'hor' OR $this->rotation_angle == 'vrt') - { - return $this->image_mirror_gd(); - } - else - { - return $this->image_rotate_gd(); - } - } - - // -------------------------------------------------------------------- - - /** - * Image Process Using GD/GD2 - * - * This function will resize or crop - * - * @access public - * @param string - * @return bool - */ - function image_process_gd($action = 'resize') - { - $v2_override = FALSE; - - if ($action == 'crop') - { - // If the target width/height match the source then it's pointless to crop, right? - if ($this->width >= $this->orig_width AND $this->height >= $this->orig_width) - { - // We'll return true so the user thinks the process succeeded. - // It'll be our little secret... - - return TRUE; - } - - // Reassign the source width/height if cropping - $this->orig_width = $this->width; - $this->orig_height = $this->height; - - // GD 2.0 has a cropping bug so we'll test for it - if ($this->gd_version() !== FALSE) - { - $gd_version = str_replace('0', '', $this->gd_version()); - $v2_override = ($gd_version == 2) ? TRUE : FALSE; - } - } - else - { - // If the target width/height match the source, AND if - // the new file name is not equal to the old file name - // we'll simply make a copy of the original with the new name - if (($this->orig_width == $this->width AND $this->orig_height == $this->height) AND ($this->source_image != $this->dest_image)) - { - if ( ! @copy($this->full_src_path, $this->full_dst_path)) - { - $this->set_error('imglib_copy_failed'); - return FALSE; - } - - @chmod($this->full_dst_path, 0777); - return TRUE; - } - - // If resizing the x/y axis must be zero - $this->x_axis = 0; - $this->y_axis = 0; - } - - // Create the image handle - if ( ! ($src_img = $this->image_create_gd())) - { - return FALSE; - } - - // Create The Image - if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE) - { - $create = 'imagecreatetruecolor'; - $copy = 'imagecopyresampled'; - } - else - { - $create = 'imagecreate'; - $copy = 'imagecopyresized'; - } - - $dst_img = $create($this->width, $this->height); - $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 - if ($this->dynamic_output == TRUE) - { - $this->image_display_gd($dst_img); - } - else - { - // Or save it - if ( ! $this->image_save_gd($dst_img)) - { - return FALSE; - } - } - - // Kill the file handles - imagedestroy($dst_img); - imagedestroy($src_img); - - // Set the file to 777 - @chmod($this->full_dst_path, 0777); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Image Process Using ImageMagick - * - * This function will resize, crop or rotate - * - * @access public - * @param string - * @return bool - */ - function image_process_imagemagick($action = 'resize') - { - // Do we have a vaild library path? - if ($this->library_path == '') - { - $this->set_error('imglib_libpath_invalid'); - return FALSE; - } - - if ( ! eregi("convert$", $this->library_path)) - { - if ( ! eregi("/$", $this->library_path)) $this->library_path .= "/"; - - $this->library_path .= 'convert'; - } - - // Execute the command - $cmd = $this->library_path." -quality ".$this->quality; - - if ($action == 'crop') - { - $cmd .= " -crop ".$this->width."x".$this->height."+".$this->x_axis."+".$this->y_axis." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; - } - elseif ($action == 'rotate') - { - switch ($this->rotation_angle) - { - case 'hor' : $angle = '-flop'; - break; - case 'vrt' : $angle = '-flip'; - break; - default : $angle = '-rotate '.$this->rotation_angle; - break; - } - - $cmd .= " ".$angle." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; - } - else // Resize - { - $cmd .= " -resize ".$this->width."x".$this->height." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; - } - - $retval = 1; - - @exec($cmd, $output, $retval); - - // Did it work? - if ($retval > 0) - { - $this->set_error('imglib_image_process_failed'); - return FALSE; - } - - // Set the file to 777 - @chmod($this->full_dst_path, 0777); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Image Process Using NetPBM - * - * This function will resize, crop or rotate - * - * @access public - * @param string - * @return bool - */ - function image_process_netpbm($action = 'resize') - { - if ($this->library_path == '') - { - $this->set_error('imglib_libpath_invalid'); - return FALSE; - } - - // Build the resizing command - switch ($this->image_type) - { - case 1 : - $cmd_in = 'giftopnm'; - $cmd_out = 'ppmtogif'; - break; - case 2 : - $cmd_in = 'jpegtopnm'; - $cmd_out = 'ppmtojpeg'; - break; - case 3 : - $cmd_in = 'pngtopnm'; - $cmd_out = 'ppmtopng'; - break; - } - - if ($action == 'crop') - { - $cmd_inner = 'pnmcut -left '.$this->x_axis.' -top '.$this->y_axis.' -width '.$this->width.' -height '.$this->height; - } - elseif ($action == 'rotate') - { - switch ($this->rotation_angle) - { - case 90 : $angle = 'r270'; - break; - case 180 : $angle = 'r180'; - break; - case 270 : $angle = 'r90'; - break; - case 'vrt' : $angle = 'tb'; - break; - case 'hor' : $angle = 'lr'; - break; - } - - $cmd_inner = 'pnmflip -'.$angle.' '; - } - else // Resize - { - $cmd_inner = 'pnmscale -xysize '.$this->width.' '.$this->height; - } - - $cmd = $this->library_path.$cmd_in.' '.$this->full_src_path.' | '.$cmd_inner.' | '.$cmd_out.' > '.$this->dest_folder.'netpbm.tmp'; - - $retval = 1; - - @exec($cmd, $output, $retval); - - // Did it work? - if ($retval > 0) - { - $this->set_error('imglib_image_process_failed'); - return FALSE; - } - - // With NetPBM we have to create a temporary image. - // If you try manipulating the original it fails so - // we have to rename the temp file. - copy ($this->dest_folder.'netpbm.tmp', $this->full_dst_path); - unlink ($this->dest_folder.'netpbm.tmp'); - @chmod($dst_image, 0777); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Image Rotate Using GD - * - * @access public - * @return bool - */ - function image_rotate_gd() - { - // Is Image Rotation Supported? - // this function is only supported as of PHP 4.3 - if ( ! function_exists('imagerotate')) - { - $this->set_error('imglib_rotate_unsupported'); - return FALSE; - } - - // Create the image handle - if ( ! ($src_img = $this->image_create_gd())) - { - return FALSE; - } - - // Set the background color - // This won't work with transparent PNG files so we are - // going to have to figure out how to determine the color - // of the alpha channel in a future release. - - $white = imagecolorallocate($src_img, 255, 255, 255); - - // Rotate it! - $dst_img = imagerotate($src_img, $this->rotation_angle, $white); - - // Save the Image - if ($this->dynamic_output == TRUE) - { - $this->image_display_gd($dst_img); - } - else - { - // Or save it - if ( ! $this->image_save_gd($dst_img)) - { - return FALSE; - } - } - - // Kill the file handles - imagedestroy($dst_img); - imagedestroy($src_img); - - // Set the file to 777 - - @chmod($this->full_dst_path, 0777); - - return true; - } - - // -------------------------------------------------------------------- - - /** - * Create Mirror Image using GD - * - * This function will flip horizontal or vertical - * - * @access public - * @return bool - */ - function image_mirror_gd() - { - if ( ! $src_img = $this->image_create_gd()) - { - return FALSE; - } - - $width = $this->orig_width; - $height = $this->orig_height; - - if ($this->rotation_angle == 'hor') - { - for ($i = 0; $i < $height; $i++) - { - $left = 0; - $right = $width-1; - - while ($left < $right) - { - $cl = imagecolorat($src_img, $left, $i); - $cr = imagecolorat($src_img, $right, $i); - - imagesetpixel($src_img, $left, $i, $cr); - imagesetpixel($src_img, $right, $i, $cl); - - $left++; - $right--; - } - } - } - else - { - for ($i = 0; $i < $width; $i++) - { - $top = 0; - $bot = $height-1; - - while ($top < $bot) - { - $ct = imagecolorat($src_img, $i, $top); - $cb = imagecolorat($src_img, $i, $bot); - - imagesetpixel($src_img, $i, $top, $cb); - imagesetpixel($src_img, $i, $bot, $ct); - - $top++; - $bot--; - } - } - } - - // Show the image - if ($this->dynamic_output == TRUE) - { - $this->image_display_gd($src_img); - } - else - { - // Or save it - if ( ! $this->image_save_gd($src_img)) - { - return FALSE; - } - } - - // Kill the file handles - imagedestroy($src_img); - - // Set the file to 777 - @chmod($this->full_dst_path, 0777); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Image Watermark - * - * This is a wrapper function that chooses the type - * of watermarking based on the specified preference. - * - * @access public - * @param string - * @return bool - */ - function watermark() - { - if ($this->wm_type == 'overlay') - { - return $this->overlay_watermark(); - } - else - { - return $this->text_watermark(); - } - } - - // -------------------------------------------------------------------- - - /** - * Watermark - Graphic Version - * - * @access public - * @return bool - */ - function overlay_watermark() - { - if ( ! function_exists('imagecolortransparent')) - { - $this->set_error('imglib_gd_required'); - return FALSE; - } - - // Fetch source image properties - $this->get_image_properties(); - - // Fetch watermark image properties - $props = $this->get_image_properties($this->wm_overlay_path, TRUE); - $wm_img_type = $props['image_type']; - $wm_width = $props['width']; - $wm_height = $props['height']; - - // Create two image resources - $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type); - $src_img = $this->image_create_gd($this->full_src_path); - - // Reverse the offset if necessary - // When the image is positioned at the bottom - // we don't want the vertical offset to push it - // further down. We want the reverse, so we'll - // invert the offset. Same with the horizontal - // offset when the image is at the right - - $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); - $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); - - if ($this->wm_vrt_alignment == 'B') - $this->wm_vrt_offset = $this->wm_vrt_offset * -1; - - if ($this->wm_hor_alignment == 'R') - $this->wm_hor_offset = $this->wm_hor_offset * -1; - - // Set the base x and y axis values - $x_axis = $this->wm_hor_offset + $this->wm_padding; - $y_axis = $this->wm_vrt_offset + $this->wm_padding; - - // Set the vertical position - switch ($this->wm_vrt_alignment) - { - case 'T': - break; - case 'M': $y_axis += ($this->orig_height / 2) - ($wm_height / 2); - break; - case 'B': $y_axis += $this->orig_height - $wm_height; - break; - } - - // Set the horizontal position - switch ($this->wm_hor_alignment) - { - case 'L': - break; - case 'C': $x_axis += ($this->orig_width / 2) - ($wm_width / 2); - break; - case 'R': $x_axis += $this->orig_width - $wm_width; - break; - } - - // Build the finalized image - if ($wm_img_type == 3 AND function_exists('imagealphablending')) - { - @imagealphablending($src_img, TRUE); - } - - // Set RGB values for text and shadow - imagecolortransparent($wm_img, imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp)); - imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity); - - // Output the image - if ($this->dynamic_output == TRUE) - { - $this->image_display_gd($src_img); - } - else - { - if ( ! $this->image_save_gd($src_img)) - { - return FALSE; - } - } - - imagedestroy($src_img); - imagedestroy($wm_img); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Watermark - Text Version - * - * @access public - * @return bool - */ - function text_watermark() - { - if ( ! ($src_img = $this->image_create_gd())) - { - return FALSE; - } - - if ($this->wm_use_truetype == TRUE AND ! file_exists($this->wm_font_path)) - { - $this->set_error('imglib_missing_font'); - return FALSE; - } - - // Fetch source image properties - $this->get_image_properties(); - - // Set RGB values for text and shadow - $this->wm_font_color = str_replace('#', '', $this->wm_font_color); - $this->wm_shadow_color = str_replace('#', '', $this->wm_shadow_color); - - $R1 = hexdec(substr($this->wm_font_color, 0, 2)); - $G1 = hexdec(substr($this->wm_font_color, 2, 2)); - $B1 = hexdec(substr($this->wm_font_color, 4, 2)); - - $R2 = hexdec(substr($this->wm_shadow_color, 0, 2)); - $G2 = hexdec(substr($this->wm_shadow_color, 2, 2)); - $B2 = hexdec(substr($this->wm_shadow_color, 4, 2)); - - $txt_color = imagecolorclosest($src_img, $R1, $G1, $B1); - $drp_color = imagecolorclosest($src_img, $R2, $G2, $B2); - - // Reverse the vertical offset - // When the image is positioned at the bottom - // we don't want the vertical offset to push it - // further down. We want the reverse, so we'll - // invert the offset. Note: The horizontal - // offset flips itself automatically - - if ($this->wm_vrt_alignment == 'B') - $this->wm_vrt_offset = $this->wm_vrt_offset * -1; - - if ($this->wm_hor_alignment == 'R') - $this->wm_hor_offset = $this->wm_hor_offset * -1; - - // Set font width and height - // These are calculated differently depending on - // whether we are using the true type font or not - if ($this->wm_use_truetype == TRUE) - { - if ($this->wm_font_size == '') - $this->wm_font_size = '17'; - - $fontwidth = $this->wm_font_size-($this->wm_font_size/4); - $fontheight = $this->wm_font_size; - $this->wm_vrt_offset += $this->wm_font_size; - } - else - { - $fontwidth = imagefontwidth($this->wm_font_size); - $fontheight = imagefontheight($this->wm_font_size); - } - - // Set base X and Y axis values - $x_axis = $this->wm_hor_offset + $this->wm_padding; - $y_axis = $this->wm_vrt_offset + $this->wm_padding; - - // Set verticle alignment - if ($this->wm_use_drop_shadow == FALSE) - $this->wm_shadow_distance = 0; - - $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); - $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); - - switch ($this->wm_vrt_alignment) - { - case "T" : - break; - case "M": $y_axis += ($this->orig_height/2)+($fontheight/2); - break; - case "B": $y_axis += ($this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight/2)); - break; - } - - $x_shad = $x_axis + $this->wm_shadow_distance; - $y_shad = $y_axis + $this->wm_shadow_distance; - - // Set horizontal alignment - switch ($this->wm_hor_alignment) - { - case "L": - break; - case "R": - if ($this->wm_use_drop_shadow) - $x_shad += ($this->orig_width - $fontwidth*strlen($this->wm_text)); - $x_axis += ($this->orig_width - $fontwidth*strlen($this->wm_text)); - break; - case "C": - if ($this->wm_use_drop_shadow) - $x_shad += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2); - $x_axis += floor(($this->orig_width -$fontwidth*strlen($this->wm_text))/2); - break; - } - - // Add the text to the source image - if ($this->wm_use_truetype) - { - if ($this->wm_use_drop_shadow) - imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text); - imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text); - } - else - { - if ($this->wm_use_drop_shadow) - imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color); - imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); - } - - // Output the final image - if ($this->dynamic_output == TRUE) - { - $this->image_display_gd($src_img); - } - else - { - $this->image_save_gd($src_img); - } - - imagedestroy($src_img); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Create Image - GD - * - * This simply creates an image resource handle - * based on the type of image being processed - * - * @access public - * @param string - * @return resource - */ - function image_create_gd($path = '', $image_type = '') - { - if ($path == '') - $path = $this->full_src_path; - - if ($image_type == '') - $image_type = $this->image_type; - - - switch ($image_type) - { - case 1 : - if ( ! function_exists('imagecreatefromgif')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); - return FALSE; - } - - return imagecreatefromgif($path); - break; - case 2 : - if ( ! function_exists('imagecreatefromjpeg')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); - return FALSE; - } - - return imagecreatefromjpeg($path); - break; - case 3 : - if ( ! function_exists('imagecreatefrompng')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); - return FALSE; - } - - return imagecreatefrompng($path); - break; - - } - - $this->set_error(array('imglib_unsupported_imagecreate')); - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Write image file to disk - GD - * - * Takes an image resource as input and writes the file - * to the specified destination - * - * @access public - * @param resource - * @return bool - */ - function image_save_gd($resource) - { - switch ($this->image_type) - { - case 1 : - if ( ! function_exists('imagegif')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); - return FALSE; - } - - @imagegif($resource, $this->full_dst_path); - break; - case 2 : - if ( ! function_exists('imagejpeg')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); - return FALSE; - } - - if (phpversion() == '4.4.1') - { - @touch($this->full_dst_path); // PHP 4.4.1 bug #35060 - workaround - } - - @imagejpeg($resource, $this->full_dst_path, $this->quality); - break; - case 3 : - if ( ! function_exists('imagepng')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); - return FALSE; - } - - @imagepng($resource, $this->full_dst_path); - break; - default : - $this->set_error(array('imglib_unsupported_imagecreate')); - return FALSE; - break; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Dynamically outputs an image - * - * @access public - * @param resource - * @return void - */ - function image_display_gd($resource) - { - header("Content-Disposition: filename={$this->source_image};"); - header("Content-Type: {$this->mime_type}"); - header('Content-Transfer-Encoding: binary'); - header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT'); - - switch ($this->image_type) - { - case 1 : imagegif($resource); - break; - case 2 : imagejpeg($resource, '', $this->quality); - break; - case 3 : imagepng($resource); - break; - default : echo 'Unable to display the image'; - break; - } - } - - // -------------------------------------------------------------------- - - /** - * Re-proportion Image Width/Height - * - * When creating thumbs, the desired width/height - * can end up warping the image due to an incorrect - * ratio between the full-sized image and the thumb. - * - * This function lets us re-proportion the width/height - * if users choose to maintain the aspect ratio when resizing. - * - * @access public - * @return void - */ - function image_reproportion() - { - if ( ! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0) - return; - - if ( ! is_numeric($this->orig_width) OR ! is_numeric($this->orig_height) OR $this->orig_width == 0 OR $this->orig_height == 0) - return; - - $new_width = ceil($this->orig_width*$this->height/$this->orig_height); - $new_height = ceil($this->width*$this->orig_height/$this->orig_width); - - $ratio = (($this->orig_height/$this->orig_width) - ($this->height/$this->width)); - - if ($this->master_dim != 'width' AND $this->master_dim != 'height') - { - $this->master_dim = ($ratio < 0) ? 'width' : 'height'; - } - - if (($this->width != $new_width) AND ($this->height != $new_height)) - { - if ($this->master_dim == 'height') - { - $this->width = $new_width; - } - else - { - $this->height = $new_height; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Get image properties - * - * A helper function that gets info about the file - * - * @access public - * @param string - * @return mixed - */ - function get_image_properties($path = '', $return = FALSE) - { - // For now we require GD but we should - // find a way to determine this using IM or NetPBM - - if ($path == '') - $path = $this->full_src_path; - - if ( ! file_exists($path)) - { - $this->set_error('imglib_invalid_path'); - return FALSE; - } - - $vals = @getimagesize($path); - - $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); - - $mime = (isset($types[$vals['2']])) ? 'image/'.$types[$vals['2']] : 'image/jpg'; - - if ($return == TRUE) - { - $v['width'] = $vals['0']; - $v['height'] = $vals['1']; - $v['image_type'] = $vals['2']; - $v['size_str'] = $vals['3']; - $v['mime_type'] = $mime; - - return $v; - } - - $this->orig_width = $vals['0']; - $this->orig_height = $vals['1']; - $this->image_type = $vals['2']; - $this->size_str = $vals['3']; - $this->mime_type = $mime; - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Size calculator - * - * This function takes a known width x height and - * recalculates it to a new size. Only one - * new variable needs to be known - * - * $props = array( - * 'width' => $width, - * 'height' => $height, - * 'new_width' => 40, - * 'new_height' => '' - * ); - * - * @access public - * @param array - * @return array - */ - function size_calculator($vals) - { - if ( ! is_array($vals)) - return; - - $allowed = array('new_width', 'new_height', 'width', 'height'); - - foreach ($allowed as $item) - { - if ( ! isset($vals[$item]) OR $vals[$item] == '') - $vals[$item] = 0; - } - - if ($vals['width'] == 0 OR $vals['height'] == 0) - { - return $vals; - } - - if ($vals['new_width'] == 0) - { - $vals['new_width'] = ceil($vals['width']*$vals['new_height']/$vals['height']); - } - elseif ($vals['new_height'] == 0) - { - $vals['new_height'] = ceil($vals['new_width']*$vals['height']/$vals['width']); - } - - return $vals; - } - - // -------------------------------------------------------------------- - - /** - * Explode source_image - * - * This is a helper function that extracts the extension - * from the source_image. This function lets us deal with - * source_images with multiple periods, like: my.cool.jpg - * It returns an associative array with two elements: - * $array['ext'] = '.jpg'; - * $array['name'] = 'my.cool'; - * - * @access public - * @param array - * @return array - */ - function explode_name($source_image) - { - $x = explode('.', $source_image); - $ret['ext'] = '.'.end($x); - - $name = ''; - - $ct = count($x)-1; - - for ($i = 0; $i < $ct; $i++) - { - $name .= $x[$i]; - - if ($i < ($ct - 1)) - { - $name .= '.'; - } - } - - $ret['name'] = $name; - - return $ret; - } - - // -------------------------------------------------------------------- - - /** - * Is GD Installed? - * - * @access public - * @return bool - */ - function gd_loaded() - { - if ( ! extension_loaded('gd')) - { - if ( ! dl('gd.so')) - { - return FALSE; - } - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Get GD version - * - * @access public - * @return mixed - */ - function gd_version() - { - if (function_exists('gd_info')) - { - $gd_version = @gd_info(); - $gd_version = preg_replace("/\D/", "", $gd_version['GD Version']); - - return $gd_version; - } - - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Set error message - * - * @access public - * @param string - * @return void - */ - function set_error($msg) - { - $CI =& get_instance(); - $CI->lang->load('imglib'); - - if (is_array($msg)) - { - foreach ($msg as $val) - { - - $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val); - $this->error_msg[] = $msg; - log_message('error', $msg); - } - } - else - { - $msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg); - $this->error_msg[] = $msg; - log_message('error', $msg); - } - } - - // -------------------------------------------------------------------- - - /** - * Show error messages - * - * @access public - * @param string - * @return string - */ - function display_errors($open = '

', $close = '

') - { - $str = ''; - foreach ($this->error_msg as $val) - { - $str .= $open.$val.$close; - } - - return $str; - } - -} -// END Image_lib Class + 0) + { + $this->initialize($props); + } + + log_message('debug', "Image Lib Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Initialize image properties + * + * Resets values in case this class is used in a loop + * + * @access public + * @return void + */ + function clear() + { + $props = array('source_folder', 'dest_folder', 'source_image', 'full_src_path', 'full_dst_path', 'new_image', 'image_type', 'size_str', 'quality', 'orig_width', 'orig_height', 'rotation_angle', 'x_axis', 'y_axis', 'create_fnc', 'copy_fnc', 'wm_overlay_path', 'wm_use_truetype', 'dynamic_output', 'wm_font_size', 'wm_text', 'wm_vrt_alignment', 'wm_hor_alignment', 'wm_padding', 'wm_hor_offset', 'wm_vrt_offset', 'wm_font_color', 'wm_use_drop_shadow', 'wm_shadow_color', 'wm_shadow_distance', 'wm_opacity'); + + foreach ($props as $val) + { + $this->$val = ''; + } + } + + // -------------------------------------------------------------------- + + /** + * initialize image preferences + * + * @access public + * @param array + * @return void + */ + function initialize($props = array()) + { + /* + * Convert array elements into class variables + */ + if (count($props) > 0) + { + foreach ($props as $key => $val) + { + $this->$key = $val; + } + } + + /* + * Is there a source image? + * + * If not, there's no reason to continue + * + */ + if ($this->source_image == '') + { + $this->set_error('imglib_source_image_required'); + return FALSE; + } + + /* + * Is getimagesize() Available? + * + * We use it to determine the image properties (width/height). + * Note: We need to figure out how to determine image + * properties using ImageMagick and NetPBM + * + */ + if ( ! function_exists('getimagesize')) + { + $this->set_error('imglib_gd_required_for_props'); + return FALSE; + } + + $this->image_library = strtolower($this->image_library); + + /* + * Set the full server path + * + * The source image may or may not contain a path. + * Either way, we'll try use realpath to generate the + * full server path in order to more reliably read it. + * + */ + if (function_exists('realpath') AND @realpath($this->source_image) !== FALSE) + { + $full_source_path = str_replace("\\", "/", realpath($this->source_image)); + } + else + { + $full_source_path = $this->source_image; + } + + $x = explode('/', $full_source_path); + $this->source_image = end($x); + $this->source_folder = str_replace($this->source_image, '', $full_source_path); + + // Set the Image Properties + if ( ! $this->get_image_properties($this->source_folder.$this->source_image)) + { + return FALSE; + } + + /* + * Assign the "new" image name/path + * + * If the user has set a "new_image" name it means + * we are making a copy of the source image. If not + * it means we are altering the original. We'll + * set the destination filename and path accordingly. + * + */ + if ($this->new_image == '') + { + $this->dest_image = $this->source_image; + $this->dest_folder = $this->source_folder; + } + else + { + if (strpos($this->new_image, '/') === FALSE) + { + $this->dest_folder = $this->source_folder; + $this->dest_image = $this->new_image; + } + else + { + if (function_exists('realpath') AND @realpath($this->new_image) !== FALSE) + { + $full_dest_path = str_replace("\\", "/", realpath($this->new_image)); + } + else + { + $full_dest_path = $this->new_image; + } + + // Is there a file name? + if ( ! preg_match("#[\.jpg|\.jpeg|\.gif|\.png]$#i", $full_dest_path)) + { + $this->dest_folder = $full_dest_path.'/'; + $this->dest_image = $this->source_image; + } + else + { + $x = explode('/', $full_dest_path); + $this->dest_image = end($x); + $this->dest_folder = str_replace($this->dest_image, '', $full_dest_path); + } + } + } + + /* + * Compile the finalized filenames/paths + * + * We'll create two master strings containing the + * full server path to the source image and the + * full server path to the destination image. + * We'll also split the destination image name + * so we can insert the thumbnail marker if needed. + * + */ + if ($this->create_thumb === FALSE OR $this->thumb_marker == '') + { + $this->thumb_marker = ''; + } + + $xp = $this->explode_name($this->dest_image); + + $filename = $xp['name']; + $file_ext = $xp['ext']; + + $this->full_src_path = $this->source_folder.$this->source_image; + $this->full_dst_path = $this->dest_folder.$filename.$this->thumb_marker.$file_ext; + + /* + * Should we maintain image proportions? + * + * When creating thumbs or copies, the target width/height + * might not be in correct proportion with the source + * image's width/height. We'll recalculate it here. + * + */ + if ($this->maintain_ratio === TRUE && ($this->width != '' AND $this->height != '')) + { + $this->image_reproportion(); + } + + /* + * Was a width and height specified? + * + * If the destination width/height was + * not submitted we will use the values + * from the actual file + * + */ + if ($this->width == '') + $this->width = $this->orig_width; + + if ($this->height == '') + $this->height = $this->orig_height; + + // Set the quality + $this->quality = trim(str_replace("%", "", $this->quality)); + + if ($this->quality == '' OR $this->quality == 0 OR ! is_numeric($this->quality)) + $this->quality = 90; + + // Set the x/y coordinates + $this->x_axis = ($this->x_axis == '' OR ! is_numeric($this->x_axis)) ? 0 : $this->x_axis; + $this->y_axis = ($this->y_axis == '' OR ! is_numeric($this->y_axis)) ? 0 : $this->y_axis; + + // Watermark-related Stuff... + if ($this->wm_font_color != '') + { + if (strlen($this->wm_font_color) == 6) + { + $this->wm_font_color = '#'.$this->wm_font_color; + } + } + + if ($this->wm_shadow_color != '') + { + if (strlen($this->wm_shadow_color) == 6) + { + $this->wm_shadow_color = '#'.$this->wm_shadow_color; + } + } + + if ($this->wm_overlay_path != '') + { + $this->wm_overlay_path = str_replace("\\", "/", realpath($this->wm_overlay_path)); + } + + if ($this->wm_shadow_color != '') + { + $this->wm_use_drop_shadow = TRUE; + } + + if ($this->wm_font_path != '') + { + $this->wm_use_truetype = TRUE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Image Resize + * + * This is a wrapper function that chooses the proper + * resize function based on the protocol specified + * + * @access public + * @return bool + */ + function resize() + { + $protocol = 'image_process_'.$this->image_library; + + if (eregi("gd2$", $protocol)) + { + $protocol = 'image_process_gd'; + } + + return $this->$protocol('resize'); + } + + // -------------------------------------------------------------------- + + /** + * Image Crop + * + * This is a wrapper function that chooses the proper + * cropping function based on the protocol specified + * + * @access public + * @return bool + */ + function crop() + { + $protocol = 'image_process_'.$this->image_library; + + if (eregi("gd2$", $protocol)) + { + $protocol = 'image_process_gd'; + } + + return $this->$protocol('crop'); + } + + // -------------------------------------------------------------------- + + /** + * Image Rotate + * + * This is a wrapper function that chooses the proper + * rotation function based on the protocol specified + * + * @access public + * @return bool + */ + function rotate() + { + // Allowed rotation values + $degs = array(90, 180, 270, 'vrt', 'hor'); + + if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs, TRUE)) + { + $this->set_error('imglib_rotation_angle_required'); + return FALSE; + } + + // Reassign the width and height + if ($this->rotation_angle == 90 OR $this->rotation_angle == 270) + { + $this->width = $this->orig_height; + $this->height = $this->orig_width; + } + else + { + $this->width = $this->orig_width; + $this->height = $this->orig_height; + } + + + // Choose resizing function + if ($this->image_library == 'imagemagick' OR $this->image_library == 'netpbm') + { + $protocol = 'image_process_'.$this->image_library; + + return $this->$protocol('rotate'); + } + + if ($this->rotation_angle == 'hor' OR $this->rotation_angle == 'vrt') + { + return $this->image_mirror_gd(); + } + else + { + return $this->image_rotate_gd(); + } + } + + // -------------------------------------------------------------------- + + /** + * Image Process Using GD/GD2 + * + * This function will resize or crop + * + * @access public + * @param string + * @return bool + */ + function image_process_gd($action = 'resize') + { + $v2_override = FALSE; + + if ($action == 'crop') + { + // If the target width/height match the source then it's pointless to crop, right? + if ($this->width >= $this->orig_width AND $this->height >= $this->orig_height) + { + // We'll return true so the user thinks the process succeeded. + // It'll be our little secret... + + return TRUE; + } + + // Reassign the source width/height if cropping + $this->orig_width = $this->width; + $this->orig_height = $this->height; + + // GD 2.0 has a cropping bug so we'll test for it + if ($this->gd_version() !== FALSE) + { + $gd_version = str_replace('0', '', $this->gd_version()); + $v2_override = ($gd_version == 2) ? TRUE : FALSE; + } + } + else + { + // If the target width/height match the source, AND if + // the new file name is not equal to the old file name + // we'll simply make a copy of the original with the new name + if (($this->orig_width == $this->width AND $this->orig_height == $this->height) AND ($this->source_image != $this->dest_image)) + { + if ( ! @copy($this->full_src_path, $this->full_dst_path)) + { + $this->set_error('imglib_copy_failed'); + return FALSE; + } + + @chmod($this->full_dst_path, 0777); + return TRUE; + } + + // If resizing the x/y axis must be zero + $this->x_axis = 0; + $this->y_axis = 0; + } + + // Create the image handle + if ( ! ($src_img = $this->image_create_gd())) + { + return FALSE; + } + + // Create The Image + if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE) + { + $create = 'imagecreatetruecolor'; + $copy = 'imagecopyresampled'; + } + else + { + $create = 'imagecreate'; + $copy = 'imagecopyresized'; + } + + $dst_img = $create($this->width, $this->height); + $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 + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($dst_img); + } + else + { + // Or save it + if ( ! $this->image_save_gd($dst_img)) + { + return FALSE; + } + } + + // Kill the file handles + imagedestroy($dst_img); + imagedestroy($src_img); + + // Set the file to 777 + @chmod($this->full_dst_path, 0777); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Image Process Using ImageMagick + * + * This function will resize, crop or rotate + * + * @access public + * @param string + * @return bool + */ + function image_process_imagemagick($action = 'resize') + { + // Do we have a vaild library path? + if ($this->library_path == '') + { + $this->set_error('imglib_libpath_invalid'); + return FALSE; + } + + if ( ! eregi("convert$", $this->library_path)) + { + if ( ! eregi("/$", $this->library_path)) $this->library_path .= "/"; + + $this->library_path .= 'convert'; + } + + // Execute the command + $cmd = $this->library_path." -quality ".$this->quality; + + if ($action == 'crop') + { + $cmd .= " -crop ".$this->width."x".$this->height."+".$this->x_axis."+".$this->y_axis." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; + } + elseif ($action == 'rotate') + { + switch ($this->rotation_angle) + { + case 'hor' : $angle = '-flop'; + break; + case 'vrt' : $angle = '-flip'; + break; + default : $angle = '-rotate '.$this->rotation_angle; + break; + } + + $cmd .= " ".$angle." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; + } + else // Resize + { + $cmd .= " -resize ".$this->width."x".$this->height." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; + } + + $retval = 1; + + @exec($cmd, $output, $retval); + + // Did it work? + if ($retval > 0) + { + $this->set_error('imglib_image_process_failed'); + return FALSE; + } + + // Set the file to 777 + @chmod($this->full_dst_path, 0777); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Image Process Using NetPBM + * + * This function will resize, crop or rotate + * + * @access public + * @param string + * @return bool + */ + function image_process_netpbm($action = 'resize') + { + if ($this->library_path == '') + { + $this->set_error('imglib_libpath_invalid'); + return FALSE; + } + + // Build the resizing command + switch ($this->image_type) + { + case 1 : + $cmd_in = 'giftopnm'; + $cmd_out = 'ppmtogif'; + break; + case 2 : + $cmd_in = 'jpegtopnm'; + $cmd_out = 'ppmtojpeg'; + break; + case 3 : + $cmd_in = 'pngtopnm'; + $cmd_out = 'ppmtopng'; + break; + } + + if ($action == 'crop') + { + $cmd_inner = 'pnmcut -left '.$this->x_axis.' -top '.$this->y_axis.' -width '.$this->width.' -height '.$this->height; + } + elseif ($action == 'rotate') + { + switch ($this->rotation_angle) + { + case 90 : $angle = 'r270'; + break; + case 180 : $angle = 'r180'; + break; + case 270 : $angle = 'r90'; + break; + case 'vrt' : $angle = 'tb'; + break; + case 'hor' : $angle = 'lr'; + break; + } + + $cmd_inner = 'pnmflip -'.$angle.' '; + } + else // Resize + { + $cmd_inner = 'pnmscale -xysize '.$this->width.' '.$this->height; + } + + $cmd = $this->library_path.$cmd_in.' '.$this->full_src_path.' | '.$cmd_inner.' | '.$cmd_out.' > '.$this->dest_folder.'netpbm.tmp'; + + $retval = 1; + + @exec($cmd, $output, $retval); + + // Did it work? + if ($retval > 0) + { + $this->set_error('imglib_image_process_failed'); + return FALSE; + } + + // With NetPBM we have to create a temporary image. + // If you try manipulating the original it fails so + // we have to rename the temp file. + copy ($this->dest_folder.'netpbm.tmp', $this->full_dst_path); + unlink ($this->dest_folder.'netpbm.tmp'); + @chmod($dst_image, 0777); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Image Rotate Using GD + * + * @access public + * @return bool + */ + function image_rotate_gd() + { + // Is Image Rotation Supported? + // this function is only supported as of PHP 4.3 + if ( ! function_exists('imagerotate')) + { + $this->set_error('imglib_rotate_unsupported'); + return FALSE; + } + + // Create the image handle + if ( ! ($src_img = $this->image_create_gd())) + { + return FALSE; + } + + // Set the background color + // This won't work with transparent PNG files so we are + // going to have to figure out how to determine the color + // of the alpha channel in a future release. + + $white = imagecolorallocate($src_img, 255, 255, 255); + + // Rotate it! + $dst_img = imagerotate($src_img, $this->rotation_angle, $white); + + // Save the Image + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($dst_img); + } + else + { + // Or save it + if ( ! $this->image_save_gd($dst_img)) + { + return FALSE; + } + } + + // Kill the file handles + imagedestroy($dst_img); + imagedestroy($src_img); + + // Set the file to 777 + + @chmod($this->full_dst_path, 0777); + + return true; + } + + // -------------------------------------------------------------------- + + /** + * Create Mirror Image using GD + * + * This function will flip horizontal or vertical + * + * @access public + * @return bool + */ + function image_mirror_gd() + { + if ( ! $src_img = $this->image_create_gd()) + { + return FALSE; + } + + $width = $this->orig_width; + $height = $this->orig_height; + + if ($this->rotation_angle == 'hor') + { + for ($i = 0; $i < $height; $i++) + { + $left = 0; + $right = $width-1; + + while ($left < $right) + { + $cl = imagecolorat($src_img, $left, $i); + $cr = imagecolorat($src_img, $right, $i); + + imagesetpixel($src_img, $left, $i, $cr); + imagesetpixel($src_img, $right, $i, $cl); + + $left++; + $right--; + } + } + } + else + { + for ($i = 0; $i < $width; $i++) + { + $top = 0; + $bot = $height-1; + + while ($top < $bot) + { + $ct = imagecolorat($src_img, $i, $top); + $cb = imagecolorat($src_img, $i, $bot); + + imagesetpixel($src_img, $i, $top, $cb); + imagesetpixel($src_img, $i, $bot, $ct); + + $top++; + $bot--; + } + } + } + + // Show the image + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($src_img); + } + else + { + // Or save it + if ( ! $this->image_save_gd($src_img)) + { + return FALSE; + } + } + + // Kill the file handles + imagedestroy($src_img); + + // Set the file to 777 + @chmod($this->full_dst_path, 0777); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Image Watermark + * + * This is a wrapper function that chooses the type + * of watermarking based on the specified preference. + * + * @access public + * @param string + * @return bool + */ + function watermark() + { + if ($this->wm_type == 'overlay') + { + return $this->overlay_watermark(); + } + else + { + return $this->text_watermark(); + } + } + + // -------------------------------------------------------------------- + + /** + * Watermark - Graphic Version + * + * @access public + * @return bool + */ + function overlay_watermark() + { + if ( ! function_exists('imagecolortransparent')) + { + $this->set_error('imglib_gd_required'); + return FALSE; + } + + // Fetch source image properties + $this->get_image_properties(); + + // Fetch watermark image properties + $props = $this->get_image_properties($this->wm_overlay_path, TRUE); + $wm_img_type = $props['image_type']; + $wm_width = $props['width']; + $wm_height = $props['height']; + + // Create two image resources + $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type); + $src_img = $this->image_create_gd($this->full_src_path); + + // Reverse the offset if necessary + // When the image is positioned at the bottom + // we don't want the vertical offset to push it + // further down. We want the reverse, so we'll + // invert the offset. Same with the horizontal + // offset when the image is at the right + + $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); + $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); + + if ($this->wm_vrt_alignment == 'B') + $this->wm_vrt_offset = $this->wm_vrt_offset * -1; + + if ($this->wm_hor_alignment == 'R') + $this->wm_hor_offset = $this->wm_hor_offset * -1; + + // Set the base x and y axis values + $x_axis = $this->wm_hor_offset + $this->wm_padding; + $y_axis = $this->wm_vrt_offset + $this->wm_padding; + + // Set the vertical position + switch ($this->wm_vrt_alignment) + { + case 'T': + break; + case 'M': $y_axis += ($this->orig_height / 2) - ($wm_height / 2); + break; + case 'B': $y_axis += $this->orig_height - $wm_height; + break; + } + + // Set the horizontal position + switch ($this->wm_hor_alignment) + { + case 'L': + break; + case 'C': $x_axis += ($this->orig_width / 2) - ($wm_width / 2); + break; + case 'R': $x_axis += $this->orig_width - $wm_width; + break; + } + + // Build the finalized image + if ($wm_img_type == 3 AND function_exists('imagealphablending')) + { + @imagealphablending($src_img, TRUE); + } + + // Set RGB values for text and shadow + imagecolortransparent($wm_img, imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp)); + imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity); + + // Output the image + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($src_img); + } + else + { + if ( ! $this->image_save_gd($src_img)) + { + return FALSE; + } + } + + imagedestroy($src_img); + imagedestroy($wm_img); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Watermark - Text Version + * + * @access public + * @return bool + */ + function text_watermark() + { + if ( ! ($src_img = $this->image_create_gd())) + { + return FALSE; + } + + if ($this->wm_use_truetype == TRUE AND ! file_exists($this->wm_font_path)) + { + $this->set_error('imglib_missing_font'); + return FALSE; + } + + // Fetch source image properties + $this->get_image_properties(); + + // Set RGB values for text and shadow + $this->wm_font_color = str_replace('#', '', $this->wm_font_color); + $this->wm_shadow_color = str_replace('#', '', $this->wm_shadow_color); + + $R1 = hexdec(substr($this->wm_font_color, 0, 2)); + $G1 = hexdec(substr($this->wm_font_color, 2, 2)); + $B1 = hexdec(substr($this->wm_font_color, 4, 2)); + + $R2 = hexdec(substr($this->wm_shadow_color, 0, 2)); + $G2 = hexdec(substr($this->wm_shadow_color, 2, 2)); + $B2 = hexdec(substr($this->wm_shadow_color, 4, 2)); + + $txt_color = imagecolorclosest($src_img, $R1, $G1, $B1); + $drp_color = imagecolorclosest($src_img, $R2, $G2, $B2); + + // Reverse the vertical offset + // When the image is positioned at the bottom + // we don't want the vertical offset to push it + // further down. We want the reverse, so we'll + // invert the offset. Note: The horizontal + // offset flips itself automatically + + if ($this->wm_vrt_alignment == 'B') + $this->wm_vrt_offset = $this->wm_vrt_offset * -1; + + if ($this->wm_hor_alignment == 'R') + $this->wm_hor_offset = $this->wm_hor_offset * -1; + + // Set font width and height + // These are calculated differently depending on + // whether we are using the true type font or not + if ($this->wm_use_truetype == TRUE) + { + if ($this->wm_font_size == '') + $this->wm_font_size = '17'; + + $fontwidth = $this->wm_font_size-($this->wm_font_size/4); + $fontheight = $this->wm_font_size; + $this->wm_vrt_offset += $this->wm_font_size; + } + else + { + $fontwidth = imagefontwidth($this->wm_font_size); + $fontheight = imagefontheight($this->wm_font_size); + } + + // Set base X and Y axis values + $x_axis = $this->wm_hor_offset + $this->wm_padding; + $y_axis = $this->wm_vrt_offset + $this->wm_padding; + + // Set verticle alignment + if ($this->wm_use_drop_shadow == FALSE) + $this->wm_shadow_distance = 0; + + $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); + $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); + + switch ($this->wm_vrt_alignment) + { + case "T" : + break; + case "M": $y_axis += ($this->orig_height/2)+($fontheight/2); + break; + case "B": $y_axis += ($this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight/2)); + break; + } + + $x_shad = $x_axis + $this->wm_shadow_distance; + $y_shad = $y_axis + $this->wm_shadow_distance; + + // Set horizontal alignment + switch ($this->wm_hor_alignment) + { + case "L": + break; + case "R": + if ($this->wm_use_drop_shadow) + $x_shad += ($this->orig_width - $fontwidth*strlen($this->wm_text)); + $x_axis += ($this->orig_width - $fontwidth*strlen($this->wm_text)); + break; + case "C": + if ($this->wm_use_drop_shadow) + $x_shad += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2); + $x_axis += floor(($this->orig_width -$fontwidth*strlen($this->wm_text))/2); + break; + } + + // Add the text to the source image + if ($this->wm_use_truetype) + { + if ($this->wm_use_drop_shadow) + imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text); + imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text); + } + else + { + if ($this->wm_use_drop_shadow) + imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color); + imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); + } + + // Output the final image + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($src_img); + } + else + { + $this->image_save_gd($src_img); + } + + imagedestroy($src_img); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Create Image - GD + * + * This simply creates an image resource handle + * based on the type of image being processed + * + * @access public + * @param string + * @return resource + */ + function image_create_gd($path = '', $image_type = '') + { + if ($path == '') + $path = $this->full_src_path; + + if ($image_type == '') + $image_type = $this->image_type; + + + switch ($image_type) + { + case 1 : + if ( ! function_exists('imagecreatefromgif')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); + return FALSE; + } + + return imagecreatefromgif($path); + break; + case 2 : + if ( ! function_exists('imagecreatefromjpeg')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); + return FALSE; + } + + return imagecreatefromjpeg($path); + break; + case 3 : + if ( ! function_exists('imagecreatefrompng')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); + return FALSE; + } + + return imagecreatefrompng($path); + break; + + } + + $this->set_error(array('imglib_unsupported_imagecreate')); + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Write image file to disk - GD + * + * Takes an image resource as input and writes the file + * to the specified destination + * + * @access public + * @param resource + * @return bool + */ + function image_save_gd($resource) + { + switch ($this->image_type) + { + case 1 : + if ( ! function_exists('imagegif')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); + return FALSE; + } + + @imagegif($resource, $this->full_dst_path); + break; + case 2 : + if ( ! function_exists('imagejpeg')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); + return FALSE; + } + + if (phpversion() == '4.4.1') + { + @touch($this->full_dst_path); // PHP 4.4.1 bug #35060 - workaround + } + + @imagejpeg($resource, $this->full_dst_path, $this->quality); + break; + case 3 : + if ( ! function_exists('imagepng')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); + return FALSE; + } + + @imagepng($resource, $this->full_dst_path); + break; + default : + $this->set_error(array('imglib_unsupported_imagecreate')); + return FALSE; + break; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Dynamically outputs an image + * + * @access public + * @param resource + * @return void + */ + function image_display_gd($resource) + { + header("Content-Disposition: filename={$this->source_image};"); + header("Content-Type: {$this->mime_type}"); + header('Content-Transfer-Encoding: binary'); + header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT'); + + switch ($this->image_type) + { + case 1 : imagegif($resource); + break; + case 2 : imagejpeg($resource, '', $this->quality); + break; + case 3 : imagepng($resource); + break; + default : echo 'Unable to display the image'; + break; + } + } + + // -------------------------------------------------------------------- + + /** + * Re-proportion Image Width/Height + * + * When creating thumbs, the desired width/height + * can end up warping the image due to an incorrect + * ratio between the full-sized image and the thumb. + * + * This function lets us re-proportion the width/height + * if users choose to maintain the aspect ratio when resizing. + * + * @access public + * @return void + */ + function image_reproportion() + { + if ( ! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0) + return; + + if ( ! is_numeric($this->orig_width) OR ! is_numeric($this->orig_height) OR $this->orig_width == 0 OR $this->orig_height == 0) + return; + + $new_width = ceil($this->orig_width*$this->height/$this->orig_height); + $new_height = ceil($this->width*$this->orig_height/$this->orig_width); + + $ratio = (($this->orig_height/$this->orig_width) - ($this->height/$this->width)); + + if ($this->master_dim != 'width' AND $this->master_dim != 'height') + { + $this->master_dim = ($ratio < 0) ? 'width' : 'height'; + } + + if (($this->width != $new_width) AND ($this->height != $new_height)) + { + if ($this->master_dim == 'height') + { + $this->width = $new_width; + } + else + { + $this->height = $new_height; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Get image properties + * + * A helper function that gets info about the file + * + * @access public + * @param string + * @return mixed + */ + function get_image_properties($path = '', $return = FALSE) + { + // For now we require GD but we should + // find a way to determine this using IM or NetPBM + + if ($path == '') + $path = $this->full_src_path; + + if ( ! file_exists($path)) + { + $this->set_error('imglib_invalid_path'); + return FALSE; + } + + $vals = @getimagesize($path); + + $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); + + $mime = (isset($types[$vals['2']])) ? 'image/'.$types[$vals['2']] : 'image/jpg'; + + if ($return == TRUE) + { + $v['width'] = $vals['0']; + $v['height'] = $vals['1']; + $v['image_type'] = $vals['2']; + $v['size_str'] = $vals['3']; + $v['mime_type'] = $mime; + + return $v; + } + + $this->orig_width = $vals['0']; + $this->orig_height = $vals['1']; + $this->image_type = $vals['2']; + $this->size_str = $vals['3']; + $this->mime_type = $mime; + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Size calculator + * + * This function takes a known width x height and + * recalculates it to a new size. Only one + * new variable needs to be known + * + * $props = array( + * 'width' => $width, + * 'height' => $height, + * 'new_width' => 40, + * 'new_height' => '' + * ); + * + * @access public + * @param array + * @return array + */ + function size_calculator($vals) + { + if ( ! is_array($vals)) + return; + + $allowed = array('new_width', 'new_height', 'width', 'height'); + + foreach ($allowed as $item) + { + if ( ! isset($vals[$item]) OR $vals[$item] == '') + $vals[$item] = 0; + } + + if ($vals['width'] == 0 OR $vals['height'] == 0) + { + return $vals; + } + + if ($vals['new_width'] == 0) + { + $vals['new_width'] = ceil($vals['width']*$vals['new_height']/$vals['height']); + } + elseif ($vals['new_height'] == 0) + { + $vals['new_height'] = ceil($vals['new_width']*$vals['height']/$vals['width']); + } + + return $vals; + } + + // -------------------------------------------------------------------- + + /** + * Explode source_image + * + * This is a helper function that extracts the extension + * from the source_image. This function lets us deal with + * source_images with multiple periods, like: my.cool.jpg + * It returns an associative array with two elements: + * $array['ext'] = '.jpg'; + * $array['name'] = 'my.cool'; + * + * @access public + * @param array + * @return array + */ + function explode_name($source_image) + { + $x = explode('.', $source_image); + $ret['ext'] = '.'.end($x); + + $name = ''; + + $ct = count($x)-1; + + for ($i = 0; $i < $ct; $i++) + { + $name .= $x[$i]; + + if ($i < ($ct - 1)) + { + $name .= '.'; + } + } + + $ret['name'] = $name; + + return $ret; + } + + // -------------------------------------------------------------------- + + /** + * Is GD Installed? + * + * @access public + * @return bool + */ + function gd_loaded() + { + if ( ! extension_loaded('gd')) + { + if ( ! dl('gd.so')) + { + return FALSE; + } + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Get GD version + * + * @access public + * @return mixed + */ + function gd_version() + { + if (function_exists('gd_info')) + { + $gd_version = @gd_info(); + $gd_version = preg_replace("/\D/", "", $gd_version['GD Version']); + + return $gd_version; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Set error message + * + * @access public + * @param string + * @return void + */ + function set_error($msg) + { + $CI =& get_instance(); + $CI->lang->load('imglib'); + + if (is_array($msg)) + { + foreach ($msg as $val) + { + + $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val); + $this->error_msg[] = $msg; + log_message('error', $msg); + } + } + else + { + $msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg); + $this->error_msg[] = $msg; + log_message('error', $msg); + } + } + + // -------------------------------------------------------------------- + + /** + * Show error messages + * + * @access public + * @param string + * @return string + */ + function display_errors($open = '

', $close = '

') + { + $str = ''; + foreach ($this->error_msg as $val) + { + $str .= $open.$val.$close; + } + + return $str; + } + +} +// END Image_lib Class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 085c00ff6948bd21e72d24c53457f3bbf2274985 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 5 Feb 2007 22:36:56 +0000 Subject: --- system/libraries/Loader.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 0947046ed..f76146ffd 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -499,10 +499,10 @@ class CI_Loader { * @param string * @return void */ - function config($file = '') - { + function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) + { $CI =& get_instance(); - $CI->config->load($file); + $CI->config->load($file, $use_sections, $fail_gracefully); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 7fcf8ca599f21732a124b8d2610f32a9e4b01c7d Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 5 Feb 2007 22:46:56 +0000 Subject: --- system/libraries/Loader.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index f76146ffd..38d7c35a8 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -697,7 +697,6 @@ class CI_Loader { } // Lets search for the requested library file and load it. - $is_duplicate = FALSE; for ($i = 1; $i < 3; $i++) { $path = ($i % 2) ? APPPATH : BASEPATH; @@ -712,8 +711,8 @@ class CI_Loader { // Safety: Was the class already loaded by a previous call? if (in_array($fp, $this->_ci_classes)) { - $is_duplicate = TRUE; - continue; + log_message('debug', $class." class already loaded.Ê Second attempt ignored."); + return; } include($fp); -- cgit v1.2.3-24-g4f1b From 29eff53d35fd2fb1ba8867eab20794ef0a53d5bb Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 5 Feb 2007 23:55:06 +0000 Subject: Fixed a typo in error message --- system/libraries/Loader.php | 1860 +++++++++++++++++++++---------------------- 1 file changed, 930 insertions(+), 930 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 38d7c35a8..d11630712 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -1,931 +1,931 @@ - 'unit', 'user_agent' => 'agent'); - - - /** - * Constructor - * - * Sets the path to the view files and gets the initial output buffering level - * - * @access public - */ - function CI_Loader() - { - $this->_ci_is_php5 = (floor(phpversion()) >= 5) ? TRUE : FALSE; - $this->_ci_view_path = APPPATH.'views/'; - $this->_ci_ob_level = ob_get_level(); - - log_message('debug', "Loader Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Class Loader - * - * This function lets users load and instantiate classes. - * It is designed to be called from a user's app controllers. - * - * @access public - * @param string the name of the class - * @param mixed the optional parameters - * @return void - */ - function library($library = '', $params = NULL) - { - if ($library == '') - { - return FALSE; - } - - if (is_array($library)) - { - foreach ($library as $class) - { - $this->_ci_load_class($class, $params); - } - } - else - { - $this->_ci_load_class($library, $params); - } - - $this->_ci_assign_to_models(); - } - - // -------------------------------------------------------------------- - - /** - * Model Loader - * - * This function lets users load and instantiate models. - * - * @access public - * @param string the name of the class - * @param mixed any initialization parameters - * @return void - */ - function model($model, $name = '', $db_conn = FALSE) - { - if ($model == '') - return; - - // Is the model in a sub-folder? If so, parse out the filename and path. - if (strpos($model, '/') === FALSE) - { - $path = ''; - } - else - { - $x = explode('/', $model); - $model = end($x); - unset($x[count($x)-1]); - $path = implode('/', $x).'/'; - } - - 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); - - if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT)) - { - show_error('Unable to locate the model you have specified: '.$model); - } - - if ($db_conn !== FALSE AND ! class_exists('CI_DB')) - { - if ($db_conn === TRUE) - $db_conn = ''; - - $CI->load->database($db_conn, FALSE, TRUE); - } - - if ( ! class_exists('Model')) - { - require_once(BASEPATH.'libraries/Model'.EXT); - } - - require_once(APPPATH.'models/'.$path.$model.EXT); - - $model = ucfirst($model); - - $CI->$name = new $model(); - $CI->$name->_assign_libraries(); - - $this->_ci_models[] = $name; - } - - // -------------------------------------------------------------------- - - /** - * Database Loader - * - * @access public - * @param string the DB credentials - * @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 = FALSE) - { - // Do we even need to load the database class? - if (class_exists('CI_DB') AND $return == FALSE AND $active_record == FALSE) - { - return FALSE; - } - - require_once(BASEPATH.'database/DB'.EXT); - - if ($return === TRUE) - { - return DB($params, $active_record); - } - - // Grab the super object - $CI =& get_instance(); - - // Initialize the db variable. Needed to prevent - // reference errors with some configurations - $CI->db = ''; - - // Load the DB class - $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 - */ - function dbutil() - { - if ( ! class_exists('CI_DB')) - { - $this->database(); - } - - $CI =& get_instance(); - - 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'; - - $CI->dbutil = new $class(); - $CI->load->_ci_assign_to_models(); - } - - // -------------------------------------------------------------------- - - /** - * Load View - * - * This function is used to load a "view" file. It has three parameters: - * - * 1. The name of the "view" file to be included. - * 2. An associative array of data to be extracted for use in the view. - * 3. TRUE/FALSE - whether to return the data or load it. In - * some cases it's advantageous to be able to return data so that - * a developer can process it in some way. - * - * @access public - * @param string - * @param array - * @param bool - * @return void - */ - function view($view, $vars = array(), $return = FALSE) - { - return $this->_ci_load(array('view' => $view, 'vars' => $this->_ci_object_to_array($vars), 'return' => $return)); - } - - // -------------------------------------------------------------------- - - /** - * Load File - * - * This is a generic file loader - * - * @access public - * @param string - * @param bool - * @return string - */ - function file($path, $return = FALSE) - { - return $this->_ci_load(array('path' => $path, 'return' => $return)); - } - - // -------------------------------------------------------------------- - - /** - * Set Variables - * - * Once variables are set they become available within - * the controller class and its "view" files. - * - * @access public - * @param array - * @return void - */ - function vars($vars = array()) - { - $vars = $this->_ci_object_to_array($vars); - - if (is_array($vars) AND count($vars) > 0) - { - foreach ($vars as $key => $val) - { - $this->_ci_cached_vars[$key] = $val; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Load Helper - * - * This function loads the specified helper file. - * - * @access public - * @param mixed - * @return void - */ - function helper($helpers = array()) - { - if ( ! is_array($helpers)) - { - $helpers = array($helpers); - } - - foreach ($helpers as $helper) - { - $helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper'); - - if (isset($this->_ci_helpers[$helper])) - { - continue; - } - - if (file_exists(APPPATH.'helpers/'.$helper.EXT)) - { - include_once(APPPATH.'helpers/'.$helper.EXT); - } - else - { - if (file_exists(BASEPATH.'helpers/'.$helper.EXT)) - { - include(BASEPATH.'helpers/'.$helper.EXT); - } - else - { - show_error('Unable to load the requested file: helpers/'.$helper.EXT); - } - } - - $this->_ci_helpers[$helper] = TRUE; - - } - - log_message('debug', 'Helpers loaded: '.implode(', ', $helpers)); - } - - // -------------------------------------------------------------------- - - /** - * Load Helpers - * - * This is simply an alias to the above function in case the - * user has written the plural form of this function. - * - * @access public - * @param array - * @return void - */ - function helpers($helpers = array()) - { - $this->helper($helpers); - } - - // -------------------------------------------------------------------- - - /** - * Load Plugin - * - * This function loads the specified plugin. - * - * @access public - * @param array - * @return void - */ - function plugin($plugins = array()) - { - if ( ! is_array($plugins)) - { - $plugins = array($plugins); - } - - foreach ($plugins as $plugin) - { - $plugin = strtolower(str_replace(EXT, '', str_replace('_plugin.', '', $plugin)).'_pi'); - - if (isset($this->_ci_plugins[$plugin])) - { - continue; - } - - if (file_exists(APPPATH.'plugins/'.$plugin.EXT)) - { - include(APPPATH.'plugins/'.$plugin.EXT); - } - else - { - if (file_exists(BASEPATH.'plugins/'.$plugin.EXT)) - { - include(BASEPATH.'plugins/'.$plugin.EXT); - } - else - { - show_error('Unable to load the requested file: plugins/'.$plugin.EXT); - } - } - - $this->_ci_plugins[$plugin] = TRUE; - } - - log_message('debug', 'Plugins loaded: '.implode(', ', $plugins)); - } - - // -------------------------------------------------------------------- - - /** - * Load Plugins - * - * This is simply an alias to the above function in case the - * user has written the plural form of this function. - * - * @access public - * @param array - * @return void - */ - function plugins($plugins = array()) - { - $this->plugin($plugins); - } - - // -------------------------------------------------------------------- - - /** - * Load Script - * - * This function loads the specified include file from the - * application/scripts/ folder. - * - * NOTE: This feature has been deprecated but it will remain available - * for legacy users. - * - * @access public - * @param array - * @return void - */ - function script($scripts = array()) - { - if ( ! is_array($scripts)) - { - $scripts = array($scripts); - } - - foreach ($scripts as $script) - { - $script = strtolower(str_replace(EXT, '', $script)); - - if (isset($this->_ci_scripts[$script])) - { - continue; - } - - if ( ! file_exists(APPPATH.'scripts/'.$script.EXT)) - { - show_error('Unable to load the requested script: scripts/'.$script.EXT); - } - - include(APPPATH.'scripts/'.$script.EXT); - } - - log_message('debug', 'Scripts loaded: '.implode(', ', $scripts)); - } - - // -------------------------------------------------------------------- - - /** - * Loads a language file - * - * @access public - * @param string - * @return void - */ - function language($file = '', $lang = '', $return = FALSE) - { - $CI =& get_instance(); - return $CI->lang->load($file, $lang, $return); - } - - // -------------------------------------------------------------------- - - /** - * Loads a config file - * - * @access public - * @param string - * @return void - */ - function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) - { - $CI =& get_instance(); - $CI->config->load($file, $use_sections, $fail_gracefully); - } - - // -------------------------------------------------------------------- - - /** - * Scaffolding Loader - * - * This initializing function works a bit different than the - * others. It doesn't load the class. Instead, it simply - * sets a flag indicating that scaffolding is allowed to be - * used. The actual scaffolding function below is - * called by the front controller based on whether the - * second segment of the URL matches the "secret" scaffolding - * word stored in the application/config/routes.php - * - * @access public - * @param string - * @return void - */ - function scaffolding($table = '') - { - if ($table === FALSE) - { - show_error('You must include the name of the table you would like access when you initialize scaffolding'); - } - - $CI =& get_instance(); - $CI->_ci_scaffolding = TRUE; - $CI->_ci_scaff_table = $table; - } - - // -------------------------------------------------------------------- - - /** - * Loader - * - * This function is used to load views and files. - * - * @access private - * @param array - * @return void - */ - function _ci_load($data) - { - // Set the default data variables - foreach (array('view', 'vars', 'path', 'return') as $val) - { - $$val = ( ! isset($data[$val])) ? FALSE : $data[$val]; - } - - // Set the path to the requested file - if ($path == '') - { - $ext = pathinfo($view, PATHINFO_EXTENSION); - $file = ($ext == '') ? $view.EXT : $view; - $path = $this->_ci_view_path.$file; - } - else - { - $x = explode('/', $path); - $file = end($x); - } - - if ( ! file_exists($path)) - { - show_error('Unable to load the requested file: '.$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 =& get_instance(); - foreach (get_object_vars($CI) as $key => $var) - { - if ( ! isset($this->$key)) - { - $this->$key =& $CI->$key; - } - } - } - - /* - * Extract and cache variables - * - * You can either set variables using the dedicated $this->load_vars() - * 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($vars)) - { - $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $vars); - } - extract($this->_ci_cached_vars); - - /* - * Buffer the output - * - * We buffer the output for two reasons: - * 1. Speed. You get a significant speed boost. - * 2. So that the final rendered template can be - * post-processed by the output class. Why do we - * need post processing? For one thing, in order to - * show the elapsed page load time. Unless we - * can intercept the content right before it's sent to - * 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(' $this->_ci_ob_level + 1) - { - ob_end_flush(); - } - else - { - // PHP 4 requires that we use a global - global $OUT; - $OUT->set_output(ob_get_contents()); - @ob_end_clean(); - } - } - - // -------------------------------------------------------------------- - - /** - * Load class - * - * This function loads the requested class. - * - * @access private - * @param string the item that is being loaded - * @param mixed any additional parameters - * @return void - */ - function _ci_load_class($class, $params = NULL) - { - // Get the class name - $class = str_replace(EXT, '', $class); - - // We'll test for both lowercase and capitalized versions of the file name - foreach (array(ucfirst($class), strtolower($class)) as $class) - { - // Is this a class extension request? - if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT)) - { - if ( ! file_exists(BASEPATH.'libraries/'.ucfirst($class).EXT)) - { - log_message('error', "Unable to load the requested class: ".$class); - show_error("Unable to load the requested class: ".$class); - } - - include(BASEPATH.'libraries/'.ucfirst($class).EXT); - include(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT); - - return $this->_ci_init_class($class, config_item('subclass_prefix'), $params); - } - - // Lets search for the requested library file and load it. - for ($i = 1; $i < 3; $i++) - { - $path = ($i % 2) ? APPPATH : BASEPATH; - $fp = $path.'libraries/'.$class.EXT; - - // Does the file exist? No? Bummer... - if ( ! file_exists($fp)) - { - continue; - } - - // Safety: Was the class already loaded by a previous call? - if (in_array($fp, $this->_ci_classes)) - { - log_message('debug', $class." class already loaded.Ê Second attempt ignored."); - return; - } - - include($fp); - $this->_ci_classes[] = $fp; - return $this->_ci_init_class($class, '', $params); - } - } // END FOREACH - - // If we got this far we were unable to find the requested class. - // We do not issue errors if the load call failed due to a duplicate request - if ($is_duplicate == FALSE) - { - log_message('error', "Unable to load the requested class: ".$class); - show_error("Unable to load the requested class: ".$class); - } - } - - // -------------------------------------------------------------------- - - /** - * Instantiates a class - * - * @access private - * @param string - * @param string - * @return null - */ - function _ci_init_class($class, $prefix = '', $config = FALSE) - { - // Is there an associated config file for this class? - if ($config === NULL) - { - $config = NULL; - if (file_exists(APPPATH.'config/'.$class.EXT)) - { - include(APPPATH.'config/'.$class.EXT); - } - } - - if ($prefix == '') - { - $name = (class_exists('CI_'.$class)) ? 'CI_'.$class : $class; - } - else - { - $name = $prefix.$class; - } - - // Set the variable name we will assign the class to - $class = strtolower($class); - $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; - - // Instantiate the class - $CI =& get_instance(); - if ($config !== NULL) - { - $CI->$classvar = new $name($config); - } - else - { - $CI->$classvar = new $name; - } - } - - // -------------------------------------------------------------------- - - /** - * Autoloader - * - * The config/autoload.php file contains an array that permits sub-systems, - * libraries, plugins, and helpers to be loaded automatically. - * - * @access private - * @param array - * @return void - */ - function _ci_autoloader() - { - include(APPPATH.'config/autoload'.EXT); - - if ( ! isset($autoload)) - { - return FALSE; - } - - // Load any custome config file - if (count($autoload['config']) > 0) - { - $CI =& get_instance(); - foreach ($autoload['config'] as $key => $val) - { - $CI->config->load($val); - } - } - - // Load plugins, helpers, and scripts - foreach (array('helper', 'plugin', 'script') as $type) - { - if (isset($autoload[$type]) AND count($autoload[$type]) > 0) - { - $this->$type($autoload[$type]); - } - } - - // A little tweak to remain backward compatible - // The $autoload['core'] item was deprecated - if ( ! isset($autoload['libraries'])) - { - $autoload['libraries'] = $autoload['core']; - } - - // Load libraries - if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0) - { - // Load the database driver. - if (in_array('database', $autoload['libraries'])) - { - $this->database(); - $autoload['libraries'] = array_diff($autoload['libraries'], array('database')); - } - - // Load the model class. - if (in_array('model', $autoload['libraries'])) - { - $this->model(); - $autoload['libraries'] = array_diff($autoload['libraries'], array('model')); - } - - // Load scaffolding - if (in_array('scaffolding', $autoload['libraries'])) - { - $this->scaffolding(); - $autoload['libraries'] = array_diff($autoload['libraries'], array('scaffolding')); - } - - // Load all other libraries - foreach ($autoload['libraries'] as $item) - { - $this->library($item); - } - } - } - - // -------------------------------------------------------------------- - - /** - * Assign to Models - * - * Makes sure that anything loaded by the loader class (libraries, plugins, etc.) - * will be available to models, if any exist. - * - * @access private - * @param object - * @return array - */ - function _ci_assign_to_models() - { - if (count($this->_ci_models) == 0) - { - return; - } - - if ($this->_ci_is_instance()) - { - $CI =& get_instance(); - foreach ($this->_ci_models as $model) - { - $CI->$model->_assign_libraries(); - } - } - else - { - foreach ($this->_ci_models as $model) - { - $this->$model->_assign_libraries(); - } - } - } - - // -------------------------------------------------------------------- - - /** - * Object to Array - * - * Takes an object as input and converts the class variables to array key/vals - * - * @access private - * @param object - * @return array - */ - function _ci_object_to_array($object) - { - return (is_object($object)) ? get_object_vars($object) : $object; - } - - // -------------------------------------------------------------------- - - /** - * Determines whether we should use the CI instance or $this - * - * @access private - * @return bool - */ - function _ci_is_instance() - { - if ($this->_ci_is_php5 == TRUE) - { - return TRUE; - } - - global $CI; - return (is_object($CI)) ? TRUE : FALSE; - } - -} + 'unit', 'user_agent' => 'agent'); + + + /** + * Constructor + * + * Sets the path to the view files and gets the initial output buffering level + * + * @access public + */ + function CI_Loader() + { + $this->_ci_is_php5 = (floor(phpversion()) >= 5) ? TRUE : FALSE; + $this->_ci_view_path = APPPATH.'views/'; + $this->_ci_ob_level = ob_get_level(); + + log_message('debug', "Loader Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Class Loader + * + * This function lets users load and instantiate classes. + * It is designed to be called from a user's app controllers. + * + * @access public + * @param string the name of the class + * @param mixed the optional parameters + * @return void + */ + function library($library = '', $params = NULL) + { + if ($library == '') + { + return FALSE; + } + + if (is_array($library)) + { + foreach ($library as $class) + { + $this->_ci_load_class($class, $params); + } + } + else + { + $this->_ci_load_class($library, $params); + } + + $this->_ci_assign_to_models(); + } + + // -------------------------------------------------------------------- + + /** + * Model Loader + * + * This function lets users load and instantiate models. + * + * @access public + * @param string the name of the class + * @param mixed any initialization parameters + * @return void + */ + function model($model, $name = '', $db_conn = FALSE) + { + if ($model == '') + return; + + // Is the model in a sub-folder? If so, parse out the filename and path. + if (strpos($model, '/') === FALSE) + { + $path = ''; + } + else + { + $x = explode('/', $model); + $model = end($x); + unset($x[count($x)-1]); + $path = implode('/', $x).'/'; + } + + 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); + + if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT)) + { + show_error('Unable to locate the model you have specified: '.$model); + } + + if ($db_conn !== FALSE AND ! class_exists('CI_DB')) + { + if ($db_conn === TRUE) + $db_conn = ''; + + $CI->load->database($db_conn, FALSE, TRUE); + } + + if ( ! class_exists('Model')) + { + require_once(BASEPATH.'libraries/Model'.EXT); + } + + require_once(APPPATH.'models/'.$path.$model.EXT); + + $model = ucfirst($model); + + $CI->$name = new $model(); + $CI->$name->_assign_libraries(); + + $this->_ci_models[] = $name; + } + + // -------------------------------------------------------------------- + + /** + * Database Loader + * + * @access public + * @param string the DB credentials + * @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 = FALSE) + { + // Do we even need to load the database class? + if (class_exists('CI_DB') AND $return == FALSE AND $active_record == FALSE) + { + return FALSE; + } + + require_once(BASEPATH.'database/DB'.EXT); + + if ($return === TRUE) + { + return DB($params, $active_record); + } + + // Grab the super object + $CI =& get_instance(); + + // Initialize the db variable. Needed to prevent + // reference errors with some configurations + $CI->db = ''; + + // Load the DB class + $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 + */ + function dbutil() + { + if ( ! class_exists('CI_DB')) + { + $this->database(); + } + + $CI =& get_instance(); + + 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'; + + $CI->dbutil = new $class(); + $CI->load->_ci_assign_to_models(); + } + + // -------------------------------------------------------------------- + + /** + * Load View + * + * This function is used to load a "view" file. It has three parameters: + * + * 1. The name of the "view" file to be included. + * 2. An associative array of data to be extracted for use in the view. + * 3. TRUE/FALSE - whether to return the data or load it. In + * some cases it's advantageous to be able to return data so that + * a developer can process it in some way. + * + * @access public + * @param string + * @param array + * @param bool + * @return void + */ + function view($view, $vars = array(), $return = FALSE) + { + return $this->_ci_load(array('view' => $view, 'vars' => $this->_ci_object_to_array($vars), 'return' => $return)); + } + + // -------------------------------------------------------------------- + + /** + * Load File + * + * This is a generic file loader + * + * @access public + * @param string + * @param bool + * @return string + */ + function file($path, $return = FALSE) + { + return $this->_ci_load(array('path' => $path, 'return' => $return)); + } + + // -------------------------------------------------------------------- + + /** + * Set Variables + * + * Once variables are set they become available within + * the controller class and its "view" files. + * + * @access public + * @param array + * @return void + */ + function vars($vars = array()) + { + $vars = $this->_ci_object_to_array($vars); + + if (is_array($vars) AND count($vars) > 0) + { + foreach ($vars as $key => $val) + { + $this->_ci_cached_vars[$key] = $val; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Load Helper + * + * This function loads the specified helper file. + * + * @access public + * @param mixed + * @return void + */ + function helper($helpers = array()) + { + if ( ! is_array($helpers)) + { + $helpers = array($helpers); + } + + foreach ($helpers as $helper) + { + $helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper'); + + if (isset($this->_ci_helpers[$helper])) + { + continue; + } + + if (file_exists(APPPATH.'helpers/'.$helper.EXT)) + { + include_once(APPPATH.'helpers/'.$helper.EXT); + } + else + { + if (file_exists(BASEPATH.'helpers/'.$helper.EXT)) + { + include(BASEPATH.'helpers/'.$helper.EXT); + } + else + { + show_error('Unable to load the requested file: helpers/'.$helper.EXT); + } + } + + $this->_ci_helpers[$helper] = TRUE; + + } + + log_message('debug', 'Helpers loaded: '.implode(', ', $helpers)); + } + + // -------------------------------------------------------------------- + + /** + * Load Helpers + * + * This is simply an alias to the above function in case the + * user has written the plural form of this function. + * + * @access public + * @param array + * @return void + */ + function helpers($helpers = array()) + { + $this->helper($helpers); + } + + // -------------------------------------------------------------------- + + /** + * Load Plugin + * + * This function loads the specified plugin. + * + * @access public + * @param array + * @return void + */ + function plugin($plugins = array()) + { + if ( ! is_array($plugins)) + { + $plugins = array($plugins); + } + + foreach ($plugins as $plugin) + { + $plugin = strtolower(str_replace(EXT, '', str_replace('_plugin.', '', $plugin)).'_pi'); + + if (isset($this->_ci_plugins[$plugin])) + { + continue; + } + + if (file_exists(APPPATH.'plugins/'.$plugin.EXT)) + { + include(APPPATH.'plugins/'.$plugin.EXT); + } + else + { + if (file_exists(BASEPATH.'plugins/'.$plugin.EXT)) + { + include(BASEPATH.'plugins/'.$plugin.EXT); + } + else + { + show_error('Unable to load the requested file: plugins/'.$plugin.EXT); + } + } + + $this->_ci_plugins[$plugin] = TRUE; + } + + log_message('debug', 'Plugins loaded: '.implode(', ', $plugins)); + } + + // -------------------------------------------------------------------- + + /** + * Load Plugins + * + * This is simply an alias to the above function in case the + * user has written the plural form of this function. + * + * @access public + * @param array + * @return void + */ + function plugins($plugins = array()) + { + $this->plugin($plugins); + } + + // -------------------------------------------------------------------- + + /** + * Load Script + * + * This function loads the specified include file from the + * application/scripts/ folder. + * + * NOTE: This feature has been deprecated but it will remain available + * for legacy users. + * + * @access public + * @param array + * @return void + */ + function script($scripts = array()) + { + if ( ! is_array($scripts)) + { + $scripts = array($scripts); + } + + foreach ($scripts as $script) + { + $script = strtolower(str_replace(EXT, '', $script)); + + if (isset($this->_ci_scripts[$script])) + { + continue; + } + + if ( ! file_exists(APPPATH.'scripts/'.$script.EXT)) + { + show_error('Unable to load the requested script: scripts/'.$script.EXT); + } + + include(APPPATH.'scripts/'.$script.EXT); + } + + log_message('debug', 'Scripts loaded: '.implode(', ', $scripts)); + } + + // -------------------------------------------------------------------- + + /** + * Loads a language file + * + * @access public + * @param string + * @return void + */ + function language($file = '', $lang = '', $return = FALSE) + { + $CI =& get_instance(); + return $CI->lang->load($file, $lang, $return); + } + + // -------------------------------------------------------------------- + + /** + * Loads a config file + * + * @access public + * @param string + * @return void + */ + function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) + { + $CI =& get_instance(); + $CI->config->load($file, $use_sections, $fail_gracefully); + } + + // -------------------------------------------------------------------- + + /** + * Scaffolding Loader + * + * This initializing function works a bit different than the + * others. It doesn't load the class. Instead, it simply + * sets a flag indicating that scaffolding is allowed to be + * used. The actual scaffolding function below is + * called by the front controller based on whether the + * second segment of the URL matches the "secret" scaffolding + * word stored in the application/config/routes.php + * + * @access public + * @param string + * @return void + */ + function scaffolding($table = '') + { + if ($table === FALSE) + { + show_error('You must include the name of the table you would like access when you initialize scaffolding'); + } + + $CI =& get_instance(); + $CI->_ci_scaffolding = TRUE; + $CI->_ci_scaff_table = $table; + } + + // -------------------------------------------------------------------- + + /** + * Loader + * + * This function is used to load views and files. + * + * @access private + * @param array + * @return void + */ + function _ci_load($data) + { + // Set the default data variables + foreach (array('view', 'vars', 'path', 'return') as $val) + { + $$val = ( ! isset($data[$val])) ? FALSE : $data[$val]; + } + + // Set the path to the requested file + if ($path == '') + { + $ext = pathinfo($view, PATHINFO_EXTENSION); + $file = ($ext == '') ? $view.EXT : $view; + $path = $this->_ci_view_path.$file; + } + else + { + $x = explode('/', $path); + $file = end($x); + } + + if ( ! file_exists($path)) + { + show_error('Unable to load the requested file: '.$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 =& get_instance(); + foreach (get_object_vars($CI) as $key => $var) + { + if ( ! isset($this->$key)) + { + $this->$key =& $CI->$key; + } + } + } + + /* + * Extract and cache variables + * + * You can either set variables using the dedicated $this->load_vars() + * 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($vars)) + { + $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $vars); + } + extract($this->_ci_cached_vars); + + /* + * Buffer the output + * + * We buffer the output for two reasons: + * 1. Speed. You get a significant speed boost. + * 2. So that the final rendered template can be + * post-processed by the output class. Why do we + * need post processing? For one thing, in order to + * show the elapsed page load time. Unless we + * can intercept the content right before it's sent to + * 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(' $this->_ci_ob_level + 1) + { + ob_end_flush(); + } + else + { + // PHP 4 requires that we use a global + global $OUT; + $OUT->set_output(ob_get_contents()); + @ob_end_clean(); + } + } + + // -------------------------------------------------------------------- + + /** + * Load class + * + * This function loads the requested class. + * + * @access private + * @param string the item that is being loaded + * @param mixed any additional parameters + * @return void + */ + function _ci_load_class($class, $params = NULL) + { + // Get the class name + $class = str_replace(EXT, '', $class); + + // We'll test for both lowercase and capitalized versions of the file name + foreach (array(ucfirst($class), strtolower($class)) as $class) + { + // Is this a class extension request? + if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT)) + { + if ( ! file_exists(BASEPATH.'libraries/'.ucfirst($class).EXT)) + { + log_message('error', "Unable to load the requested class: ".$class); + show_error("Unable to load the requested class: ".$class); + } + + include(BASEPATH.'libraries/'.ucfirst($class).EXT); + include(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT); + + return $this->_ci_init_class($class, config_item('subclass_prefix'), $params); + } + + // Lets search for the requested library file and load it. + for ($i = 1; $i < 3; $i++) + { + $path = ($i % 2) ? APPPATH : BASEPATH; + $fp = $path.'libraries/'.$class.EXT; + + // Does the file exist? No? Bummer... + if ( ! file_exists($fp)) + { + continue; + } + + // Safety: Was the class already loaded by a previous call? + if (in_array($fp, $this->_ci_classes)) + { + log_message('debug', $class." class already loaded. Second attempt ignored."); + return; + } + + include($fp); + $this->_ci_classes[] = $fp; + return $this->_ci_init_class($class, '', $params); + } + } // END FOREACH + + // If we got this far we were unable to find the requested class. + // We do not issue errors if the load call failed due to a duplicate request + if ($is_duplicate == FALSE) + { + log_message('error', "Unable to load the requested class: ".$class); + show_error("Unable to load the requested class: ".$class); + } + } + + // -------------------------------------------------------------------- + + /** + * Instantiates a class + * + * @access private + * @param string + * @param string + * @return null + */ + function _ci_init_class($class, $prefix = '', $config = FALSE) + { + // Is there an associated config file for this class? + if ($config === NULL) + { + $config = NULL; + if (file_exists(APPPATH.'config/'.$class.EXT)) + { + include(APPPATH.'config/'.$class.EXT); + } + } + + if ($prefix == '') + { + $name = (class_exists('CI_'.$class)) ? 'CI_'.$class : $class; + } + else + { + $name = $prefix.$class; + } + + // Set the variable name we will assign the class to + $class = strtolower($class); + $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; + + // Instantiate the class + $CI =& get_instance(); + if ($config !== NULL) + { + $CI->$classvar = new $name($config); + } + else + { + $CI->$classvar = new $name; + } + } + + // -------------------------------------------------------------------- + + /** + * Autoloader + * + * The config/autoload.php file contains an array that permits sub-systems, + * libraries, plugins, and helpers to be loaded automatically. + * + * @access private + * @param array + * @return void + */ + function _ci_autoloader() + { + include(APPPATH.'config/autoload'.EXT); + + if ( ! isset($autoload)) + { + return FALSE; + } + + // Load any custome config file + if (count($autoload['config']) > 0) + { + $CI =& get_instance(); + foreach ($autoload['config'] as $key => $val) + { + $CI->config->load($val); + } + } + + // Load plugins, helpers, and scripts + foreach (array('helper', 'plugin', 'script') as $type) + { + if (isset($autoload[$type]) AND count($autoload[$type]) > 0) + { + $this->$type($autoload[$type]); + } + } + + // A little tweak to remain backward compatible + // The $autoload['core'] item was deprecated + if ( ! isset($autoload['libraries'])) + { + $autoload['libraries'] = $autoload['core']; + } + + // Load libraries + if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0) + { + // Load the database driver. + if (in_array('database', $autoload['libraries'])) + { + $this->database(); + $autoload['libraries'] = array_diff($autoload['libraries'], array('database')); + } + + // Load the model class. + if (in_array('model', $autoload['libraries'])) + { + $this->model(); + $autoload['libraries'] = array_diff($autoload['libraries'], array('model')); + } + + // Load scaffolding + if (in_array('scaffolding', $autoload['libraries'])) + { + $this->scaffolding(); + $autoload['libraries'] = array_diff($autoload['libraries'], array('scaffolding')); + } + + // Load all other libraries + foreach ($autoload['libraries'] as $item) + { + $this->library($item); + } + } + } + + // -------------------------------------------------------------------- + + /** + * Assign to Models + * + * Makes sure that anything loaded by the loader class (libraries, plugins, etc.) + * will be available to models, if any exist. + * + * @access private + * @param object + * @return array + */ + function _ci_assign_to_models() + { + if (count($this->_ci_models) == 0) + { + return; + } + + if ($this->_ci_is_instance()) + { + $CI =& get_instance(); + foreach ($this->_ci_models as $model) + { + $CI->$model->_assign_libraries(); + } + } + else + { + foreach ($this->_ci_models as $model) + { + $this->$model->_assign_libraries(); + } + } + } + + // -------------------------------------------------------------------- + + /** + * Object to Array + * + * Takes an object as input and converts the class variables to array key/vals + * + * @access private + * @param object + * @return array + */ + function _ci_object_to_array($object) + { + return (is_object($object)) ? get_object_vars($object) : $object; + } + + // -------------------------------------------------------------------- + + /** + * Determines whether we should use the CI instance or $this + * + * @access private + * @return bool + */ + function _ci_is_instance() + { + if ($this->_ci_is_php5 == TRUE) + { + return TRUE; + } + + global $CI; + return (is_object($CI)) ? TRUE : FALSE; + } + +} ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 655bc02b4992d0ed764363f8181459d6390be24b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 6 Feb 2007 23:45:33 +0000 Subject: fixed grammer error in show_error message --- system/libraries/Loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index d11630712..aede38d7a 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -526,7 +526,7 @@ class CI_Loader { { if ($table === FALSE) { - show_error('You must include the name of the table you would like access when you initialize scaffolding'); + show_error('You must include the name of the table you would like to access when you initialize scaffolding'); } $CI =& get_instance(); -- cgit v1.2.3-24-g4f1b From 4dde0de7576872c075171c75363dfad7e5528952 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 14 Feb 2007 22:44:36 +0000 Subject: fixed an undefined var --- system/libraries/Loader.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index aede38d7a..e634c3885 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -697,6 +697,7 @@ class CI_Loader { } // Lets search for the requested library file and load it. + $is_duplicate = FALSE; for ($i = 1; $i < 3; $i++) { $path = ($i % 2) ? APPPATH : BASEPATH; @@ -711,6 +712,7 @@ class CI_Loader { // Safety: Was the class already loaded by a previous call? if (in_array($fp, $this->_ci_classes)) { + $is_duplicate = TRUE; log_message('debug', $class." class already loaded. Second attempt ignored."); return; } -- cgit v1.2.3-24-g4f1b From a8b10bed6b1064548b8af605e5b16113b457de02 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 15 Feb 2007 18:20:05 +0000 Subject: allow for extending models --- system/libraries/Loader.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index e634c3885..8438cc0bb 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -154,10 +154,7 @@ class CI_Loader { $CI->load->database($db_conn, FALSE, TRUE); } - if ( ! class_exists('Model')) - { - require_once(BASEPATH.'libraries/Model'.EXT); - } + load_class('Model', false); require_once(APPPATH.'models/'.$path.$model.EXT); -- cgit v1.2.3-24-g4f1b From ac0eb4543ce713d0d25125614489de3b8b2fd296 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 15 Feb 2007 18:42:22 +0000 Subject: reverted a change user testing revealed a flaw. --- system/libraries/Loader.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 8438cc0bb..e634c3885 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -154,7 +154,10 @@ class CI_Loader { $CI->load->database($db_conn, FALSE, TRUE); } - load_class('Model', false); + if ( ! class_exists('Model')) + { + require_once(BASEPATH.'libraries/Model'.EXT); + } require_once(APPPATH.'models/'.$path.$model.EXT); -- cgit v1.2.3-24-g4f1b From 112569db87d01a04b98eb6c37d9c9ced03b52f3f Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 26 Feb 2007 19:19:08 +0000 Subject: --- system/libraries/Input.php | 74 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index f346cabaa..0d41b0a99 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -91,6 +91,16 @@ class CI_Input { { $_GET = array(); } + else + { + if (is_array($_GET) AND count($_GET) > 0) + { + foreach($_GET as $key => $val) + { + $_GET[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); + } + } + } // Clean $_POST Data if (is_array($_POST) AND count($_POST) > 0) @@ -173,6 +183,41 @@ class CI_Input { return $str; } + + // -------------------------------------------------------------------- + + /** + * Fetch an item from the GET array + * + * @access public + * @param string + * @param bool + * @return string + */ + function post($index = '', $xss_clean = FALSE) + { + if ( ! isset($_GET[$index])) + { + return FALSE; + } + + if ($xss_clean === TRUE) + { + if (is_array($_GET[$index])) + { + foreach($_GET[$index] as $key => $val) + { + $_GET[$index][$key] = $this->xss_clean($val); + } + } + else + { + return $this->xss_clean($_GET[$index]); + } + } + + return $_GET[$index]; + } // -------------------------------------------------------------------- @@ -337,7 +382,34 @@ class CI_Input { */ function valid_ip($ip) { - return ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) ? FALSE : TRUE; + if ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) + { + return FALSE; + } + + $octets = explode('.', $ip); + + for ($i = 1; $i <= 4; $i++) + { + $octet = intval($octets[($i-1)]); + if ($i === 1) + { + if ($octet > 223 OR $octet < 1) + return FALSE; + } + elseif ($i === 4) + { + if ($octet < 1) + return FALSE; + } + else + { + if ($octet > 254) + return FALSE; + } + } + + return TRUE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 87d1eeb9e1f5678c78e06c3a685fb3aa1a88ece3 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 1 Mar 2007 13:20:43 +0000 Subject: function post() duplicated, changed the second to function get() --- system/libraries/Input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 0d41b0a99..3a35f498a 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -194,7 +194,7 @@ class CI_Input { * @param bool * @return string */ - function post($index = '', $xss_clean = FALSE) + function get($index = '', $xss_clean = FALSE) { if ( ! isset($_GET[$index])) { -- cgit v1.2.3-24-g4f1b From c2f90e23b62c7155a49e38a2958796e6a886e868 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 3 Apr 2007 11:17:44 +0000 Subject: array to string addition http://codeigniter.com/forums/viewthread/46994/ --- system/libraries/Profiler.php | 414 +++++++++++++++++++++--------------------- 1 file changed, 212 insertions(+), 202 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 5b0f6e2b7..37b345184 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -1,203 +1,213 @@ -CI =& get_instance(); - $this->CI->load->language('profiler'); - } - - // -------------------------------------------------------------------- - - /** - * Auto Profiler - * - * This function cycles through the entire array of mark points and - * matches any two points that are named identically (ending in "_start" - * and "_end" respectively). It then compiles the execution times for - * all points and returns it as an array - * - * @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); - } - } - } - - // 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 .= '
'; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_benchmarks').'  '; - $output .= "\n"; - $output .= "\n\n\n"; - - foreach ($profile as $key => $val) - { - $key = ucwords(str_replace(array('_', '-'), ' ', $key)); - $output .= "\n"; - } - - $output .= "
".$key."  ".$val."
\n"; - $output .= "
"; - - return $output; - } - - // -------------------------------------------------------------------- - - /** - * Compile Queries - * - * @access private - * @return string - */ - function _compile_queries() - { - $output = "\n\n"; - $output .= '
'; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; - $output .= "\n"; - - if ( ! class_exists('CI_DB_driver')) - { - $output .= "
".$this->CI->lang->line('profiler_no_db')."
"; - } - else - { - if (count($this->CI->db->queries) == 0) - { - $output .= "
".$this->CI->lang->line('profiler_no_queries')."
"; - } - else - { - foreach ($this->CI->db->queries as $val) - { - $output .= '
'; - $output .= $val; - $output .= "
\n"; - } - } - } - - $output .= "
"; - - return $output; - } - - // -------------------------------------------------------------------- - - /** - * Compile $_POST Data - * - * @access private - * @return string - */ - function _compile_post() - { - $output = "\n\n"; - $output .= '
'; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_post_data').'  '; - $output .= "\n"; - - if (count($_POST) == 0) - { - $output .= "
".$this->CI->lang->line('profiler_no_post')."
"; - } - else - { - $output .= "\n\n\n"; - - foreach ($_POST as $key => $val) - { - if ( ! is_numeric($key)) - { - $key = "'".$key."'"; - } - - $output .= "\n"; - } - - $output .= "
$_POST[".$key."]  ".htmlspecialchars(stripslashes($val))."
\n"; - } - $output .= "
"; - - return $output; - } - - // -------------------------------------------------------------------- - - /** - * Run the Profiler - * - * @access private - * @return string - */ - function run($output = '') - { - $output = '
'; - $output .= "
"; - - $output .= $this->_compile_benchmarks(); - $output .= $this->_compile_post(); - $output .= $this->_compile_queries(); - - $output .= '
'; - - return $output; - } - -} - -// END CI_Profiler class +CI =& get_instance(); + $this->CI->load->language('profiler'); + } + + // -------------------------------------------------------------------- + + /** + * Auto Profiler + * + * This function cycles through the entire array of mark points and + * matches any two points that are named identically (ending in "_start" + * and "_end" respectively). It then compiles the execution times for + * all points and returns it as an array + * + * @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); + } + } + } + + // 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 .= '
'; + $output .= "\n"; + $output .= '  '.$this->CI->lang->line('profiler_benchmarks').'  '; + $output .= "\n"; + $output .= "\n\n\n"; + + foreach ($profile as $key => $val) + { + $key = ucwords(str_replace(array('_', '-'), ' ', $key)); + $output .= "\n"; + } + + $output .= "
".$key."  ".$val."
\n"; + $output .= "
"; + + return $output; + } + + // -------------------------------------------------------------------- + + /** + * Compile Queries + * + * @access private + * @return string + */ + function _compile_queries() + { + $output = "\n\n"; + $output .= '
'; + $output .= "\n"; + $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; + $output .= "\n"; + + if ( ! class_exists('CI_DB_driver')) + { + $output .= "
".$this->CI->lang->line('profiler_no_db')."
"; + } + else + { + if (count($this->CI->db->queries) == 0) + { + $output .= "
".$this->CI->lang->line('profiler_no_queries')."
"; + } + else + { + foreach ($this->CI->db->queries as $val) + { + $output .= '
'; + $output .= $val; + $output .= "
\n"; + } + } + } + + $output .= "
"; + + return $output; + } + + // -------------------------------------------------------------------- + + /** + * Compile $_POST Data + * + * @access private + * @return string + */ + function _compile_post() + { + $output = "\n\n"; + $output .= '
'; + $output .= "\n"; + $output .= '  '.$this->CI->lang->line('profiler_post_data').'  '; + $output .= "\n"; + + if (count($_POST) == 0) + { + $output .= "
".$this->CI->lang->line('profiler_no_post')."
"; + } + else + { + $output .= "\n\n\n"; + + foreach ($_POST as $key => $val) + { + if ( ! is_numeric($key)) + { + $key = "'".$key."'"; + } + +// $output .= "\n"; + $output .= "\n"; + } + + $output .= "
$_POST[".$key."]  ".htmlspecialchars(stripslashes($val))."
$_POST[".$key."] "; + if (is_array($val)) + { + $output .= "
" . htmlspecialchars(stripslashes(print_r($val, true))) . "
"; + } + else + { + $output .= htmlspecialchars(stripslashes($val)); + } + $output .= "
\n"; + } + $output .= "
"; + + return $output; + } + + // -------------------------------------------------------------------- + + /** + * Run the Profiler + * + * @access private + * @return string + */ + function run($output = '') + { + $output = '
'; + $output .= "
"; + + $output .= $this->_compile_benchmarks(); + $output .= $this->_compile_post(); + $output .= $this->_compile_queries(); + + $output .= '
'; + + return $output; + } + +} + +// END CI_Profiler class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0e254f16f26387e8f8feb0668c1d06a5fe97fa99 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 10 Apr 2007 21:53:38 +0000 Subject: typo fix --- system/libraries/Table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index b8ce9491a..32223708e 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -286,7 +286,7 @@ class CI_Table { // -------------------------------------------------------------------- /** - * Clears the table arrays. Useful if multiple tables are beting generated + * Clears the table arrays. Useful if multiple tables are being generated * * @access public * @return void -- cgit v1.2.3-24-g4f1b From d2df9bc7cc9d4b3e53818470c5d0977c9a36677c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 15 Apr 2007 17:41:17 +0000 Subject: update pMachine to EllisLab update copyright year update Code Igniter to CodeIgniter --- system/libraries/Benchmark.php | 220 +-- system/libraries/Calendar.php | 948 +++++------ system/libraries/Config.php | 488 +++--- system/libraries/Controller.php | 228 +-- system/libraries/Email.php | 3436 +++++++++++++++++++-------------------- system/libraries/Encrypt.php | 792 ++++----- system/libraries/Exceptions.php | 4 +- system/libraries/Ftp.php | 1230 +++++++------- system/libraries/Hooks.php | 446 ++--- system/libraries/Image_lib.php | 4 +- system/libraries/Input.php | 4 +- system/libraries/Language.php | 240 +-- system/libraries/Loader.php | 4 +- system/libraries/Log.php | 234 +-- system/libraries/Model.php | 162 +- system/libraries/Output.php | 726 ++++----- system/libraries/Pagination.php | 420 ++--- system/libraries/Parser.php | 340 ++-- system/libraries/Profiler.php | 6 +- system/libraries/Router.php | 4 +- system/libraries/Session.php | 974 +++++------ system/libraries/Sha1.php | 496 +++--- system/libraries/Table.php | 4 +- system/libraries/Trackback.php | 1094 ++++++------- system/libraries/URI.php | 732 ++++----- system/libraries/Unit_test.php | 660 ++++---- system/libraries/Upload.php | 1616 +++++++++--------- system/libraries/User_agent.php | 4 +- system/libraries/Validation.php | 1468 ++++++++--------- system/libraries/Xmlrpc.php | 2822 ++++++++++++++++---------------- system/libraries/Xmlrpcs.php | 1004 ++++++------ system/libraries/Zip.php | 758 ++++----- 32 files changed, 10784 insertions(+), 10784 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index 66e8a24cf..cf980a81e 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -1,111 +1,111 @@ -marker[$name] = microtime(); - } - - // -------------------------------------------------------------------- - - /** - * Calculates the time difference between two marked points. - * - * If the first parameter is empty this function instead returns the - * {elapsed_time} pseudo-variable. This permits the full system - * execution time to be shown in a template. The output class will - * swap the real value for this variable. - * - * @access public - * @param string a particular marked point - * @param string a particular marked point - * @param integer the number of decimal places - * @return mixed - */ - function elapsed_time($point1 = '', $point2 = '', $decimals = 4) - { - if ($point1 == '') - { - return '{elapsed_time}'; - } - - if ( ! isset($this->marker[$point1])) - { - return ''; - } - - if ( ! isset($this->marker[$point2])) - { - $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); - } - - // -------------------------------------------------------------------- - - /** - * Memory Usage - * - * This function returns the {memory_usage} pseudo-variable. - * This permits it to be put it anywhere in a template - * without the memory being calculated until the end. - * The output class will swap the real value for this variable. - * - * @access public - * @return string - */ - function memory_usage() - { - return '{memory_usage}'; - } - -} - -// END CI_Benchmark class +marker[$name] = microtime(); + } + + // -------------------------------------------------------------------- + + /** + * Calculates the time difference between two marked points. + * + * If the first parameter is empty this function instead returns the + * {elapsed_time} pseudo-variable. This permits the full system + * execution time to be shown in a template. The output class will + * swap the real value for this variable. + * + * @access public + * @param string a particular marked point + * @param string a particular marked point + * @param integer the number of decimal places + * @return mixed + */ + function elapsed_time($point1 = '', $point2 = '', $decimals = 4) + { + if ($point1 == '') + { + return '{elapsed_time}'; + } + + if ( ! isset($this->marker[$point1])) + { + return ''; + } + + if ( ! isset($this->marker[$point2])) + { + $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); + } + + // -------------------------------------------------------------------- + + /** + * Memory Usage + * + * This function returns the {memory_usage} pseudo-variable. + * This permits it to be put it anywhere in a template + * without the memory being calculated until the end. + * The output class will swap the real value for this variable. + * + * @access public + * @return string + */ + function memory_usage() + { + return '{memory_usage}'; + } + +} + +// END CI_Benchmark class ?> \ No newline at end of file diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index fdef5dd75..ef6a3f841 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -1,475 +1,475 @@ -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 - * - * Accepts an associative array as input, containing display preferences - * - * @access public - * @param array config preferences - * @return void - */ - function initialize($config = array()) - { - foreach ($config as $key => $val) - { - if (isset($this->$key)) - { - $this->$key = $val; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Generate the calendar - * - * @access public - * @param integer the year - * @param integer the month - * @param array the data to be shown in the calendar cells - * @return string - */ - function generate($year = '', $month = '', $data = array()) - { - // 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) - $year = '200'.$year; - - if (strlen($year) == 2) - $year = '20'.$year; - - 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 - $out = $this->temp['table_open']; - $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"; - } - - // 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 .= $this->temp['heading_row_end']; - $out .= "\n"; - - // Write the cells containing the days of the week - $out .= "\n"; - $out .= $this->temp['week_row_start']; - $out .= "\n"; - - $day_names = $this->get_day_names(); - - for ($i = 0; $i < 7; $i ++) - { - $out .= str_replace('{week_day}', $day_names[($start_day + $i) %7], $this->temp['week_day_cell']); - } - - $out .= "\n"; - $out .= $this->temp['week_row_end']; - $out .= "\n"; - - // Build the main body of the calendar - while ($day <= $total_days) - { - $out .= "\n"; - $out .= $this->temp['cal_row_start']; - $out .= "\n"; - - 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)); - } - else - { - // Cells with no content - $temp = ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_no_content_today'] : $this->temp['cal_cell_no_content']; - $out .= str_replace('{day}', $day, $temp); - } - } - else - { - // 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']; - $day++; - } - - $out .= "\n"; - $out .= $this->temp['cal_row_end']; - $out .= "\n"; - } - - $out .= "\n"; - $out .= $this->temp['table_close']; - - return $out; - } - - // -------------------------------------------------------------------- - - /** - * Get Month Name - * - * Generates a textual month name based on the numeric - * month provided. - * - * @access public - * @param integer the month - * @return string - */ - function get_month_name($month) - { - if ($this->month_type == 'short') - { - $month_names = array('01' => 'cal_jan', '02' => 'cal_feb', '03' => 'cal_mar', '04' => 'cal_apr', '05' => 'cal_may', '06' => 'cal_jun', '07' => 'cal_jul', '08' => 'cal_aug', '09' => 'cal_sep', '10' => 'cal_oct', '11' => 'cal_nov', '12' => 'cal_dec'); - } - else - { - $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)); - } - - return $this->CI->lang->line($month); - } - - // -------------------------------------------------------------------- - - /** - * Get Day Names - * - * Returns an array of day names (Sunday, Monday, etc.) based - * on the type. Options: long, short, abrev - * - * @access public - * @param string - * @return array - */ - function get_day_names($day_type = '') - { - if ($day_type != '') - $this->day_type = $day_type; - - if ($this->day_type == 'long') - { - $day_names = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'); - } - elseif ($this->day_type == 'short') - { - $day_names = array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'); - } - else - { - $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; - } - - // -------------------------------------------------------------------- - - /** - * Adjust Date - * - * This function makes sure that we have a valid month/year. - * For example, if you submit 13 as the month, the year will - * increment and the month will become January. - * - * @access public - * @param integer the month - * @param integer the year - * @return array - */ - function adjust_date($month, $year) - { - $date = array(); - - $date['month'] = $month; - $date['year'] = $year; - - while ($date['month'] > 12) - { - $date['month'] -= 12; - $date['year']++; - } - - while ($date['month'] <= 0) - { - $date['month'] += 12; - $date['year']--; - } - - if (strlen($date['month']) == 1) - { - $date['month'] = '0'.$date['month']; - } - - return $date; - } - - // -------------------------------------------------------------------- - - /** - * Total days in a given month - * - * @access public - * @param integer the month - * @param integer the year - * @return integer - */ - function get_total_days($month, $year) - { - $days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); - - if ($month < 1 OR $month > 12) - { - return 0; - } - - // Is the year a leap year? - if ($month == 2) - { - if ($year % 400 == 0 OR ($year % 4 == 0 AND $year % 100 != 0)) - { - return 29; - } - } - - return $days_in_month[$month - 1]; - } - - // -------------------------------------------------------------------- - - /** - * Set Default Template Data - * - * This is used in the event that the user has not created their own template - * - * @access public - * @return array - */ - function default_template() - { - return array ( - 'table_open' => '', - '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_end_today' => '', - 'cal_row_end' => '', - 'table_close' => '
<<{heading}>>
{week_day}
', - 'cal_cell_start_today' => '', - 'cal_cell_content' => '{day}', - 'cal_cell_content_today' => '{day}', - 'cal_cell_no_content' => '{day}', - 'cal_cell_no_content_today' => '{day}', - 'cal_cell_blank' => ' ', - 'cal_cell_end' => '
' - ); - } - - // -------------------------------------------------------------------- - - /** - * Parse Template - * - * Harvests the data within the template {pseudo-variables} - * used to display the calendar - * - * @access public - * @return void - */ - function parse_template() - { - $this->temp = $this->default_template(); - - 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)) - { - $this->temp[$val] = $match['1']; - } - else - { - if (in_array($val, $today, TRUE)) - { - $this->temp[$val] = $this->temp[str_replace('_today', '', $val)]; - } - } - } - } - -} - -// END CI_Calendar class +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 + * + * Accepts an associative array as input, containing display preferences + * + * @access public + * @param array config preferences + * @return void + */ + function initialize($config = array()) + { + foreach ($config as $key => $val) + { + if (isset($this->$key)) + { + $this->$key = $val; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Generate the calendar + * + * @access public + * @param integer the year + * @param integer the month + * @param array the data to be shown in the calendar cells + * @return string + */ + function generate($year = '', $month = '', $data = array()) + { + // 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) + $year = '200'.$year; + + if (strlen($year) == 2) + $year = '20'.$year; + + 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 + $out = $this->temp['table_open']; + $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"; + } + + // 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 .= $this->temp['heading_row_end']; + $out .= "\n"; + + // Write the cells containing the days of the week + $out .= "\n"; + $out .= $this->temp['week_row_start']; + $out .= "\n"; + + $day_names = $this->get_day_names(); + + for ($i = 0; $i < 7; $i ++) + { + $out .= str_replace('{week_day}', $day_names[($start_day + $i) %7], $this->temp['week_day_cell']); + } + + $out .= "\n"; + $out .= $this->temp['week_row_end']; + $out .= "\n"; + + // Build the main body of the calendar + while ($day <= $total_days) + { + $out .= "\n"; + $out .= $this->temp['cal_row_start']; + $out .= "\n"; + + 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)); + } + else + { + // Cells with no content + $temp = ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_no_content_today'] : $this->temp['cal_cell_no_content']; + $out .= str_replace('{day}', $day, $temp); + } + } + else + { + // 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']; + $day++; + } + + $out .= "\n"; + $out .= $this->temp['cal_row_end']; + $out .= "\n"; + } + + $out .= "\n"; + $out .= $this->temp['table_close']; + + return $out; + } + + // -------------------------------------------------------------------- + + /** + * Get Month Name + * + * Generates a textual month name based on the numeric + * month provided. + * + * @access public + * @param integer the month + * @return string + */ + function get_month_name($month) + { + if ($this->month_type == 'short') + { + $month_names = array('01' => 'cal_jan', '02' => 'cal_feb', '03' => 'cal_mar', '04' => 'cal_apr', '05' => 'cal_may', '06' => 'cal_jun', '07' => 'cal_jul', '08' => 'cal_aug', '09' => 'cal_sep', '10' => 'cal_oct', '11' => 'cal_nov', '12' => 'cal_dec'); + } + else + { + $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)); + } + + return $this->CI->lang->line($month); + } + + // -------------------------------------------------------------------- + + /** + * Get Day Names + * + * Returns an array of day names (Sunday, Monday, etc.) based + * on the type. Options: long, short, abrev + * + * @access public + * @param string + * @return array + */ + function get_day_names($day_type = '') + { + if ($day_type != '') + $this->day_type = $day_type; + + if ($this->day_type == 'long') + { + $day_names = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'); + } + elseif ($this->day_type == 'short') + { + $day_names = array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'); + } + else + { + $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; + } + + // -------------------------------------------------------------------- + + /** + * Adjust Date + * + * This function makes sure that we have a valid month/year. + * For example, if you submit 13 as the month, the year will + * increment and the month will become January. + * + * @access public + * @param integer the month + * @param integer the year + * @return array + */ + function adjust_date($month, $year) + { + $date = array(); + + $date['month'] = $month; + $date['year'] = $year; + + while ($date['month'] > 12) + { + $date['month'] -= 12; + $date['year']++; + } + + while ($date['month'] <= 0) + { + $date['month'] += 12; + $date['year']--; + } + + if (strlen($date['month']) == 1) + { + $date['month'] = '0'.$date['month']; + } + + return $date; + } + + // -------------------------------------------------------------------- + + /** + * Total days in a given month + * + * @access public + * @param integer the month + * @param integer the year + * @return integer + */ + function get_total_days($month, $year) + { + $days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); + + if ($month < 1 OR $month > 12) + { + return 0; + } + + // Is the year a leap year? + if ($month == 2) + { + if ($year % 400 == 0 OR ($year % 4 == 0 AND $year % 100 != 0)) + { + return 29; + } + } + + return $days_in_month[$month - 1]; + } + + // -------------------------------------------------------------------- + + /** + * Set Default Template Data + * + * This is used in the event that the user has not created their own template + * + * @access public + * @return array + */ + function default_template() + { + return array ( + 'table_open' => '', + '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_end_today' => '', + 'cal_row_end' => '', + 'table_close' => '
<<{heading}>>
{week_day}
', + 'cal_cell_start_today' => '', + 'cal_cell_content' => '{day}', + 'cal_cell_content_today' => '{day}', + 'cal_cell_no_content' => '{day}', + 'cal_cell_no_content_today' => '{day}', + 'cal_cell_blank' => ' ', + 'cal_cell_end' => '
' + ); + } + + // -------------------------------------------------------------------- + + /** + * Parse Template + * + * Harvests the data within the template {pseudo-variables} + * used to display the calendar + * + * @access public + * @return void + */ + function parse_template() + { + $this->temp = $this->default_template(); + + 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)) + { + $this->temp[$val] = $match['1']; + } + else + { + if (in_array($val, $today, TRUE)) + { + $this->temp[$val] = $this->temp[str_replace('_today', '', $val)]; + } + } + } + } + +} + +// END CI_Calendar class ?> \ No newline at end of file diff --git a/system/libraries/Config.php b/system/libraries/Config.php index 28409fbc4..831ba925d 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -1,245 +1,245 @@ -config =& get_config(); - log_message('debug', "Config Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Load Config File - * - * @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); - - if (in_array($file, $this->is_loaded, TRUE)) - { - return TRUE; - } - - if ( ! file_exists(APPPATH.'config/'.$file.EXT)) - { - if ($fail_gracefully === TRUE) - { - return FALSE; - } - show_error('The configuration file '.$file.EXT.' does not exist.'); - } - - include(APPPATH.'config/'.$file.EXT); - - if ( ! isset($config) OR ! is_array($config)) - { - if ($fail_gracefully === TRUE) - { - return FALSE; - } - show_error('Your '.$file.EXT.' file does not appear to contain a valid configuration array.'); - } - - if ($use_sections === TRUE) - { - if (isset($this->config[$file])) - { - $this->config[$file] = array_merge($this->config[$file], $config); - } - else - { - $this->config[$file] = $config; - } - } - else - { - $this->config = array_merge($this->config, $config); - } - - $this->is_loaded[] = $file; - unset($config); - - log_message('debug', 'Config file loaded: config/'.$file.EXT); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Fetch a config file item - * - * - * @access public - * @param string the config item name - * @param string the index name - * @param bool - * @return string - */ - function item($item, $index = '') - { - if ($index == '') - { - if ( ! isset($this->config[$item])) - { - return FALSE; - } - - $pref = $this->config[$item]; - } - else - { - if ( ! isset($this->config[$index])) - { - return FALSE; - } - - if ( ! isset($this->config[$index][$item])) - { - return FALSE; - } - - $pref = $this->config[$index][$item]; - } - - return $pref; - } - - // -------------------------------------------------------------------- - - /** - * Fetch a config file item - adds slash after item - * - * The second parameter allows a slash to be added to the end of - * the item, in the case of a path. - * - * @access public - * @param string the config item name - * @param bool - * @return string - */ - function slash_item($item) - { - if ( ! isset($this->config[$item])) - { - return FALSE; - } - - $pref = $this->config[$item]; - - if ($pref != '') - { - if (ereg("/$", $pref) === FALSE) - { - $pref .= '/'; - } - } - - return $pref; - } - - // -------------------------------------------------------------------- - - /** - * Site URL - * - * @access public - * @param string the URI string - * @return string - */ - function site_url($uri = '') - { - if (is_array($uri)) - { - $uri = implode('/', $uri); - } - - if ($uri == '') - { - return $this->slash_item('base_url').$this->item('index_page'); - } - else - { - $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix'); - return $this->slash_item('base_url').$this->slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix; - } - } - - // -------------------------------------------------------------------- - - /** - * System URL - * - * @access public - * @return string - */ - function system_url() - { - $x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH)); - return $this->slash_item('base_url').end($x).'/'; - } - - // -------------------------------------------------------------------- - - /** - * Set a config file item - * - * @access public - * @param string the config item key - * @param string the config item value - * @return void - */ - function set_item($item, $value) - { - $this->config[$item] = $value; - } - -} - -// END CI_Config class +config =& get_config(); + log_message('debug', "Config Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Load Config File + * + * @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); + + if (in_array($file, $this->is_loaded, TRUE)) + { + return TRUE; + } + + if ( ! file_exists(APPPATH.'config/'.$file.EXT)) + { + if ($fail_gracefully === TRUE) + { + return FALSE; + } + show_error('The configuration file '.$file.EXT.' does not exist.'); + } + + include(APPPATH.'config/'.$file.EXT); + + if ( ! isset($config) OR ! is_array($config)) + { + if ($fail_gracefully === TRUE) + { + return FALSE; + } + show_error('Your '.$file.EXT.' file does not appear to contain a valid configuration array.'); + } + + if ($use_sections === TRUE) + { + if (isset($this->config[$file])) + { + $this->config[$file] = array_merge($this->config[$file], $config); + } + else + { + $this->config[$file] = $config; + } + } + else + { + $this->config = array_merge($this->config, $config); + } + + $this->is_loaded[] = $file; + unset($config); + + log_message('debug', 'Config file loaded: config/'.$file.EXT); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Fetch a config file item + * + * + * @access public + * @param string the config item name + * @param string the index name + * @param bool + * @return string + */ + function item($item, $index = '') + { + if ($index == '') + { + if ( ! isset($this->config[$item])) + { + return FALSE; + } + + $pref = $this->config[$item]; + } + else + { + if ( ! isset($this->config[$index])) + { + return FALSE; + } + + if ( ! isset($this->config[$index][$item])) + { + return FALSE; + } + + $pref = $this->config[$index][$item]; + } + + return $pref; + } + + // -------------------------------------------------------------------- + + /** + * Fetch a config file item - adds slash after item + * + * The second parameter allows a slash to be added to the end of + * the item, in the case of a path. + * + * @access public + * @param string the config item name + * @param bool + * @return string + */ + function slash_item($item) + { + if ( ! isset($this->config[$item])) + { + return FALSE; + } + + $pref = $this->config[$item]; + + if ($pref != '') + { + if (ereg("/$", $pref) === FALSE) + { + $pref .= '/'; + } + } + + return $pref; + } + + // -------------------------------------------------------------------- + + /** + * Site URL + * + * @access public + * @param string the URI string + * @return string + */ + function site_url($uri = '') + { + if (is_array($uri)) + { + $uri = implode('/', $uri); + } + + if ($uri == '') + { + return $this->slash_item('base_url').$this->item('index_page'); + } + else + { + $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix'); + return $this->slash_item('base_url').$this->slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix; + } + } + + // -------------------------------------------------------------------- + + /** + * System URL + * + * @access public + * @return string + */ + function system_url() + { + $x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH)); + return $this->slash_item('base_url').end($x).'/'; + } + + // -------------------------------------------------------------------- + + /** + * Set a config file item + * + * @access public + * @param string the config item key + * @param string the config item value + * @return void + */ + function set_item($item, $value) + { + $this->config[$item] = $value; + } + +} + +// END CI_Config class ?> \ No newline at end of file diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index c8fa646c7..81421cf31 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -1,115 +1,115 @@ -_ci_initialize(); - log_message('debug', "Controller Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize - * - * Assigns all the bases classes loaded by the front controller to - * variables in this class. Also calls the autoload routine. - * - * @access private - * @return void - */ - function _ci_initialize() - { - // Assign all the class objects that were instantiated by the - // front controller to local class variables so that CI can be - // run as one big super object. - $classes = array( - 'config' => 'Config', - 'input' => 'Input', - 'benchmark' => 'Benchmark', - 'uri' => 'URI', - 'output' => 'Output', - 'lang' => 'Language' - ); - - foreach ($classes as $var => $class) - { - $this->$var =& load_class($class); - } - - // In PHP 5 the Loader class is run as a discreet - // class. In PHP 4 it extends the Controller - if (floor(phpversion()) >= 5) - { - $this->load =& load_class('Loader'); - $this->load->_ci_autoloader(); - } - else - { - $this->_ci_autoloader(); - } - } - - // -------------------------------------------------------------------- - - /** - * Run Scaffolding - * - * @access private - * @return void - */ - function _ci_scaffolding() - { - if ($this->_ci_scaffolding === FALSE OR $this->_ci_scaff_table === FALSE) - { - show_404('Scaffolding unavailable'); - } - - $method = ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) ? 'view' : $this->uri->segment(3); - - require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); - $scaff = new Scaffolding($this->_ci_scaff_table); - $scaff->$method(); - } - - -} -// END _Controller class +_ci_initialize(); + log_message('debug', "Controller Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Initialize + * + * Assigns all the bases classes loaded by the front controller to + * variables in this class. Also calls the autoload routine. + * + * @access private + * @return void + */ + function _ci_initialize() + { + // Assign all the class objects that were instantiated by the + // front controller to local class variables so that CI can be + // run as one big super object. + $classes = array( + 'config' => 'Config', + 'input' => 'Input', + 'benchmark' => 'Benchmark', + 'uri' => 'URI', + 'output' => 'Output', + 'lang' => 'Language' + ); + + foreach ($classes as $var => $class) + { + $this->$var =& load_class($class); + } + + // In PHP 5 the Loader class is run as a discreet + // class. In PHP 4 it extends the Controller + if (floor(phpversion()) >= 5) + { + $this->load =& load_class('Loader'); + $this->load->_ci_autoloader(); + } + else + { + $this->_ci_autoloader(); + } + } + + // -------------------------------------------------------------------- + + /** + * Run Scaffolding + * + * @access private + * @return void + */ + function _ci_scaffolding() + { + if ($this->_ci_scaffolding === FALSE OR $this->_ci_scaff_table === FALSE) + { + show_404('Scaffolding unavailable'); + } + + $method = ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) ? 'view' : $this->uri->segment(3); + + require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); + $scaff = new Scaffolding($this->_ci_scaff_table); + $scaff->$method(); + } + + +} +// END _Controller class ?> \ No newline at end of file diff --git a/system/libraries/Email.php b/system/libraries/Email.php index e6dd614f4..a8acec674 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1,1719 +1,1719 @@ - 0) - { - $this->initialize($config); - } - - log_message('debug', "Email Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize preferences - * - * @access public - * @param array - * @return void - */ - function initialize($config = array()) - { - $this->clear(); - foreach ($config as $key => $val) - { - if (isset($this->$key)) - { - $method = 'set_'.$key; - - if (method_exists($this, $method)) - { - $this->$method($val); - } - else - { - $this->$key = $val; - } - } - } - $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; - $this->_safe_mode = (@ini_get("safe_mode") == 0) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Initialize the Email Data - * - * @access public - * @return void - */ - function clear($clear_attachments = FALSE) - { - $this->_subject = ""; - $this->_body = ""; - $this->_finalbody = ""; - $this->_header_str = ""; - $this->_replyto_flag = FALSE; - $this->_recipients = array(); - $this->_headers = array(); - $this->_debug_msg = array(); - - $this->_set_header('User-Agent', $this->useragent); - $this->_set_header('Date', $this->_set_date()); - - if ($clear_attachments !== FALSE) - { - $this->_attach_name = array(); - $this->_attach_type = array(); - $this->_attach_disp = array(); - } - } - - // -------------------------------------------------------------------- - - /** - * Set FROM - * - * @access public - * @param string - * @param string - * @return void - */ - function from($from, $name = '') - { - if (preg_match( '/\<(.*)\>/', $from, $match)) - $from = $match['1']; - - if ($this->validate) - $this->validate_email($this->_str_to_array($from)); - - if ($name != '' && substr($name, 0, 1) != '"') - { - $name = '"'.$name.'"'; - } - - $this->_set_header('From', $name.' <'.$from.'>'); - $this->_set_header('Return-Path', '<'.$from.'>'); - } - - // -------------------------------------------------------------------- - - /** - * Set Reply-to - * - * @access public - * @param string - * @param string - * @return void - */ - function reply_to($replyto, $name = '') - { - if (preg_match( '/\<(.*)\>/', $replyto, $match)) - $replyto = $match['1']; - - if ($this->validate) - $this->validate_email($this->_str_to_array($replyto)); - - if ($name == '') - { - $name = $replyto; - } - - if (substr($name, 0, 1) != '"') - { - $name = '"'.$name.'"'; - } - - $this->_set_header('Reply-To', $name.' <'.$replyto.'>'); - $this->_replyto_flag = TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set Recipients - * - * @access public - * @param string - * @return void - */ - function to($to) - { - $to = $this->_str_to_array($to); - $to = $this->clean_email($to); - - if ($this->validate) - $this->validate_email($to); - - if ($this->_get_protocol() != 'mail') - $this->_set_header('To', implode(", ", $to)); - - switch ($this->_get_protocol()) - { - case 'smtp' : $this->_recipients = $to; - break; - case 'sendmail' : $this->_recipients = implode(", ", $to); - break; - case 'mail' : $this->_recipients = implode(", ", $to); - break; - } - } - - // -------------------------------------------------------------------- - - /** - * Set CC - * - * @access public - * @param string - * @return void - */ - function cc($cc) - { - $cc = $this->_str_to_array($cc); - $cc = $this->clean_email($cc); - - if ($this->validate) - $this->validate_email($cc); - - $this->_set_header('Cc', implode(", ", $cc)); - - if ($this->_get_protocol() == "smtp") - $this->_cc_array = $cc; - } - - // -------------------------------------------------------------------- - - /** - * Set BCC - * - * @access public - * @param string - * @param string - * @return void - */ - function bcc($bcc, $limit = '') - { - if ($limit != '' && is_numeric($limit)) - { - $this->bcc_batch_mode = true; - $this->bcc_batch_size = $limit; - } - - $bcc = $this->_str_to_array($bcc); - $bcc = $this->clean_email($bcc); - - if ($this->validate) - $this->validate_email($bcc); - - if (($this->_get_protocol() == "smtp") OR ($this->bcc_batch_mode && count($bcc) > $this->bcc_batch_size)) - $this->_bcc_array = $bcc; - else - $this->_set_header('Bcc', implode(", ", $bcc)); - } - - // -------------------------------------------------------------------- - - /** - * Set Email Subject - * - * @access public - * @param string - * @return void - */ - function subject($subject) - { - $subject = preg_replace("/(\r\n)|(\r)|(\n)/", "", $subject); - $subject = preg_replace("/(\t)/", " ", $subject); - - $this->_set_header('Subject', trim($subject)); - } - - // -------------------------------------------------------------------- - - /** - * Set Body - * - * @access public - * @param string - * @return void - */ - function message($body) - { - $this->_body = stripslashes(rtrim(str_replace("\r", "", $body))); - } - - // -------------------------------------------------------------------- - - /** - * Assign file attachments - * - * @access public - * @param string - * @return string - */ - function attach($filename, $disposition = 'attachment') - { - $this->_attach_name[] = $filename; - $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename)))); - $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters - } - - // -------------------------------------------------------------------- - - /** - * Add a Header Item - * - * @access public - * @param string - * @param string - * @return void - */ - function _set_header($header, $value) - { - $this->_headers[$header] = $value; - } - - // -------------------------------------------------------------------- - - /** - * Convert a String to an Array - * - * @access public - * @param string - * @return array - */ - function _str_to_array($email) - { - if ( ! is_array($email)) - { - if (ereg(',$', $email)) - $email = substr($email, 0, -1); - - if (ereg('^,', $email)) - $email = substr($email, 1); - - if (ereg(',', $email)) - { - $x = explode(',', $email); - $email = array(); - - for ($i = 0; $i < count($x); $i ++) - $email[] = trim($x[$i]); - } - else - { - $email = trim($email); - settype($email, "array"); - } - } - return $email; - } - - // -------------------------------------------------------------------- - - /** - * Set Multipart Value - * - * @access public - * @param string - * @return void - */ - function set_alt_message($str = '') - { - $this->alt_message = ($str == '') ? '' : $str; - } - - // -------------------------------------------------------------------- - - /** - * Set Mailtype - * - * @access public - * @param string - * @return void - */ - function set_mailtype($type = 'text') - { - $this->mailtype = ($type == 'html') ? 'html' : 'text'; - } - - // -------------------------------------------------------------------- - - /** - * Set Wordwrap - * - * @access public - * @param string - * @return void - */ - function set_wordwrap($wordwrap = TRUE) - { - $this->wordwrap = ($wordwrap === FALSE) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set Protocol - * - * @access public - * @param string - * @return void - */ - function set_protocol($protocol = 'mail') - { - $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol); - } - - // -------------------------------------------------------------------- - - /** - * Set Priority - * - * @access public - * @param integer - * @return void - */ - function set_priority($n = 3) - { - if ( ! is_numeric($n)) - { - $this->priority = 3; - return; - } - - if ($n < 1 OR $n > 5) - { - $this->priority = 3; - return; - } - - $this->priority = $n; - } - - // -------------------------------------------------------------------- - - /** - * Set Newline Character - * - * @access public - * @param string - * @return void - */ - function set_newline($newline = "\n") - { - if ($newline != "\n" OR $newline != "\r\n" OR $newline != "\r") - { - $this->newline = "\n"; - return; - } - - $this->newline = $newline; - } - - // -------------------------------------------------------------------- - - /** - * Set Message Boundary - * - * @access private - * @return void - */ - function _set_boundaries() - { - $this->_alt_boundary = "B_ALT_".uniqid(''); // multipart/alternative - $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary - } - - // -------------------------------------------------------------------- - - /** - * Get the Message ID - * - * @access private - * @return string - */ - function _get_message_id() - { - $from = $this->_headers['Return-Path']; - $from = str_replace(">", "", $from); - $from = str_replace("<", "", $from); - - return "<".uniqid('').strstr($from, '@').">"; - } - - // -------------------------------------------------------------------- - - /** - * Get Mail Protocol - * - * @access private - * @param bool - * @return string - */ - function _get_protocol($return = true) - { - $this->protocol = strtolower($this->protocol); - $this->protocol = ( ! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol; - - if ($return == true) - return $this->protocol; - } - - // -------------------------------------------------------------------- - - /** - * Get Mail Encoding - * - * @access private - * @param bool - * @return string - */ - function _get_encoding($return = true) - { - $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '7bit' : $this->_encoding; - - if ( ! in_array($this->charset, $this->_base_charsets, TRUE)) - $this->_encoding = "8bit"; - - if ($return == true) - return $this->_encoding; - } - - // -------------------------------------------------------------------- - - /** - * Get content type (text/html/attachment) - * - * @access private - * @return string - */ - function _get_content_type() - { - if ($this->mailtype == 'html' && count($this->_attach_name) == 0) - return 'html'; - - elseif ($this->mailtype == 'html' && count($this->_attach_name) > 0) - return 'html-attach'; - - elseif ($this->mailtype == 'text' && count($this->_attach_name) > 0) - return 'plain-attach'; - - else return 'plain'; - } - - // -------------------------------------------------------------------- - - /** - * Set RFC 822 Date - * - * @access public - * @return string - */ - function _set_date() - { - $timezone = date("Z"); - $operator = (substr($timezone, 0, 1) == '-') ? '-' : '+'; - $timezone = abs($timezone); - $timezone = ($timezone/3600) * 100 + ($timezone % 3600) /60; - - return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone); - } - - // -------------------------------------------------------------------- - - /** - * Mime message - * - * @access private - * @return string - */ - function _get_mime_message() - { - return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format."; - } - - // -------------------------------------------------------------------- - - /** - * Validate Email Address - * - * @access public - * @param string - * @return bool - */ - function validate_email($email) - { - if ( ! is_array($email)) - { - $this->_set_error_message('email_must_be_array'); - return FALSE; - } - - foreach ($email as $val) - { - if ( ! $this->valid_email($val)) - { - $this->_set_error_message('email_invalid_address', $val); - return FALSE; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Email Validation - * - * @access public - * @param string - * @return bool - */ - function valid_email($address) - { - if ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) - return FALSE; - else - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Clean Extended Email Address: Joe Smith - * - * @access public - * @param string - * @return string - */ - function clean_email($email) - { - if ( ! is_array($email)) - { - if (preg_match('/\<(.*)\>/', $email, $match)) - return $match['1']; - else - return $email; - } - - $clean_email = array(); - - for ($i=0; $i < count($email); $i++) - { - if (preg_match( '/\<(.*)\>/', $email[$i], $match)) - $clean_email[] = $match['1']; - else - $clean_email[] = $email[$i]; - } - - return $clean_email; - } - - // -------------------------------------------------------------------- - - /** - * Build alternative plain text message - * - * This function provides the raw message for use - * in plain-text headers of HTML-formatted emails. - * If the user hasn't specified his own alternative message - * it creates one by stripping the HTML - * - * @access private - * @return string - */ - function _get_alt_message() - { - if ($this->alt_message != "") - { - return $this->word_wrap($this->alt_message, '76'); - } - - if (eregi( '\', $this->_body, $match)) - { - $body = $match['1']; - $body = substr($body, strpos($body, ">") + 1); - } - else - { - $body = $this->_body; - } - - $body = trim(strip_tags($body)); - $body = preg_replace( '# '.$msg."\n"; - - flock($fp, LOCK_EX); - fwrite($fp, $message); - flock($fp, LOCK_UN); - fclose($fp); - - @chmod($filepath, 0666); - return TRUE; - } - -} -// END Log Class + '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4'); + + /** + * Constructor + * + * @access public + * @param string the log file path + * @param string the error threshold + * @param string the date formatting codes + */ + 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_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 + * + * Generally this function will be called using the global log_message() function + * + * @access public + * @param string the error level + * @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, "a")) + { + return FALSE; + } + + $message .= $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --> '.$msg."\n"; + + flock($fp, LOCK_EX); + fwrite($fp, $message); + flock($fp, LOCK_UN); + fclose($fp); + + @chmod($filepath, 0666); + return TRUE; + } + +} +// END Log Class ?> \ No newline at end of file diff --git a/system/libraries/Model.php b/system/libraries/Model.php index 6f4f7e7ef..3b4c2e144 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -1,82 +1,82 @@ -_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"); - } - - /** - * Assign Libraries - * - * 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. - * - * @access private - */ - function _assign_libraries($use_reference = TRUE) - { - $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) - { - // Needed to prevent reference errors with some configurations - $this->$key = ''; - $this->$key =& $CI->$key; - } - else - { - $this->$key = $CI->$key; - } - } - } - } - -} -// END Model Class +_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"); + } + + /** + * Assign Libraries + * + * 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. + * + * @access private + */ + function _assign_libraries($use_reference = TRUE) + { + $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) + { + // Needed to prevent reference errors with some configurations + $this->$key = ''; + $this->$key =& $CI->$key; + } + else + { + $this->$key = $CI->$key; + } + } + } + } + +} +// END Model Class ?> \ No newline at end of file diff --git a/system/libraries/Output.php b/system/libraries/Output.php index e53627408..743228e53 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -1,364 +1,364 @@ -final_output; - } - - // -------------------------------------------------------------------- - - /** - * Set Output - * - * Sets the output string - * - * @access public - * @param string - * @return void - */ - function set_output($output) - { - $this->final_output = $output; - } - - // -------------------------------------------------------------------- - - /** - * Set Header - * - * Lets you set a server header which will be outputted with the final display. - * - * Note: If a file is cached, headers will not be sent. We need to figure out - * how to permit header data to be saved with the cache data... - * - * @access public - * @param string - * @return void - */ - function set_header($header) - { - $this->headers[] = $header; - } - - // -------------------------------------------------------------------- - - /** - * Enable/disable Profiler - * - * @access public - * @param bool - * @return void - */ - function enable_profiler($val = TRUE) - { - $this->enable_profiler = (is_bool($val)) ? $val : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set Cache - * - * @access public - * @param integer - * @return void - */ - function cache($time) - { - $this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time; - } - - // -------------------------------------------------------------------- - - /** - * Display Output - * - * All "view" data is automatically put into this variable by the controller class: - * - * $this->final_output - * - * This function sends the finalized output data to the browser along - * with any server headers and profile data. It also stops the - * benchmark timer so the page rendering speed and memory usage can be shown. - * - * @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. - global $BM, $CFG; - - // -------------------------------------------------------------------- - - // Set the output data - if ($output == '') - { - $output =& $this->final_output; - } - - // -------------------------------------------------------------------- - - // Do we need to write a cache file? - if ($this->cache_expiration > 0) - { - $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'); - $output = str_replace('{elapsed_time}', $elapsed, $output); - - $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; - $output = str_replace('{memory_usage}', $memory, $output); - - // -------------------------------------------------------------------- - - // Is compression requested? - if ($CFG->item('compress_output') === TRUE) - { - if (extension_loaded('zlib')) - { - if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) AND strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE) - { - ob_start('ob_gzhandler'); - } - } - } - - // -------------------------------------------------------------------- - - // Are there any server headers to send? - if (count($this->headers) > 0) - { - foreach ($this->headers as $header) - { - @header($header); - } - } - - // -------------------------------------------------------------------- - - // Does the get_instance() function exist? - // If not we know we are dealing with a cache file so we'll - // simply echo out the data and exit. - if ( ! function_exists('get_instance')) - { - echo $output; - log_message('debug', "Final output sent to browser"); - log_message('debug', "Total execution time: ".$elapsed); - return TRUE; - } - - // -------------------------------------------------------------------- - - // Grab the super object. We'll need it in a moment... - $CI =& get_instance(); - - // 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'); - - // If the output data contains closing and tags - // we will remove them and add them back after we insert the profile data - if (preg_match("|.*?|is", $output)) - { - $output = preg_replace("|.*?|is", '', $output); - $output .= $CI->profiler->run(); - $output .= ''; - } - else - { - $output .= $CI->profiler->run(); - } - } - - // -------------------------------------------------------------------- - - // Does the controller contain a function named _output()? - // If so send the output there. Otherwise, echo it. - if (method_exists($CI, '_output')) - { - $CI->_output($output); - } - else - { - echo $output; // Send it to the browser! - } - - log_message('debug', "Final output sent to browser"); - log_message('debug', "Total execution time: ".$elapsed); - } - - // -------------------------------------------------------------------- - - /** - * Write a Cache File - * - * @access public - * @return void - */ - function _write_cache($output) - { - $CI =& get_instance(); - $path = $CI->config->item('cache_path'); - - $cache_path = ($path == '') ? BASEPATH.'cache/' : $path; - - if ( ! is_dir($cache_path) OR ! is_writable($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, 'wb')) - { - log_message('error', "Unable to write ache file: ".$cache_path); - return; - } - - $expire = time() + ($this->cache_expiration * 60); - - flock($fp, LOCK_EX); - fwrite($fp, $expire.'TS--->'.$output); - flock($fp, LOCK_UN); - fclose($fp); - @chmod($cache_path, 0777); - - log_message('debug', "Cache file written: ".$cache_path); - } - - // -------------------------------------------------------------------- - - /** - * Update/serve a cached file - * - * @access public - * @return void - */ - function _display_cache(&$CFG, &$RTR) - { - $CFG =& load_class('Config'); - $RTR =& load_class('Router'); - - $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); - - if ( ! is_dir($cache_path) OR ! is_writable($cache_path)) - { - return FALSE; - } - - // Build the file path. The file name is an MD5 hash of the full URI - $uri = $CFG->item('base_url'). - $CFG->item('index_page'). - $RTR->uri_string; - - $filepath = $cache_path.md5($uri); - - if ( ! @file_exists($filepath)) - { - return FALSE; - } - - if ( ! $fp = @fopen($filepath, 'rb')) - { - 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 - 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']))) - { - @unlink($filepath); - log_message('debug', "Cache file has expired. File deleted"); - return FALSE; - } - - // Display the cache - $this->_display(str_replace($match['0'], '', $cache)); - log_message('debug', "Cache file is current. Sending it to browser."); - return TRUE; - } - - -} -// END Output Class +final_output; + } + + // -------------------------------------------------------------------- + + /** + * Set Output + * + * Sets the output string + * + * @access public + * @param string + * @return void + */ + function set_output($output) + { + $this->final_output = $output; + } + + // -------------------------------------------------------------------- + + /** + * Set Header + * + * Lets you set a server header which will be outputted with the final display. + * + * Note: If a file is cached, headers will not be sent. We need to figure out + * how to permit header data to be saved with the cache data... + * + * @access public + * @param string + * @return void + */ + function set_header($header) + { + $this->headers[] = $header; + } + + // -------------------------------------------------------------------- + + /** + * Enable/disable Profiler + * + * @access public + * @param bool + * @return void + */ + function enable_profiler($val = TRUE) + { + $this->enable_profiler = (is_bool($val)) ? $val : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Set Cache + * + * @access public + * @param integer + * @return void + */ + function cache($time) + { + $this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time; + } + + // -------------------------------------------------------------------- + + /** + * Display Output + * + * All "view" data is automatically put into this variable by the controller class: + * + * $this->final_output + * + * This function sends the finalized output data to the browser along + * with any server headers and profile data. It also stops the + * benchmark timer so the page rendering speed and memory usage can be shown. + * + * @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. + global $BM, $CFG; + + // -------------------------------------------------------------------- + + // Set the output data + if ($output == '') + { + $output =& $this->final_output; + } + + // -------------------------------------------------------------------- + + // Do we need to write a cache file? + if ($this->cache_expiration > 0) + { + $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'); + $output = str_replace('{elapsed_time}', $elapsed, $output); + + $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; + $output = str_replace('{memory_usage}', $memory, $output); + + // -------------------------------------------------------------------- + + // Is compression requested? + if ($CFG->item('compress_output') === TRUE) + { + if (extension_loaded('zlib')) + { + if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) AND strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE) + { + ob_start('ob_gzhandler'); + } + } + } + + // -------------------------------------------------------------------- + + // Are there any server headers to send? + if (count($this->headers) > 0) + { + foreach ($this->headers as $header) + { + @header($header); + } + } + + // -------------------------------------------------------------------- + + // Does the get_instance() function exist? + // If not we know we are dealing with a cache file so we'll + // simply echo out the data and exit. + if ( ! function_exists('get_instance')) + { + echo $output; + log_message('debug', "Final output sent to browser"); + log_message('debug', "Total execution time: ".$elapsed); + return TRUE; + } + + // -------------------------------------------------------------------- + + // Grab the super object. We'll need it in a moment... + $CI =& get_instance(); + + // 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'); + + // If the output data contains closing and tags + // we will remove them and add them back after we insert the profile data + if (preg_match("|.*?|is", $output)) + { + $output = preg_replace("|.*?|is", '', $output); + $output .= $CI->profiler->run(); + $output .= ''; + } + else + { + $output .= $CI->profiler->run(); + } + } + + // -------------------------------------------------------------------- + + // Does the controller contain a function named _output()? + // If so send the output there. Otherwise, echo it. + if (method_exists($CI, '_output')) + { + $CI->_output($output); + } + else + { + echo $output; // Send it to the browser! + } + + log_message('debug', "Final output sent to browser"); + log_message('debug', "Total execution time: ".$elapsed); + } + + // -------------------------------------------------------------------- + + /** + * Write a Cache File + * + * @access public + * @return void + */ + function _write_cache($output) + { + $CI =& get_instance(); + $path = $CI->config->item('cache_path'); + + $cache_path = ($path == '') ? BASEPATH.'cache/' : $path; + + if ( ! is_dir($cache_path) OR ! is_writable($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, 'wb')) + { + log_message('error', "Unable to write ache file: ".$cache_path); + return; + } + + $expire = time() + ($this->cache_expiration * 60); + + flock($fp, LOCK_EX); + fwrite($fp, $expire.'TS--->'.$output); + flock($fp, LOCK_UN); + fclose($fp); + @chmod($cache_path, 0777); + + log_message('debug', "Cache file written: ".$cache_path); + } + + // -------------------------------------------------------------------- + + /** + * Update/serve a cached file + * + * @access public + * @return void + */ + function _display_cache(&$CFG, &$RTR) + { + $CFG =& load_class('Config'); + $RTR =& load_class('Router'); + + $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); + + if ( ! is_dir($cache_path) OR ! is_writable($cache_path)) + { + return FALSE; + } + + // Build the file path. The file name is an MD5 hash of the full URI + $uri = $CFG->item('base_url'). + $CFG->item('index_page'). + $RTR->uri_string; + + $filepath = $cache_path.md5($uri); + + if ( ! @file_exists($filepath)) + { + return FALSE; + } + + if ( ! $fp = @fopen($filepath, 'rb')) + { + 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 + 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']))) + { + @unlink($filepath); + log_message('debug', "Cache file has expired. File deleted"); + return FALSE; + } + + // Display the cache + $this->_display(str_replace($match['0'], '', $cache)); + log_message('debug', "Cache file is current. Sending it to browser."); + return TRUE; + } + + +} +// END Output Class ?> \ No newline at end of file diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 07ad6a683..27104c95c 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -1,211 +1,211 @@ -'; - var $cur_tag_close = ''; - var $next_tag_open = ' '; - var $next_tag_close = ' '; - var $prev_tag_open = ' '; - var $prev_tag_close = ''; - var $num_tag_open = ' '; - var $num_tag_close = ''; - - /** - * Constructor - * - * @access public - * @param array initialization parameters - */ - function CI_Pagination($params = array()) - { - if (count($params) > 0) - { - $this->initialize($params); - } - - log_message('debug', "Pagination Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize Preferences - * - * @access public - * @param array initialization parameters - * @return void - */ - function initialize($params = array()) - { - if (count($params) > 0) - { - foreach ($params as $key => $val) - { - if (isset($this->$key)) - { - $this->$key = $val; - } - } - } - } - - // -------------------------------------------------------------------- - - /** - * Generate the pagination links - * - * @access public - * @return string - */ - function create_links() - { - // If our item count or per-page total is zero there is no need to continue. - if ($this->total_rows == 0 OR $this->per_page == 0) - { - return ''; - } - - // Calculate the total number of pages - $num_pages = ceil($this->total_rows / $this->per_page); - - // Is there only one page? Hm... nothing more to do here then. - if ($num_pages == 1) - { - return ''; - } - - // Determine the current page number. - $CI =& get_instance(); - if ($CI->uri->segment($this->uri_segment) != 0) - { - $this->cur_page = $CI->uri->segment($this->uri_segment); - - // Prep the current page - no funny business! - $this->cur_page = preg_replace("/[a-z\-]/", "", $this->cur_page); - } - - if ( ! is_numeric($this->cur_page)) - { - $this->cur_page = 0; - } - - // Is the page number beyond the result range? - // If so we show the last page - if ($this->cur_page > $this->total_rows) - { - $this->cur_page = ($num_pages - 1) * $this->per_page; - } - - $uri_page_number = $this->cur_page; - $this->cur_page = floor(($this->cur_page/$this->per_page) + 1); - - // Calculate the start and end numbers. These determine - // which number to start and end the digit links with - $start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1; - $end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages; - - // Add a trailing slash to the base URL if needed - $this->base_url = preg_replace("/(.+?)\/*$/", "\\1/", $this->base_url); - - // And here we go... - $output = ''; - - // Render the "First" link - if ($this->cur_page > $this->num_links) - { - $output .= $this->first_tag_open.''.$this->first_link.''.$this->first_tag_close; - } - - // Render the "previous" link - if (($this->cur_page - $this->num_links) >= 0) - { - $i = $uri_page_number - $this->per_page; - if ($i == 0) $i = ''; - $output .= $this->prev_tag_open.''.$this->prev_link.''.$this->prev_tag_close; - } - - // Write the digit links - for ($loop = $start -1; $loop <= $end; $loop++) - { - $i = ($loop * $this->per_page) - $this->per_page; - - if ($i >= 0) - { - if ($this->cur_page == $loop) - { - $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page - } - else - { - $n = ($i == 0) ? '' : $i; - $output .= $this->num_tag_open.''.$loop.''.$this->num_tag_close; - } - } - } - - // Render the "next" link - if ($this->cur_page < $num_pages) - { - $output .= $this->next_tag_open.''.$this->next_link.''.$this->next_tag_close; - } - - // Render the "Last" link - if (($this->cur_page + $this->num_links) < $num_pages) - { - $i = (($num_pages * $this->per_page) - $this->per_page); - $output .= $this->last_tag_open.''.$this->last_link.''.$this->last_tag_close; - } - - // Kill double slashes. Note: Sometimes we can end up with a double slash - // in the penultimate link so we'll kill all double slashes. - $output = preg_replace("#([^:])//+#", "\\1/", $output); - - // Add the wrapper HTML if exists - $output = $this->full_tag_open.$output.$this->full_tag_close; - - return $output; - } -} -// END Pagination Class +'; + var $cur_tag_close = ''; + var $next_tag_open = ' '; + var $next_tag_close = ' '; + var $prev_tag_open = ' '; + var $prev_tag_close = ''; + var $num_tag_open = ' '; + var $num_tag_close = ''; + + /** + * Constructor + * + * @access public + * @param array initialization parameters + */ + function CI_Pagination($params = array()) + { + if (count($params) > 0) + { + $this->initialize($params); + } + + log_message('debug', "Pagination Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Initialize Preferences + * + * @access public + * @param array initialization parameters + * @return void + */ + function initialize($params = array()) + { + if (count($params) > 0) + { + foreach ($params as $key => $val) + { + if (isset($this->$key)) + { + $this->$key = $val; + } + } + } + } + + // -------------------------------------------------------------------- + + /** + * Generate the pagination links + * + * @access public + * @return string + */ + function create_links() + { + // If our item count or per-page total is zero there is no need to continue. + if ($this->total_rows == 0 OR $this->per_page == 0) + { + return ''; + } + + // Calculate the total number of pages + $num_pages = ceil($this->total_rows / $this->per_page); + + // Is there only one page? Hm... nothing more to do here then. + if ($num_pages == 1) + { + return ''; + } + + // Determine the current page number. + $CI =& get_instance(); + if ($CI->uri->segment($this->uri_segment) != 0) + { + $this->cur_page = $CI->uri->segment($this->uri_segment); + + // Prep the current page - no funny business! + $this->cur_page = preg_replace("/[a-z\-]/", "", $this->cur_page); + } + + if ( ! is_numeric($this->cur_page)) + { + $this->cur_page = 0; + } + + // Is the page number beyond the result range? + // If so we show the last page + if ($this->cur_page > $this->total_rows) + { + $this->cur_page = ($num_pages - 1) * $this->per_page; + } + + $uri_page_number = $this->cur_page; + $this->cur_page = floor(($this->cur_page/$this->per_page) + 1); + + // Calculate the start and end numbers. These determine + // which number to start and end the digit links with + $start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1; + $end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages; + + // Add a trailing slash to the base URL if needed + $this->base_url = preg_replace("/(.+?)\/*$/", "\\1/", $this->base_url); + + // And here we go... + $output = ''; + + // Render the "First" link + if ($this->cur_page > $this->num_links) + { + $output .= $this->first_tag_open.''.$this->first_link.''.$this->first_tag_close; + } + + // Render the "previous" link + if (($this->cur_page - $this->num_links) >= 0) + { + $i = $uri_page_number - $this->per_page; + if ($i == 0) $i = ''; + $output .= $this->prev_tag_open.''.$this->prev_link.''.$this->prev_tag_close; + } + + // Write the digit links + for ($loop = $start -1; $loop <= $end; $loop++) + { + $i = ($loop * $this->per_page) - $this->per_page; + + if ($i >= 0) + { + if ($this->cur_page == $loop) + { + $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page + } + else + { + $n = ($i == 0) ? '' : $i; + $output .= $this->num_tag_open.''.$loop.''.$this->num_tag_close; + } + } + } + + // Render the "next" link + if ($this->cur_page < $num_pages) + { + $output .= $this->next_tag_open.''.$this->next_link.''.$this->next_tag_close; + } + + // Render the "Last" link + if (($this->cur_page + $this->num_links) < $num_pages) + { + $i = (($num_pages * $this->per_page) - $this->per_page); + $output .= $this->last_tag_open.''.$this->last_link.''.$this->last_tag_close; + } + + // Kill double slashes. Note: Sometimes we can end up with a double slash + // in the penultimate link so we'll kill all double slashes. + $output = preg_replace("#([^:])//+#", "\\1/", $output); + + // Add the wrapper HTML if exists + $output = $this->full_tag_open.$output.$this->full_tag_close; + + return $output; + } +} +// END Pagination Class ?> \ No newline at end of file diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 760d5d4d3..613668ac8 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -1,171 +1,171 @@ -load->view($template, $data, TRUE); - - if ($template == '') - { - return FALSE; - } - - foreach ($data as $key => $val) - { - if (is_string($val)) - { - $template = $this->_parse_single($key, $val, $template); - } - elseif (is_array($val)) - { - $template = $this->_parse_pair($key, $val, $template); - } - } - - if ($return == FALSE) - { - $CI->output->final_output = $template; - } - - return $template; - } - - // -------------------------------------------------------------------- - - /** - * Set the left/right variable delimiters - * - * @access public - * @param string - * @param string - * @return void - */ - function set_delimiters($l = '{', $r = '}') - { - $this->l_delim = $l; - $this->r_delim = $r; - } - - // -------------------------------------------------------------------- - - /** - * Parse a single key/value - * - * @access private - * @param string - * @param string - * @param string - * @return string - */ - function _parse_single($key, $val, $string) - { - return str_replace($this->l_delim.$key.$this->r_delim, $val, $string); - } - - // -------------------------------------------------------------------- - - /** - * Parse a tag pair - * - * Parses tag pairs: {some_tag} string... {/some_tag} - * - * @access private - * @param string - * @param array - * @param string - * @return string - */ - function _parse_pair($variable, $data, $string) - { - if (FALSE === ($match = $this->_match_pair($string, $variable))) - { - return $string; - } - - $str = ''; - foreach ($data as $row) - { - $temp = $match['1']; - foreach ($row as $key => $val) - { - if ( ! is_array($val)) - { - $temp = $this->_parse_single($key, $val, $temp); - } - else - { - $temp = $this->_parse_pair($key, $val, $temp); - } - } - - $str .= $temp; - } - - return str_replace($match['0'], $str, $string); - } - - // -------------------------------------------------------------------- - - /** - * Matches a variable pair - * - * @access private - * @param string - * @param string - * @return mixed - */ - function _match_pair($string, $variable) - { - if ( ! preg_match("|".$this->l_delim . $variable . $this->r_delim."(.+)".$this->l_delim . '/' . $variable . $this->r_delim."|s", $string, $match)) - { - return FALSE; - } - - return $match; - } - -} -// END Parser Class +load->view($template, $data, TRUE); + + if ($template == '') + { + return FALSE; + } + + foreach ($data as $key => $val) + { + if (is_string($val)) + { + $template = $this->_parse_single($key, $val, $template); + } + elseif (is_array($val)) + { + $template = $this->_parse_pair($key, $val, $template); + } + } + + if ($return == FALSE) + { + $CI->output->final_output = $template; + } + + return $template; + } + + // -------------------------------------------------------------------- + + /** + * Set the left/right variable delimiters + * + * @access public + * @param string + * @param string + * @return void + */ + function set_delimiters($l = '{', $r = '}') + { + $this->l_delim = $l; + $this->r_delim = $r; + } + + // -------------------------------------------------------------------- + + /** + * Parse a single key/value + * + * @access private + * @param string + * @param string + * @param string + * @return string + */ + function _parse_single($key, $val, $string) + { + return str_replace($this->l_delim.$key.$this->r_delim, $val, $string); + } + + // -------------------------------------------------------------------- + + /** + * Parse a tag pair + * + * Parses tag pairs: {some_tag} string... {/some_tag} + * + * @access private + * @param string + * @param array + * @param string + * @return string + */ + function _parse_pair($variable, $data, $string) + { + if (FALSE === ($match = $this->_match_pair($string, $variable))) + { + return $string; + } + + $str = ''; + foreach ($data as $row) + { + $temp = $match['1']; + foreach ($row as $key => $val) + { + if ( ! is_array($val)) + { + $temp = $this->_parse_single($key, $val, $temp); + } + else + { + $temp = $this->_parse_pair($key, $val, $temp); + } + } + + $str .= $temp; + } + + return str_replace($match['0'], $str, $string); + } + + // -------------------------------------------------------------------- + + /** + * Matches a variable pair + * + * @access private + * @param string + * @param string + * @return mixed + */ + function _match_pair($string, $variable) + { + if ( ! preg_match("|".$this->l_delim . $variable . $this->r_delim."(.+)".$this->l_delim . '/' . $variable . $this->r_delim."|s", $string, $match)) + { + return FALSE; + } + + return $match; + } + +} +// END Parser Class ?> \ No newline at end of file diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 37b345184..cdc4f6fc9 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -1,12 +1,12 @@ CI =& get_instance(); - - log_message('debug', "Session Class Initialized"); - $this->sess_run(); - } - - // -------------------------------------------------------------------- - - /** - * Run the session routines - * - * @access public - * @return void - */ - function sess_run() - { - /* - * Set the "now" time - * - * It can either set to GMT or time(). The pref - * is set in the config file. If the developer - * is doing any sort of time localization they - * might want to set the session time to GMT so - * they can offset the "last_activity" and - * "last_visit" times based on each user's locale. - * - */ - if (strtolower($this->CI->config->item('time_reference')) == 'gmt') - { - $now = time(); - $this->now = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); - - if (strlen($this->now) < 10) - { - $this->now = time(); - log_message('error', 'The session class could not set a proper GMT timestamp so the local time() value was used.'); - } - } - else - { - $this->now = time(); - } - - /* - * Set the session length - * - * If the session expiration is set to zero in - * the config file we'll set the expiration - * two years from now. - * - */ - $expiration = $this->CI->config->item('sess_expiration'); - - if (is_numeric($expiration)) - { - if ($expiration > 0) - { - $this->sess_length = $this->CI->config->item('sess_expiration'); - } - else - { - $this->sess_length = (60*60*24*365*2); - } - } - - // Do we need encryption? - $this->encryption = $this->CI->config->item('sess_encrypt_cookie'); - - if ($this->encryption == TRUE) - { - $this->CI->load->library('encrypt'); - } - - // Are we using a database? - if ($this->CI->config->item('sess_use_database') === TRUE AND $this->CI->config->item('sess_table_name') != '') - { - $this->use_database = TRUE; - $this->session_table = $this->CI->config->item('sess_table_name'); - $this->CI->load->database(); - } - - // Set the cookie name - if ($this->CI->config->item('sess_cookie_name') != FALSE) - { - $this->sess_cookie = $this->CI->config->item('cookie_prefix').$this->CI->config->item('sess_cookie_name'); - } - - /* - * Fetch the current session - * - * If a session doesn't exist we'll create - * a new one. If it does, we'll update it. - * - */ - if ( ! $this->sess_read()) - { - $this->sess_create(); - } - else - { - // We only update the session every five minutes - if (($this->userdata['last_activity'] + 300) < $this->now) - { - $this->sess_update(); - } - } - - // Delete expired sessions if necessary - if ($this->use_database === TRUE) - { - $this->sess_gc(); - } - } - - // -------------------------------------------------------------------- - - /** - * Fetch the current session data if it exists - * - * @access public - * @return void - */ - function sess_read() - { - // Fetch the cookie - $session = $this->CI->input->cookie($this->sess_cookie); - - if ($session === FALSE) - { - log_message('debug', 'A session cookie was not found.'); - return FALSE; - } - - // Decrypt and unserialize the data - if ($this->encryption == TRUE) - { - $session = $this->CI->encrypt->decode($session); - } - - $session = @unserialize($this->strip_slashes($session)); - - if ( ! is_array($session) OR ! isset($session['last_activity'])) - { - log_message('error', 'The session cookie data did not contain a valid array. This could be a possible hacking attempt.'); - return FALSE; - } - - // Is the session current? - if (($session['last_activity'] + $this->sess_length) < $this->now) - { - $this->sess_destroy(); - return FALSE; - } - - // Does the IP Match? - if ($this->CI->config->item('sess_match_ip') == TRUE AND $session['ip_address'] != $this->CI->input->ip_address()) - { - $this->sess_destroy(); - return FALSE; - } - - // Does the User Agent Match? - if ($this->CI->config->item('sess_match_useragent') == TRUE AND $session['user_agent'] != substr($this->CI->input->user_agent(), 0, 50)) - { - $this->sess_destroy(); - return FALSE; - } - - // Is there a corresponding session in the DB? - if ($this->use_database === TRUE) - { - $this->CI->db->where('session_id', $session['session_id']); - - if ($this->CI->config->item('sess_match_ip') == TRUE) - { - $this->CI->db->where('ip_address', $session['ip_address']); - } - - if ($this->CI->config->item('sess_match_useragent') == TRUE) - { - $this->CI->db->where('user_agent', $session['user_agent']); - } - - $query = $this->CI->db->get($this->session_table); - - if ($query->num_rows() == 0) - { - $this->sess_destroy(); - return FALSE; - } - else - { - $row = $query->row(); - if (($row->last_activity + $this->sess_length) < $this->now) - { - $this->CI->db->where('session_id', $session['session_id']); - $this->CI->db->delete($this->session_table); - $this->sess_destroy(); - return FALSE; - } - } - } - - // Session is valid! - $this->userdata = $session; - unset($session); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Write the session cookie - * - * @access public - * @return void - */ - function sess_write() - { - $cookie_data = serialize($this->userdata); - - if ($this->encryption == TRUE) - { - $cookie_data = $this->CI->encrypt->encode($cookie_data); - } - - setcookie( - $this->sess_cookie, - $cookie_data, - $this->sess_length + time(), - $this->CI->config->item('cookie_path'), - $this->CI->config->item('cookie_domain'), - 0 - ); - } - - // -------------------------------------------------------------------- - - /** - * Create a new session - * - * @access public - * @return void - */ - function sess_create() - { - $sessid = ''; - while (strlen($sessid) < 32) - { - $sessid .= mt_rand(0, mt_getrandmax()); - } - - $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), - 'last_activity' => $this->now - ); - - - // Save the session in the DB if needed - if ($this->use_database === TRUE) - { - $this->CI->db->query($this->CI->db->insert_string($this->session_table, $this->userdata)); - } - - // Write the cookie - $this->userdata['last_visit'] = 0; - $this->sess_write(); - } - - // -------------------------------------------------------------------- - - /** - * Update an existing session - * - * @access public - * @return void - */ - function sess_update() - { - if (($this->userdata['last_activity'] + $this->sess_length) < $this->now) - { - $this->userdata['last_visit'] = $this->userdata['last_activity']; - } - - $this->userdata['last_activity'] = $this->now; - - // Update the session in the DB if needed - if ($this->use_database === TRUE) - { - $this->CI->db->query($this->CI->db->update_string($this->session_table, array('last_activity' => $this->now), array('session_id' => $this->userdata['session_id']))); - } - - // Write the cookie - $this->sess_write(); - } - - // -------------------------------------------------------------------- - - /** - * Destroy the current session - * - * @access public - * @return void - */ - function sess_destroy() - { - setcookie( - $this->sess_cookie, - addslashes(serialize(array())), - ($this->now - 31500000), - $this->CI->config->item('cookie_path'), - $this->CI->config->item('cookie_domain'), - 0 - ); - } - - // -------------------------------------------------------------------- - - /** - * Garbage collection - * - * This deletes expired session rows from database - * if the probability percentage is met - * - * @access public - * @return void - */ - function sess_gc() - { - srand(time()); - if ((rand() % 100) < $this->gc_probability) - { - $expire = $this->now - $this->sess_length; - - $this->CI->db->where("last_activity < {$expire}"); - $this->CI->db->delete($this->session_table); - - log_message('debug', 'Session garbage collection performed.'); - } - } - - // -------------------------------------------------------------------- - - /** - * Fetch a specific item form the session array - * - * @access public - * @param string - * @return string - */ - function userdata($item) - { - return ( ! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; - } - - // -------------------------------------------------------------------- - - /** - * Add or change data in the "userdata" array - * - * @access public - * @param mixed - * @param string - * @return void - */ - function set_userdata($newdata = array(), $newval = '') - { - if (is_string($newdata)) - { - $newdata = array($newdata => $newval); - } - - if (count($newdata) > 0) - { - foreach ($newdata as $key => $val) - { - $this->userdata[$key] = $val; - } - } - - $this->sess_write(); - } - - // -------------------------------------------------------------------- - - /** - * Delete a session variable from the "userdata" array - * - * @access array - * @return void - */ - function unset_userdata($newdata = array()) - { - if (is_string($newdata)) - { - $newdata = array($newdata => ''); - } - - if (count($newdata) > 0) - { - foreach ($newdata as $key => $val) - { - unset($this->userdata[$key]); - } - } - - $this->sess_write(); - } - - // -------------------------------------------------------------------- - - /** - * Strip slashes - * - * @access public - * @param mixed - * @return mixed - */ - function strip_slashes($vals) - { - if (is_array($vals)) - { - foreach ($vals as $key=>$val) - { - $vals[$key] = $this->strip_slashes($val); - } - } - else - { - $vals = stripslashes($vals); - } - - return $vals; - } - -} -// END Session Class +CI =& get_instance(); + + log_message('debug', "Session Class Initialized"); + $this->sess_run(); + } + + // -------------------------------------------------------------------- + + /** + * Run the session routines + * + * @access public + * @return void + */ + function sess_run() + { + /* + * Set the "now" time + * + * It can either set to GMT or time(). The pref + * is set in the config file. If the developer + * is doing any sort of time localization they + * might want to set the session time to GMT so + * they can offset the "last_activity" and + * "last_visit" times based on each user's locale. + * + */ + if (strtolower($this->CI->config->item('time_reference')) == 'gmt') + { + $now = time(); + $this->now = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); + + if (strlen($this->now) < 10) + { + $this->now = time(); + log_message('error', 'The session class could not set a proper GMT timestamp so the local time() value was used.'); + } + } + else + { + $this->now = time(); + } + + /* + * Set the session length + * + * If the session expiration is set to zero in + * the config file we'll set the expiration + * two years from now. + * + */ + $expiration = $this->CI->config->item('sess_expiration'); + + if (is_numeric($expiration)) + { + if ($expiration > 0) + { + $this->sess_length = $this->CI->config->item('sess_expiration'); + } + else + { + $this->sess_length = (60*60*24*365*2); + } + } + + // Do we need encryption? + $this->encryption = $this->CI->config->item('sess_encrypt_cookie'); + + if ($this->encryption == TRUE) + { + $this->CI->load->library('encrypt'); + } + + // Are we using a database? + if ($this->CI->config->item('sess_use_database') === TRUE AND $this->CI->config->item('sess_table_name') != '') + { + $this->use_database = TRUE; + $this->session_table = $this->CI->config->item('sess_table_name'); + $this->CI->load->database(); + } + + // Set the cookie name + if ($this->CI->config->item('sess_cookie_name') != FALSE) + { + $this->sess_cookie = $this->CI->config->item('cookie_prefix').$this->CI->config->item('sess_cookie_name'); + } + + /* + * Fetch the current session + * + * If a session doesn't exist we'll create + * a new one. If it does, we'll update it. + * + */ + if ( ! $this->sess_read()) + { + $this->sess_create(); + } + else + { + // We only update the session every five minutes + if (($this->userdata['last_activity'] + 300) < $this->now) + { + $this->sess_update(); + } + } + + // Delete expired sessions if necessary + if ($this->use_database === TRUE) + { + $this->sess_gc(); + } + } + + // -------------------------------------------------------------------- + + /** + * Fetch the current session data if it exists + * + * @access public + * @return void + */ + function sess_read() + { + // Fetch the cookie + $session = $this->CI->input->cookie($this->sess_cookie); + + if ($session === FALSE) + { + log_message('debug', 'A session cookie was not found.'); + return FALSE; + } + + // Decrypt and unserialize the data + if ($this->encryption == TRUE) + { + $session = $this->CI->encrypt->decode($session); + } + + $session = @unserialize($this->strip_slashes($session)); + + if ( ! is_array($session) OR ! isset($session['last_activity'])) + { + log_message('error', 'The session cookie data did not contain a valid array. This could be a possible hacking attempt.'); + return FALSE; + } + + // Is the session current? + if (($session['last_activity'] + $this->sess_length) < $this->now) + { + $this->sess_destroy(); + return FALSE; + } + + // Does the IP Match? + if ($this->CI->config->item('sess_match_ip') == TRUE AND $session['ip_address'] != $this->CI->input->ip_address()) + { + $this->sess_destroy(); + return FALSE; + } + + // Does the User Agent Match? + if ($this->CI->config->item('sess_match_useragent') == TRUE AND $session['user_agent'] != substr($this->CI->input->user_agent(), 0, 50)) + { + $this->sess_destroy(); + return FALSE; + } + + // Is there a corresponding session in the DB? + if ($this->use_database === TRUE) + { + $this->CI->db->where('session_id', $session['session_id']); + + if ($this->CI->config->item('sess_match_ip') == TRUE) + { + $this->CI->db->where('ip_address', $session['ip_address']); + } + + if ($this->CI->config->item('sess_match_useragent') == TRUE) + { + $this->CI->db->where('user_agent', $session['user_agent']); + } + + $query = $this->CI->db->get($this->session_table); + + if ($query->num_rows() == 0) + { + $this->sess_destroy(); + return FALSE; + } + else + { + $row = $query->row(); + if (($row->last_activity + $this->sess_length) < $this->now) + { + $this->CI->db->where('session_id', $session['session_id']); + $this->CI->db->delete($this->session_table); + $this->sess_destroy(); + return FALSE; + } + } + } + + // Session is valid! + $this->userdata = $session; + unset($session); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Write the session cookie + * + * @access public + * @return void + */ + function sess_write() + { + $cookie_data = serialize($this->userdata); + + if ($this->encryption == TRUE) + { + $cookie_data = $this->CI->encrypt->encode($cookie_data); + } + + setcookie( + $this->sess_cookie, + $cookie_data, + $this->sess_length + time(), + $this->CI->config->item('cookie_path'), + $this->CI->config->item('cookie_domain'), + 0 + ); + } + + // -------------------------------------------------------------------- + + /** + * Create a new session + * + * @access public + * @return void + */ + function sess_create() + { + $sessid = ''; + while (strlen($sessid) < 32) + { + $sessid .= mt_rand(0, mt_getrandmax()); + } + + $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), + 'last_activity' => $this->now + ); + + + // Save the session in the DB if needed + if ($this->use_database === TRUE) + { + $this->CI->db->query($this->CI->db->insert_string($this->session_table, $this->userdata)); + } + + // Write the cookie + $this->userdata['last_visit'] = 0; + $this->sess_write(); + } + + // -------------------------------------------------------------------- + + /** + * Update an existing session + * + * @access public + * @return void + */ + function sess_update() + { + if (($this->userdata['last_activity'] + $this->sess_length) < $this->now) + { + $this->userdata['last_visit'] = $this->userdata['last_activity']; + } + + $this->userdata['last_activity'] = $this->now; + + // Update the session in the DB if needed + if ($this->use_database === TRUE) + { + $this->CI->db->query($this->CI->db->update_string($this->session_table, array('last_activity' => $this->now), array('session_id' => $this->userdata['session_id']))); + } + + // Write the cookie + $this->sess_write(); + } + + // -------------------------------------------------------------------- + + /** + * Destroy the current session + * + * @access public + * @return void + */ + function sess_destroy() + { + setcookie( + $this->sess_cookie, + addslashes(serialize(array())), + ($this->now - 31500000), + $this->CI->config->item('cookie_path'), + $this->CI->config->item('cookie_domain'), + 0 + ); + } + + // -------------------------------------------------------------------- + + /** + * Garbage collection + * + * This deletes expired session rows from database + * if the probability percentage is met + * + * @access public + * @return void + */ + function sess_gc() + { + srand(time()); + if ((rand() % 100) < $this->gc_probability) + { + $expire = $this->now - $this->sess_length; + + $this->CI->db->where("last_activity < {$expire}"); + $this->CI->db->delete($this->session_table); + + log_message('debug', 'Session garbage collection performed.'); + } + } + + // -------------------------------------------------------------------- + + /** + * Fetch a specific item form the session array + * + * @access public + * @param string + * @return string + */ + function userdata($item) + { + return ( ! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; + } + + // -------------------------------------------------------------------- + + /** + * Add or change data in the "userdata" array + * + * @access public + * @param mixed + * @param string + * @return void + */ + function set_userdata($newdata = array(), $newval = '') + { + if (is_string($newdata)) + { + $newdata = array($newdata => $newval); + } + + if (count($newdata) > 0) + { + foreach ($newdata as $key => $val) + { + $this->userdata[$key] = $val; + } + } + + $this->sess_write(); + } + + // -------------------------------------------------------------------- + + /** + * Delete a session variable from the "userdata" array + * + * @access array + * @return void + */ + function unset_userdata($newdata = array()) + { + if (is_string($newdata)) + { + $newdata = array($newdata => ''); + } + + if (count($newdata) > 0) + { + foreach ($newdata as $key => $val) + { + unset($this->userdata[$key]); + } + } + + $this->sess_write(); + } + + // -------------------------------------------------------------------- + + /** + * Strip slashes + * + * @access public + * @param mixed + * @return mixed + */ + function strip_slashes($vals) + { + if (is_array($vals)) + { + foreach ($vals as $key=>$val) + { + $vals[$key] = $this->strip_slashes($val); + } + } + else + { + $vals = stripslashes($vals); + } + + return $vals; + } + +} +// END Session Class ?> \ No newline at end of file diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index 4dde04038..451428deb 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -1,249 +1,249 @@ -> 6) + 1; - - for ($i = 0; $i < $n * 16; $i++) - { - $x[$i] = 0; - } - - for ($i = 0; $i < strlen($str); $i++) - { - $x[$i >> 2] |= ord(substr($str, $i, 1)) << (24 - ($i % 4) * 8); - } - - $x[$i >> 2] |= 0x80 << (24 - ($i % 4) * 8); - - $x[$n * 16 - 1] = strlen($str) * 8; - - $a = 1732584193; - $b = -271733879; - $c = -1732584194; - $d = 271733878; - $e = -1009589776; - - for ($i = 0; $i < sizeof($x); $i += 16) - { - $olda = $a; - $oldb = $b; - $oldc = $c; - $oldd = $d; - $olde = $e; - - for($j = 0; $j < 80; $j++) - { - if ($j < 16) - { - $w[$j] = $x[$i + $j]; - } - else - { - $w[$j] = $this->_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1); - } - - $t = $this->_safe_add($this->_safe_add($this->_rol($a, 5), $this->_ft($j, $b, $c, $d)), $this->_safe_add($this->_safe_add($e, $w[$j]), $this->_kt($j))); - - $e = $d; - $d = $c; - $c = $this->_rol($b, 30); - $b = $a; - $a = $t; - } - - $a = $this->_safe_add($a, $olda); - $b = $this->_safe_add($b, $oldb); - $c = $this->_safe_add($c, $oldc); - $d = $this->_safe_add($d, $oldd); - $e = $this->_safe_add($e, $olde); - } - - return $this->_hex($a).$this->_hex($b).$this->_hex($c).$this->_hex($d).$this->_hex($e); - } - - // -------------------------------------------------------------------- - - /** - * Convert a decimal to hex - * - * @access private - * @param string - * @return string - */ - function _hex($str) - { - $str = dechex($str); - - if (strlen($str) == 7) - { - $str = '0'.$str; - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Return result based on iteration - * - * @access private - * @return string - */ - function _ft($t, $b, $c, $d) - { - if ($t < 20) - return ($b & $c) | ((~$b) & $d); - if ($t < 40) - return $b ^ $c ^ $d; - if ($t < 60) - return ($b & $c) | ($b & $d) | ($c & $d); - - return $b ^ $c ^ $d; - } - - // -------------------------------------------------------------------- - - /** - * Determine the additive constant - * - * @access private - * @return string - */ - function _kt($t) - { - if ($t < 20) - { - return 1518500249; - } - else if ($t < 40) - { - return 1859775393; - } - else if ($t < 60) - { - return -1894007588; - } - else - { - return -899497514; - } - } - - // -------------------------------------------------------------------- - - /** - * Add integers, wrapping at 2^32 - * - * @access private - * @return string - */ - function _safe_add($x, $y) - { - $lsw = ($x & 0xFFFF) + ($y & 0xFFFF); - $msw = ($x >> 16) + ($y >> 16) + ($lsw >> 16); - - return ($msw << 16) | ($lsw & 0xFFFF); - } - - // -------------------------------------------------------------------- - - /** - * Bitwise rotate a 32-bit number - * - * @access private - * @return integer - */ - function _rol($num, $cnt) - { - return ($num << $cnt) | $this->_zero_fill($num, 32 - $cnt); - } - - // -------------------------------------------------------------------- - - /** - * Pad string with zero - * - * @access private - * @return string - */ - function _zero_fill($a, $b) - { - $bin = decbin($a); - - if (strlen($bin) < $b) - { - $bin = 0; - } - else - { - $bin = substr($bin, 0, strlen($bin) - $b); - } - - for ($i=0; $i < $b; $i++) - { - $bin = "0".$bin; - } - - return bindec($bin); - } -} -// END CI_SHA +> 6) + 1; + + for ($i = 0; $i < $n * 16; $i++) + { + $x[$i] = 0; + } + + for ($i = 0; $i < strlen($str); $i++) + { + $x[$i >> 2] |= ord(substr($str, $i, 1)) << (24 - ($i % 4) * 8); + } + + $x[$i >> 2] |= 0x80 << (24 - ($i % 4) * 8); + + $x[$n * 16 - 1] = strlen($str) * 8; + + $a = 1732584193; + $b = -271733879; + $c = -1732584194; + $d = 271733878; + $e = -1009589776; + + for ($i = 0; $i < sizeof($x); $i += 16) + { + $olda = $a; + $oldb = $b; + $oldc = $c; + $oldd = $d; + $olde = $e; + + for($j = 0; $j < 80; $j++) + { + if ($j < 16) + { + $w[$j] = $x[$i + $j]; + } + else + { + $w[$j] = $this->_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1); + } + + $t = $this->_safe_add($this->_safe_add($this->_rol($a, 5), $this->_ft($j, $b, $c, $d)), $this->_safe_add($this->_safe_add($e, $w[$j]), $this->_kt($j))); + + $e = $d; + $d = $c; + $c = $this->_rol($b, 30); + $b = $a; + $a = $t; + } + + $a = $this->_safe_add($a, $olda); + $b = $this->_safe_add($b, $oldb); + $c = $this->_safe_add($c, $oldc); + $d = $this->_safe_add($d, $oldd); + $e = $this->_safe_add($e, $olde); + } + + return $this->_hex($a).$this->_hex($b).$this->_hex($c).$this->_hex($d).$this->_hex($e); + } + + // -------------------------------------------------------------------- + + /** + * Convert a decimal to hex + * + * @access private + * @param string + * @return string + */ + function _hex($str) + { + $str = dechex($str); + + if (strlen($str) == 7) + { + $str = '0'.$str; + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Return result based on iteration + * + * @access private + * @return string + */ + function _ft($t, $b, $c, $d) + { + if ($t < 20) + return ($b & $c) | ((~$b) & $d); + if ($t < 40) + return $b ^ $c ^ $d; + if ($t < 60) + return ($b & $c) | ($b & $d) | ($c & $d); + + return $b ^ $c ^ $d; + } + + // -------------------------------------------------------------------- + + /** + * Determine the additive constant + * + * @access private + * @return string + */ + function _kt($t) + { + if ($t < 20) + { + return 1518500249; + } + else if ($t < 40) + { + return 1859775393; + } + else if ($t < 60) + { + return -1894007588; + } + else + { + return -899497514; + } + } + + // -------------------------------------------------------------------- + + /** + * Add integers, wrapping at 2^32 + * + * @access private + * @return string + */ + function _safe_add($x, $y) + { + $lsw = ($x & 0xFFFF) + ($y & 0xFFFF); + $msw = ($x >> 16) + ($y >> 16) + ($lsw >> 16); + + return ($msw << 16) | ($lsw & 0xFFFF); + } + + // -------------------------------------------------------------------- + + /** + * Bitwise rotate a 32-bit number + * + * @access private + * @return integer + */ + function _rol($num, $cnt) + { + return ($num << $cnt) | $this->_zero_fill($num, 32 - $cnt); + } + + // -------------------------------------------------------------------- + + /** + * Pad string with zero + * + * @access private + * @return string + */ + function _zero_fill($a, $b) + { + $bin = decbin($a); + + if (strlen($bin) < $b) + { + $bin = 0; + } + else + { + $bin = substr($bin, 0, strlen($bin) - $b); + } + + for ($i=0; $i < $b; $i++) + { + $bin = "0".$bin; + } + + return bindec($bin); + } +} +// END CI_SHA ?> \ No newline at end of file diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 32223708e..44acce657 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -1,12 +1,12 @@ '', 'title' => '', 'excerpt' => '', 'blog_name' => '', 'charset' => ''); - var $convert_ascii = TRUE; - var $response = ''; - var $error_msg = array(); - - /** - * Constructor - * - * @access public - */ - function 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) - { - if ( ! isset($tb_data[$item])) - { - $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])))); - break; - default : $$item = $this->convert_xml(strip_tags(stripslashes($tb_data[$item]))); - break; - } - - // Convert High ASCII Characters - if ($this->convert_ascii == TRUE) - { - if ($item == 'excerpt') - { - $$item = $this->convert_ascii($$item); - } - elseif ($item == 'title') - { - $$item = $this->convert_ascii($$item); - } - elseif($item == 'blog_name') - { - $$item = $this->convert_ascii($$item); - } - } - } - - // 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) - { - foreach ($ping_url as $url) - { - if ($this->process($url, $data) == FALSE) - { - $return = FALSE; - } - } - } - - return $return; - } - - // -------------------------------------------------------------------- - - /** - * Receive Trackback Data - * - * This function simply validates the incoming TB data. - * It returns false on failure and true on success. - * If the data is valid it is set to the $this->data array - * so that it can be inserted into a database. - * - * @access public - * @return bool - */ - function receive() - { - foreach (array('url', 'title', 'blog_name', 'excerpt') as $val) - { - if ( ! isset($_POST[$val]) OR $_POST[$val] == '') - { - $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 - * - * Allows custom errors to be set. By default it - * sends the "incomplete information" error, as that's - * the most common one. - * - * @access public - * @param string - * @return void - */ - function send_error($message = 'Incomplete Information') - { - echo "\n\n1\n".$message."\n"; - exit; - } - - // -------------------------------------------------------------------- - - /** - * Send Trackback Success Message - * - * This should be called when a trackback has been - * successfully received and inserted. - * - * @access public - * @return void - */ - function send_success() - { - echo "\n\n0\n"; - exit; - } - - // -------------------------------------------------------------------- - - /** - * Fetch a particular item - * - * @access public - * @param string - * @return string - */ - function data($item) - { - return ( ! isset($this->data[$item])) ? '' : $this->data[$item]; - } - - // -------------------------------------------------------------------- - - /** - * Process Trackback - * - * Opens a socket connection and passes the data to - * the server. Returns true on success, false on failure - * - * @access public - * @param string - * @param string - * @return bool - */ - function process($url, $data) - { - $target = parse_url($url); - - // Open the socket - if ( ! $fp = @fsockopen($target['host'], 80)) - { - $this->set_error('Invalid Connection: '.$url); - return FALSE; - } - - // 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 - if ($id = $this->get_id($url)) - { - $data = "tb_id=".$id."&".$data; - } - - // Transfer the data - fputs ($fp, "POST " . $path . " HTTP/1.0\r\n" ); - fputs ($fp, "Host: " . $target['host'] . "\r\n" ); - fputs ($fp, "Content-type: application/x-www-form-urlencoded\r\n" ); - fputs ($fp, "Content-length: " . strlen($data) . "\r\n" ); - fputs ($fp, "Connection: close\r\n\r\n" ); - fputs ($fp, $data); - - // Was it successful? - $this->response = ""; - - while(!feof($fp)) - { - $this->response .= fgets($fp, 128); - } - @fclose($fp); - - if ( ! eregi("0", $this->response)) - { - $message = 'An unknown error was encountered'; - - if (preg_match("/(.*?)<\/message>/is", $this->response, $match)) - { - $message = trim($match['1']); - } - - $this->set_error($message); - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Extract Trackback URLs - * - * This function lets multiple trackbacks be sent. - * It takes a string of URLs (separated by comma or - * space) and puts each URL into an array - * - * @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 - * - * Simply adds "http://" if missing - * - * @access public - * @param string - * @return string - */ - function validate_url($url) - { - $url = trim($url); - - if (substr($url, 0, 4) != "http") - { - $url = "http://".$url; - } - } - - // -------------------------------------------------------------------- - - /** - * Find the Trackback URL's ID - * - * @access public - * @param string - * @return string - */ - function get_id($url) - { - $tb_id = ""; - - if (strstr($url, '?')) - { - $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 - { - if (ereg("/$", $url)) - { - $url = substr($url, 0, -1); - } - - $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; - } - else - { - return $tb_id; - } - } - - // -------------------------------------------------------------------- - - /** - * Convert Reserved XML characters to Entities - * - * @access public - * @param string - * @return string - */ - 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); - - $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); - $str = preg_replace("/$temp(\w+);/","&\\1;", $str); - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Character limiter - * - * Limits the string based on the character count. Will preserve complete words. - * - * @access public - * @param string - * @param integer - * @param string - * @return string - */ - function limit_characters($str, $n = 500, $end_char = '…') - { - if (strlen($str) < $n) - { - return $str; - } - - $str = preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $str)); - - if (strlen($str) <= $n) - { - return $str; - } - - $out = ""; - foreach (explode(' ', trim($str)) as $val) - { - $out .= $val.' '; - if (strlen($out) >= $n) - { - return trim($out).$end_char; - } - } - } - - // -------------------------------------------------------------------- - - /** - * High ASCII to Entities - * - * Converts Hight ascii text and MS Word special chars - * to character entities - * - * @access public - * @param string - * @return string - */ - 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; - } - - // -------------------------------------------------------------------- - - /** - * Set error message - * - * @access public - * @param string - * @return void - */ - function set_error($msg) - { - log_message('error', $msg); - $this->error_msg[] = $msg; - } - - // -------------------------------------------------------------------- - - /** - * Show error messages - * - * @access public - * @param string - * @param string - * @return string - */ - function display_errors($open = '

', $close = '

') - { - $str = ''; - foreach ($this->error_msg as $val) - { - $str .= $open.$val.$close; - } - - return $str; - } - -} -// END Trackback Class + '', 'title' => '', 'excerpt' => '', 'blog_name' => '', 'charset' => ''); + var $convert_ascii = TRUE; + var $response = ''; + var $error_msg = array(); + + /** + * Constructor + * + * @access public + */ + function 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) + { + if ( ! isset($tb_data[$item])) + { + $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])))); + break; + default : $$item = $this->convert_xml(strip_tags(stripslashes($tb_data[$item]))); + break; + } + + // Convert High ASCII Characters + if ($this->convert_ascii == TRUE) + { + if ($item == 'excerpt') + { + $$item = $this->convert_ascii($$item); + } + elseif ($item == 'title') + { + $$item = $this->convert_ascii($$item); + } + elseif($item == 'blog_name') + { + $$item = $this->convert_ascii($$item); + } + } + } + + // 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) + { + foreach ($ping_url as $url) + { + if ($this->process($url, $data) == FALSE) + { + $return = FALSE; + } + } + } + + return $return; + } + + // -------------------------------------------------------------------- + + /** + * Receive Trackback Data + * + * This function simply validates the incoming TB data. + * It returns false on failure and true on success. + * If the data is valid it is set to the $this->data array + * so that it can be inserted into a database. + * + * @access public + * @return bool + */ + function receive() + { + foreach (array('url', 'title', 'blog_name', 'excerpt') as $val) + { + if ( ! isset($_POST[$val]) OR $_POST[$val] == '') + { + $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 + * + * Allows custom errors to be set. By default it + * sends the "incomplete information" error, as that's + * the most common one. + * + * @access public + * @param string + * @return void + */ + function send_error($message = 'Incomplete Information') + { + echo "\n\n1\n".$message."\n"; + exit; + } + + // -------------------------------------------------------------------- + + /** + * Send Trackback Success Message + * + * This should be called when a trackback has been + * successfully received and inserted. + * + * @access public + * @return void + */ + function send_success() + { + echo "\n\n0\n"; + exit; + } + + // -------------------------------------------------------------------- + + /** + * Fetch a particular item + * + * @access public + * @param string + * @return string + */ + function data($item) + { + return ( ! isset($this->data[$item])) ? '' : $this->data[$item]; + } + + // -------------------------------------------------------------------- + + /** + * Process Trackback + * + * Opens a socket connection and passes the data to + * the server. Returns true on success, false on failure + * + * @access public + * @param string + * @param string + * @return bool + */ + function process($url, $data) + { + $target = parse_url($url); + + // Open the socket + if ( ! $fp = @fsockopen($target['host'], 80)) + { + $this->set_error('Invalid Connection: '.$url); + return FALSE; + } + + // 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 + if ($id = $this->get_id($url)) + { + $data = "tb_id=".$id."&".$data; + } + + // Transfer the data + fputs ($fp, "POST " . $path . " HTTP/1.0\r\n" ); + fputs ($fp, "Host: " . $target['host'] . "\r\n" ); + fputs ($fp, "Content-type: application/x-www-form-urlencoded\r\n" ); + fputs ($fp, "Content-length: " . strlen($data) . "\r\n" ); + fputs ($fp, "Connection: close\r\n\r\n" ); + fputs ($fp, $data); + + // Was it successful? + $this->response = ""; + + while(!feof($fp)) + { + $this->response .= fgets($fp, 128); + } + @fclose($fp); + + if ( ! eregi("0", $this->response)) + { + $message = 'An unknown error was encountered'; + + if (preg_match("/(.*?)<\/message>/is", $this->response, $match)) + { + $message = trim($match['1']); + } + + $this->set_error($message); + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Extract Trackback URLs + * + * This function lets multiple trackbacks be sent. + * It takes a string of URLs (separated by comma or + * space) and puts each URL into an array + * + * @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 + * + * Simply adds "http://" if missing + * + * @access public + * @param string + * @return string + */ + function validate_url($url) + { + $url = trim($url); + + if (substr($url, 0, 4) != "http") + { + $url = "http://".$url; + } + } + + // -------------------------------------------------------------------- + + /** + * Find the Trackback URL's ID + * + * @access public + * @param string + * @return string + */ + function get_id($url) + { + $tb_id = ""; + + if (strstr($url, '?')) + { + $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 + { + if (ereg("/$", $url)) + { + $url = substr($url, 0, -1); + } + + $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; + } + else + { + return $tb_id; + } + } + + // -------------------------------------------------------------------- + + /** + * Convert Reserved XML characters to Entities + * + * @access public + * @param string + * @return string + */ + 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); + + $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); + $str = preg_replace("/$temp(\w+);/","&\\1;", $str); + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Character limiter + * + * Limits the string based on the character count. Will preserve complete words. + * + * @access public + * @param string + * @param integer + * @param string + * @return string + */ + function limit_characters($str, $n = 500, $end_char = '…') + { + if (strlen($str) < $n) + { + return $str; + } + + $str = preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $str)); + + if (strlen($str) <= $n) + { + return $str; + } + + $out = ""; + foreach (explode(' ', trim($str)) as $val) + { + $out .= $val.' '; + if (strlen($out) >= $n) + { + return trim($out).$end_char; + } + } + } + + // -------------------------------------------------------------------- + + /** + * High ASCII to Entities + * + * Converts Hight ascii text and MS Word special chars + * to character entities + * + * @access public + * @param string + * @return string + */ + 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; + } + + // -------------------------------------------------------------------- + + /** + * Set error message + * + * @access public + * @param string + * @return void + */ + function set_error($msg) + { + log_message('error', $msg); + $this->error_msg[] = $msg; + } + + // -------------------------------------------------------------------- + + /** + * Show error messages + * + * @access public + * @param string + * @param string + * @return string + */ + function display_errors($open = '

', $close = '

') + { + $str = ''; + foreach ($this->error_msg as $val) + { + $str .= $open.$val.$close; + } + + return $str; + } + +} +// END Trackback Class ?> \ No newline at end of file diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 10654a69c..5cedd8e0f 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -1,367 +1,367 @@ -router =& load_class('Router'); - log_message('debug', "URI Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Fetch a URI Segment - * - * This function returns the URI segment based on the number provided. - * - * @access public - * @param integer - * @param bool - * @return string - */ - function segment($n, $no_result = FALSE) - { - return ( ! isset($this->router->segments[$n])) ? $no_result : $this->router->segments[$n]; - } - - // -------------------------------------------------------------------- - - /** - * Fetch a URI "routed" Segment - * - * This function returns the re-routed URI segment (assuming routing rules are used) - * based on the number provided. If there is no routing this function returns the - * same result as $this->segment() - * - * @access public - * @param integer - * @param bool - * @return string - */ - function rsegment($n, $no_result = FALSE) - { - return ( ! isset($this->router->rsegments[$n])) ? $no_result : $this->router->rsegments[$n]; - } - - // -------------------------------------------------------------------- - - /** - * Generate a key value pair from the URI string - * - * This function generates and associative array of URI data starting - * at the supplied segment. For example, if this is your URI: - * - * www.your-site.com/user/search/name/joe/location/UK/gender/male - * - * You can use this function to generate an array with this prototype: - * - * array ( - * name => joe - * location => UK - * gender => male - * ) - * - * @access public - * @param integer the starting segment number - * @param array an array of default values - * @return array - */ - function uri_to_assoc($n = 3, $default = array()) - { - return $this->_uri_to_assoc($n, $default, 'segment'); - } - /** - * Identical to above only it uses the re-routed segment array - * - */ - function ruri_to_assoc($n = 3, $default = array()) - { - return $this->_uri_to_assoc($n, $default, 'rsegment'); - } - - // -------------------------------------------------------------------- - - /** - * Generate a key value pair from the URI string or Re-routed URI string - * - * @access private - * @param integer the starting segment number - * @param array an array of default values - * @param string which array we should use - * @return array - */ - function _uri_to_assoc($n = 3, $default = array(), $which = 'segment') - { - if ($which == 'segment') - { - $total_segments = 'total_segments'; - $segment_array = 'segment_array'; - } - else - { - $total_segments = 'total_rsegments'; - $segment_array = 'rsegment_array'; - } - - if ( ! is_numeric($n)) - { - return $default; - } - - if (isset($this->keyval[$n])) - { - return $this->keyval[$n]; - } - - if ($this->$total_segments() < $n) - { - if (count($default) == 0) - { - return array(); - } - - $retval = array(); - foreach ($default as $val) - { - $retval[$val] = FALSE; - } - return $retval; - } - - $segments = array_slice($this->$segment_array(), ($n - 1)); - - $i = 0; - $lastval = ''; - $retval = array(); - foreach ($segments as $seg) - { - if ($i % 2) - { - $retval[$lastval] = $seg; - } - else - { - $retval[$seg] = FALSE; - $lastval = $seg; - } - - $i++; - } - - if (count($default) > 0) - { - foreach ($default as $val) - { - if ( ! array_key_exists($val, $retval)) - { - $retval[$val] = FALSE; - } - } - } - - // Cache the array for reuse - $this->keyval[$n] = $retval; - return $retval; - } - - /** - * Generate a URI string from an associative array - * - * - * @access public - * @param array an associative array of key/values - * @return array - */ function assoc_to_uri($array) - { - $temp = array(); - foreach ((array)$array as $key => $val) - { - $temp[] = $key; - $temp[] = $val; - } - - return implode('/', $temp); - } - - // -------------------------------------------------------------------- - - /** - * Fetch a URI Segment and add a trailing slash - * - * @access public - * @param integer - * @param string - * @return string - */ - function slash_segment($n, $where = 'trailing') - { - return $this->_slash_segment($n, $where, 'segment'); - } - - // -------------------------------------------------------------------- - - /** - * Fetch a URI Segment and add a trailing slash - * - * @access public - * @param integer - * @param string - * @return string - */ - function slash_rsegment($n, $where = 'trailing') - { - return $this->_slash_segment($n, $where, 'rsegment'); - } - - // -------------------------------------------------------------------- - - /** - * Fetch a URI Segment and add a trailing slash - helper function - * - * @access private - * @param integer - * @param string - * @param string - * @return string - */ - function _slash_segment($n, $where = 'trailing', $which = 'segment') - { - if ($where == 'trailing') - { - $trailing = '/'; - $leading = ''; - } - elseif ($where == 'leading') - { - $leading = '/'; - $trailing = ''; - } - else - { - $leading = '/'; - $trailing = '/'; - } - return $leading.$this->$which($n).$trailing; - } - - // -------------------------------------------------------------------- - - /** - * Segment Array - * - * @access public - * @return array - */ - function segment_array() - { - return $this->router->segments; - } - - // -------------------------------------------------------------------- - - /** - * Routed Segment Array - * - * @access public - * @return array - */ - function rsegment_array() - { - return $this->router->rsegments; - } - - // -------------------------------------------------------------------- - - /** - * Total number of segments - * - * @access public - * @return integer - */ - function total_segments() - { - return count($this->router->segments); - } - - // -------------------------------------------------------------------- - - /** - * Total number of routed segments - * - * @access public - * @return integer - */ - function total_rsegments() - { - return count($this->router->rsegments); - } - - // -------------------------------------------------------------------- - - /** - * Fetch the entire URI string - * - * @access public - * @return string - */ - function uri_string() - { - return $this->router->uri_string; - } - - - // -------------------------------------------------------------------- - - /** - * Fetch the entire Re-routed URI string - * - * @access public - * @return string - */ - function ruri_string() - { - return '/'.implode('/', $this->rsegment_array()).'/'; - } - -} -// END URI Class +router =& load_class('Router'); + log_message('debug', "URI Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Fetch a URI Segment + * + * This function returns the URI segment based on the number provided. + * + * @access public + * @param integer + * @param bool + * @return string + */ + function segment($n, $no_result = FALSE) + { + return ( ! isset($this->router->segments[$n])) ? $no_result : $this->router->segments[$n]; + } + + // -------------------------------------------------------------------- + + /** + * Fetch a URI "routed" Segment + * + * This function returns the re-routed URI segment (assuming routing rules are used) + * based on the number provided. If there is no routing this function returns the + * same result as $this->segment() + * + * @access public + * @param integer + * @param bool + * @return string + */ + function rsegment($n, $no_result = FALSE) + { + return ( ! isset($this->router->rsegments[$n])) ? $no_result : $this->router->rsegments[$n]; + } + + // -------------------------------------------------------------------- + + /** + * Generate a key value pair from the URI string + * + * This function generates and associative array of URI data starting + * at the supplied segment. For example, if this is your URI: + * + * www.your-site.com/user/search/name/joe/location/UK/gender/male + * + * You can use this function to generate an array with this prototype: + * + * array ( + * name => joe + * location => UK + * gender => male + * ) + * + * @access public + * @param integer the starting segment number + * @param array an array of default values + * @return array + */ + function uri_to_assoc($n = 3, $default = array()) + { + return $this->_uri_to_assoc($n, $default, 'segment'); + } + /** + * Identical to above only it uses the re-routed segment array + * + */ + function ruri_to_assoc($n = 3, $default = array()) + { + return $this->_uri_to_assoc($n, $default, 'rsegment'); + } + + // -------------------------------------------------------------------- + + /** + * Generate a key value pair from the URI string or Re-routed URI string + * + * @access private + * @param integer the starting segment number + * @param array an array of default values + * @param string which array we should use + * @return array + */ + function _uri_to_assoc($n = 3, $default = array(), $which = 'segment') + { + if ($which == 'segment') + { + $total_segments = 'total_segments'; + $segment_array = 'segment_array'; + } + else + { + $total_segments = 'total_rsegments'; + $segment_array = 'rsegment_array'; + } + + if ( ! is_numeric($n)) + { + return $default; + } + + if (isset($this->keyval[$n])) + { + return $this->keyval[$n]; + } + + if ($this->$total_segments() < $n) + { + if (count($default) == 0) + { + return array(); + } + + $retval = array(); + foreach ($default as $val) + { + $retval[$val] = FALSE; + } + return $retval; + } + + $segments = array_slice($this->$segment_array(), ($n - 1)); + + $i = 0; + $lastval = ''; + $retval = array(); + foreach ($segments as $seg) + { + if ($i % 2) + { + $retval[$lastval] = $seg; + } + else + { + $retval[$seg] = FALSE; + $lastval = $seg; + } + + $i++; + } + + if (count($default) > 0) + { + foreach ($default as $val) + { + if ( ! array_key_exists($val, $retval)) + { + $retval[$val] = FALSE; + } + } + } + + // Cache the array for reuse + $this->keyval[$n] = $retval; + return $retval; + } + + /** + * Generate a URI string from an associative array + * + * + * @access public + * @param array an associative array of key/values + * @return array + */ function assoc_to_uri($array) + { + $temp = array(); + foreach ((array)$array as $key => $val) + { + $temp[] = $key; + $temp[] = $val; + } + + return implode('/', $temp); + } + + // -------------------------------------------------------------------- + + /** + * Fetch a URI Segment and add a trailing slash + * + * @access public + * @param integer + * @param string + * @return string + */ + function slash_segment($n, $where = 'trailing') + { + return $this->_slash_segment($n, $where, 'segment'); + } + + // -------------------------------------------------------------------- + + /** + * Fetch a URI Segment and add a trailing slash + * + * @access public + * @param integer + * @param string + * @return string + */ + function slash_rsegment($n, $where = 'trailing') + { + return $this->_slash_segment($n, $where, 'rsegment'); + } + + // -------------------------------------------------------------------- + + /** + * Fetch a URI Segment and add a trailing slash - helper function + * + * @access private + * @param integer + * @param string + * @param string + * @return string + */ + function _slash_segment($n, $where = 'trailing', $which = 'segment') + { + if ($where == 'trailing') + { + $trailing = '/'; + $leading = ''; + } + elseif ($where == 'leading') + { + $leading = '/'; + $trailing = ''; + } + else + { + $leading = '/'; + $trailing = '/'; + } + return $leading.$this->$which($n).$trailing; + } + + // -------------------------------------------------------------------- + + /** + * Segment Array + * + * @access public + * @return array + */ + function segment_array() + { + return $this->router->segments; + } + + // -------------------------------------------------------------------- + + /** + * Routed Segment Array + * + * @access public + * @return array + */ + function rsegment_array() + { + return $this->router->rsegments; + } + + // -------------------------------------------------------------------- + + /** + * Total number of segments + * + * @access public + * @return integer + */ + function total_segments() + { + return count($this->router->segments); + } + + // -------------------------------------------------------------------- + + /** + * Total number of routed segments + * + * @access public + * @return integer + */ + function total_rsegments() + { + return count($this->router->rsegments); + } + + // -------------------------------------------------------------------- + + /** + * Fetch the entire URI string + * + * @access public + * @return string + */ + function uri_string() + { + return $this->router->uri_string; + } + + + // -------------------------------------------------------------------- + + /** + * Fetch the entire Re-routed URI string + * + * @access public + * @return string + */ + function ruri_string() + { + return '/'.implode('/', $this->rsegment_array()).'/'; + } + +} +// END URI Class ?> \ No newline at end of file diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index f68f69e71..74ed1275f 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -1,331 +1,331 @@ -active == FALSE) - return FALSE; - - if (in_array($expected, array('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; - $extype = str_replace(array('true', 'false'), 'bool', str_replace('is_', '', $expected)); - } - else - { - if ($this->strict == TRUE) - $result = ($test === $expected) ? TRUE : FALSE; - else - $result = ($test == $expected) ? TRUE : FALSE; - - $extype = gettype($expected); - } - - $back = $this->_backtrace(); - - $report[] = array ( - 'test_name' => $test_name, - 'test_datatype' => gettype($test), - 'res_datatype' => $extype, - 'result' => ($result === TRUE) ? 'passed' : 'failed', - 'file' => $back['file'], - 'line' => $back['line'] - ); - - $this->results[] = $report; - - return($this->report($this->result($report))); - } - - // -------------------------------------------------------------------- - - /** - * Generate a report - * - * Displays a table with the test data - * - * @access public - * @return string - */ - function report($result = array()) - { - if (count($result) == 0) - { - $result = $this->result(); - } - - $this->_parse_template(); - - $r = ''; - foreach ($result as $res) - { - $table = ''; - - foreach ($res as $key => $val) - { - $temp = $this->_template_rows; - $temp = str_replace('{item}', $key, $temp); - $temp = str_replace('{result}', $val, $temp); - $table .= $temp; - } - - $r .= str_replace('{rows}', $table, $this->_template); - } - - return $r; - } - - // -------------------------------------------------------------------- - - /** - * Use strict comparison - * - * Causes the evaluation to use === rather then == - * - * @access public - * @param bool - * @return null - */ - function use_strict($state = TRUE) - { - $this->strict = ($state == FALSE) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Make Unit testing active - * - * Enables/disables unit testing - * - * @access public - * @param bool - * @return null - */ - function active($state = TRUE) - { - $this->active = ($state == FALSE) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Result Array - * - * Returns the raw result data - * - * @access public - * @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) - { - $temp = array(); - foreach ($result as $key => $val) - { - if (is_array($val)) - { - foreach ($val as $k => $v) - { - if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$v)))) - { - $v = $line; - } - $temp[$CI->lang->line('ut_'.$k)] = $v; - } - } - else - { - 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 - * - * This lets us set the template to be used to display results - * - * @access public - * @param string - * @return void - */ - function set_template($template) - { - $this->_template = $template; - } - - // -------------------------------------------------------------------- - - /** - * Generate a backtrace - * - * This lets us show file names and line numbers - * - * @access private - * @return array - */ - function _backtrace() - { - 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 - * - * @access private - * @return string - */ - function _default_template() - { - $this->_template = ' -
- - {rows} -
'; - - $this->_template_rows = ' - - {item} - {result} - - '; - } - - // -------------------------------------------------------------------- - - /** - * Parse Template - * - * Harvests the data within the template {pseudo-variables} - * - * @access private - * @return void - */ - 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->_template_rows = $match['1']; - $this->_template = str_replace($match['0'], '{rows}', $this->_template); - } - -} -// END Unit_test Class - -/** - * Helper functions to test boolean true/false - * - * - * @access private - * @return bool - */ -function is_true($test) -{ - return (is_bool($test) AND $test === TRUE) ? TRUE : FALSE; -} -function is_false($test) -{ - return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; -} - +active == FALSE) + return FALSE; + + if (in_array($expected, array('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; + $extype = str_replace(array('true', 'false'), 'bool', str_replace('is_', '', $expected)); + } + else + { + if ($this->strict == TRUE) + $result = ($test === $expected) ? TRUE : FALSE; + else + $result = ($test == $expected) ? TRUE : FALSE; + + $extype = gettype($expected); + } + + $back = $this->_backtrace(); + + $report[] = array ( + 'test_name' => $test_name, + 'test_datatype' => gettype($test), + 'res_datatype' => $extype, + 'result' => ($result === TRUE) ? 'passed' : 'failed', + 'file' => $back['file'], + 'line' => $back['line'] + ); + + $this->results[] = $report; + + return($this->report($this->result($report))); + } + + // -------------------------------------------------------------------- + + /** + * Generate a report + * + * Displays a table with the test data + * + * @access public + * @return string + */ + function report($result = array()) + { + if (count($result) == 0) + { + $result = $this->result(); + } + + $this->_parse_template(); + + $r = ''; + foreach ($result as $res) + { + $table = ''; + + foreach ($res as $key => $val) + { + $temp = $this->_template_rows; + $temp = str_replace('{item}', $key, $temp); + $temp = str_replace('{result}', $val, $temp); + $table .= $temp; + } + + $r .= str_replace('{rows}', $table, $this->_template); + } + + return $r; + } + + // -------------------------------------------------------------------- + + /** + * Use strict comparison + * + * Causes the evaluation to use === rather then == + * + * @access public + * @param bool + * @return null + */ + function use_strict($state = TRUE) + { + $this->strict = ($state == FALSE) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Make Unit testing active + * + * Enables/disables unit testing + * + * @access public + * @param bool + * @return null + */ + function active($state = TRUE) + { + $this->active = ($state == FALSE) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Result Array + * + * Returns the raw result data + * + * @access public + * @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) + { + $temp = array(); + foreach ($result as $key => $val) + { + if (is_array($val)) + { + foreach ($val as $k => $v) + { + if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$v)))) + { + $v = $line; + } + $temp[$CI->lang->line('ut_'.$k)] = $v; + } + } + else + { + 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 + * + * This lets us set the template to be used to display results + * + * @access public + * @param string + * @return void + */ + function set_template($template) + { + $this->_template = $template; + } + + // -------------------------------------------------------------------- + + /** + * Generate a backtrace + * + * This lets us show file names and line numbers + * + * @access private + * @return array + */ + function _backtrace() + { + 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 + * + * @access private + * @return string + */ + function _default_template() + { + $this->_template = ' +
+ + {rows} +
'; + + $this->_template_rows = ' + + {item} + {result} + + '; + } + + // -------------------------------------------------------------------- + + /** + * Parse Template + * + * Harvests the data within the template {pseudo-variables} + * + * @access private + * @return void + */ + 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->_template_rows = $match['1']; + $this->_template = str_replace($match['0'], '{rows}', $this->_template); + } + +} +// END Unit_test Class + +/** + * Helper functions to test boolean true/false + * + * + * @access private + * @return bool + */ +function is_true($test) +{ + return (is_bool($test) AND $test === TRUE) ? TRUE : FALSE; +} +function is_false($test) +{ + return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; +} + ?> \ No newline at end of file diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index ff0fb1cb9..564e29937 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -1,809 +1,809 @@ - 0) - { - $this->initialize($props); - } - - log_message('debug', "Upload Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize preferences - * - * @access public - * @param array - * @return void - */ - function initialize($config = array()) - { - $defaults = array( - 'max_size' => 0, - 'max_width' => 0, - 'max_height' => 0, - 'allowed_types' => "", - 'file_temp' => "", - 'file_name' => "", - 'orig_name' => "", - 'file_type' => "", - 'file_size' => "", - 'file_ext' => "", - 'upload_path' => "", - 'overwrite' => FALSE, - 'encrypt_name' => FALSE, - 'is_image' => FALSE, - 'image_width' => '', - 'image_height' => '', - 'image_type' => '', - 'image_size_str' => '', - 'error_msg' => array(), - 'mimes' => array(), - 'remove_spaces' => TRUE, - 'xss_clean' => FALSE, - 'temp_prefix' => "temp_file_" - ); - - - foreach ($defaults as $key => $val) - { - if (isset($config[$key])) - { - $method = 'set_'.$key; - if (method_exists($this, $method)) - { - $this->$method($config[$key]); - } - else - { - $this->$key = $config[$key]; - } - } - else - { - $this->$key = $val; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Perform the file upload - * - * @access public - * @return bool - */ - function do_upload($field = 'userfile') - { - // Is $_FILES[$field] set? If not, no reason to continue. - if ( ! isset($_FILES[$field])) - { - $this->set_error('upload_userfile_not_set'); - return FALSE; - } - - // Is the upload path valid? - if ( ! $this->validate_upload_path()) - { - return FALSE; - } - - // Was the file able to be uploaded? If not, determine the reason why. - if ( ! is_uploaded_file($_FILES[$field]['tmp_name'])) - { - $error = ( ! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error']; - - switch($error) - { - case 1 : $this->set_error('upload_file_exceeds_limit'); - break; - case 3 : $this->set_error('upload_file_partial'); - break; - case 4 : $this->set_error('upload_no_file_selected'); - break; - default : $this->set_error('upload_no_file_selected'); - break; - } - - return FALSE; - } - - // Set the uploaded data as class variables - $this->file_temp = $_FILES[$field]['tmp_name']; - $this->file_name = $_FILES[$field]['name']; - $this->file_size = $_FILES[$field]['size']; - $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']); - $this->file_type = strtolower($this->file_type); - $this->file_ext = $this->get_extension($_FILES[$field]['name']); - - // Convert the file size to kilobytes - if ($this->file_size > 0) - { - $this->file_size = round($this->file_size/1024, 2); - } - - // Is the file type allowed to be uploaded? - if ( ! $this->is_allowed_filetype()) - { - $this->set_error('upload_invalid_filetype'); - return FALSE; - } - - // Is the file size within the allowed maximum? - if ( ! $this->is_allowed_filesize()) - { - $this->set_error('upload_invalid_filesize'); - return FALSE; - } - - // Are the image dimensions within the allowed size? - // Note: This can fail if the server has an open_basdir restriction. - if ( ! $this->is_allowed_dimensions()) - { - $this->set_error('upload_invalid_dimensions'); - return FALSE; - } - - // Sanitize the file name for security - $this->file_name = $this->clean_file_name($this->file_name); - - // Remove white spaces in the name - if ($this->remove_spaces == TRUE) - { - $this->file_name = preg_replace("/\s+/", "_", $this->file_name); - } - - /* - * Validate the file name - * This function appends an number onto the end of - * the file if one with the same name already exists. - * If it returns false there was a problem. - */ - $this->orig_name = $this->file_name; - - if ($this->overwrite == FALSE) - { - $this->file_name = $this->set_filename($this->upload_path, $this->file_name); - - if ($this->file_name === FALSE) - { - return FALSE; - } - } - - /* - * Move the file to the final destination - * To deal with different server configurations - * we'll attempt to use copy() first. If that fails - * we'll use move_uploaded_file(). One of the two should - * reliably work in most environments - */ - if ( ! @copy($this->file_temp, $this->upload_path.$this->file_name)) - { - if ( ! @move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name)) - { - $this->set_error('upload_destination_error'); - return FALSE; - } - } - - /* - * Run the file through the XSS hacking filter - * This helps prevent malicious code from being - * embedded within a file. Scripts can easily - * be disguised as images or other file types. - */ - if ($this->xss_clean == TRUE) - { - $this->do_xss_clean(); - } - - /* - * Set the finalized image dimensions - * This sets the image width/height (assuming the - * file was an image). We use this information - * in the "data" function. - */ - $this->set_image_properties($this->upload_path.$this->file_name); - - 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 ( - 'file_name' => $this->file_name, - 'file_type' => $this->file_type, - 'file_path' => $this->upload_path, - 'full_path' => $this->upload_path.$this->file_name, - 'raw_name' => str_replace($this->file_ext, '', $this->file_name), - 'orig_name' => $this->orig_name, - 'file_ext' => $this->file_ext, - 'file_size' => $this->file_size, - 'is_image' => $this->is_image(), - 'image_width' => $this->image_width, - 'image_height' => $this->image_height, - 'image_type' => $this->image_type, - 'image_size_str' => $this->image_size_str, - ); - } - - // -------------------------------------------------------------------- - - /** - * Set Upload Path - * - * @access public - * @param string - * @return void - */ - function set_upload_path($path) - { - $this->upload_path = $path; - } - - // -------------------------------------------------------------------- - - /** - * Set the file name - * - * This function takes a filename/path as input and looks for the - * existence of a file with the same name. If found, it will append a - * number to the end of the filename to avoid overwriting a pre-existing file. - * - * @access public - * @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; - } - - 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; - break; - } - } - - if ($new_filename == '') - { - $this->set_error('upload_bad_filename'); - return FALSE; - } - else - { - return $new_filename; - } - } - - // -------------------------------------------------------------------- - - /** - * Set Maximum File Size - * - * @access public - * @param integer - * @return void - */ - function set_max_filesize($n) - { - $this->max_size = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; - } - - // -------------------------------------------------------------------- - - /** - * Set Maximum Image Width - * - * @access public - * @param integer - * @return void - */ - function set_max_width($n) - { - $this->max_width = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; - } - - // -------------------------------------------------------------------- - - /** - * Set Maximum Image Height - * - * @access public - * @param integer - * @return void - */ - function set_max_height($n) - { - $this->max_height = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; - } - - // -------------------------------------------------------------------- - - /** - * Set Allowed File Types - * - * @access public - * @param string - * @return void - */ - function set_allowed_types($types) - { - $this->allowed_types = explode('|', $types); - } - - // -------------------------------------------------------------------- - - /** - * Set Image Properties - * - * Uses GD to determine the width/height/type of image - * - * @access public - * @param string - * @return void - */ - function set_image_properties($path = '') - { - if ( ! $this->is_image()) - { - return; - } - - if (function_exists('getimagesize')) - { - if (FALSE !== ($D = @getimagesize($path))) - { - $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); - - $this->image_width = $D['0']; - $this->image_height = $D['1']; - $this->image_type = ( ! isset($types[$D['2']])) ? 'unknown' : $types[$D['2']]; - $this->image_size_str = $D['3']; // string containing height and width - } - } - } - - // -------------------------------------------------------------------- - - /** - * Set XSS Clean - * - * Enables the XSS flag so that the file that was uploaded - * will be run through the XSS filter. - * - * @access public - * @param bool - * @return void - */ - function set_xss_clean($flag = FALSE) - { - $this->xss_clean = ($flag == TRUE) ? TRUE : FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Validate the image - * - * @access public - * @return bool - */ - function is_image() - { - $img_mimes = array( - 'image/gif', - 'image/jpg', - 'image/jpe', - 'image/jpeg', - 'image/pjpeg', - 'image/png', - 'image/x-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() - { - if (count($this->allowed_types) == 0) - { - $this->set_error('upload_no_file_types'); - return FALSE; - } - - foreach ($this->allowed_types as $val) - { - $mime = $this->mimes_types(strtolower($val)); - - if (is_array($mime)) - { - if (in_array($this->file_type, $mime, TRUE)) - { - return TRUE; - } - } - else - { - if ($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) - { - return FALSE; - } - else - { - return TRUE; - } - } - - // -------------------------------------------------------------------- - - /** - * Verify that the image is within the allowed width/height - * - * @access public - * @return bool - */ - function is_allowed_dimensions() - { - if ( ! $this->is_image()) - { - return TRUE; - } - - if (function_exists('getimagesize')) - { - $D = @getimagesize($this->file_temp); - - if ($this->max_width > 0 AND $D['0'] > $this->max_width) - { - return FALSE; - } - - if ($this->max_height > 0 AND $D['1'] > $this->max_height) - { - return FALSE; - } - - return TRUE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Validate Upload Path - * - * Verifies that it is a valid upload path with proper permissions. - * - * - * @access public - * @return bool - */ - function validate_upload_path() - { - if ($this->upload_path == '') - { - $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)); - } - - if ( ! @is_dir($this->upload_path)) - { - $this->set_error('upload_no_filepath'); - return FALSE; - } - - if ( ! is_writable($this->upload_path)) - { - $this->set_error('upload_not_writable'); - return FALSE; - } - - $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( - "", - "'", - "<", - ">", - '"', - '&', - '$', - '=', - ';', - '?', - '/', - "%20", - "%22", - "%3c", // < - "%253c", // < - "%3e", // > - "%0e", // > - "%28", // ( - "%29", // ) - "%2528", // ( - "%26", // & - "%24", // $ - "%3f", // ? - "%3b", // ; - "%3d" // = - ); - - foreach ($bad as $val) - { - $filename = str_replace($val, '', $filename); - } - - return $filename; - } - - // -------------------------------------------------------------------- - - /** - * Runs the file through the XSS clean function - * - * This prevents people from embedding malicious code in their files. - * I'm not sure that it won't negatively affect certain files in unexpected ways, - * but so far I haven't found that it causes trouble. - * - * @access public - * @return void - */ - function do_xss_clean() - { - $file = $this->upload_path.$this->file_name; - - if (filesize($file) == 0) - { - return FALSE; - } - - if ( ! $fp = @fopen($file, 'rb')) - { - return FALSE; - } - - flock($fp, LOCK_EX); - - $data = fread($fp, filesize($file)); - - $CI =& get_instance(); - $data = $CI->input->xss_clean($data); - - fwrite($fp, $data); - flock($fp, LOCK_UN); - fclose($fp); - } - - // -------------------------------------------------------------------- - - /** - * Set an error message - * - * @access public - * @param string - * @return void - */ - function set_error($msg) - { - $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); - $this->error_msg[] = $msg; - log_message('error', $msg); - } - } - else - { - $msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg); - $this->error_msg[] = $msg; - log_message('error', $msg); - } - } - - // -------------------------------------------------------------------- - - /** - * Display the error message - * - * @access public - * @param string - * @param string - * @return string - */ - function display_errors($open = '

', $close = '

') - { - $str = ''; - foreach ($this->error_msg as $val) - { - $str .= $open.$val.$close; - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * List of Mime Types - * - * This is a list of mime types. We use it to validate - * the "allowed types" set by the developer - * - * @access public - * @param string - * @return string - */ - function mimes_types($mime) - { - if (count($this->mimes) == 0) - { - if (@include(APPPATH.'config/mimes'.EXT)) - { - $this->mimes = $mimes; - unset($mimes); - } - } - - return ( ! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime]; - } - -} -// END Upload Class + 0) + { + $this->initialize($props); + } + + log_message('debug', "Upload Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Initialize preferences + * + * @access public + * @param array + * @return void + */ + function initialize($config = array()) + { + $defaults = array( + 'max_size' => 0, + 'max_width' => 0, + 'max_height' => 0, + 'allowed_types' => "", + 'file_temp' => "", + 'file_name' => "", + 'orig_name' => "", + 'file_type' => "", + 'file_size' => "", + 'file_ext' => "", + 'upload_path' => "", + 'overwrite' => FALSE, + 'encrypt_name' => FALSE, + 'is_image' => FALSE, + 'image_width' => '', + 'image_height' => '', + 'image_type' => '', + 'image_size_str' => '', + 'error_msg' => array(), + 'mimes' => array(), + 'remove_spaces' => TRUE, + 'xss_clean' => FALSE, + 'temp_prefix' => "temp_file_" + ); + + + foreach ($defaults as $key => $val) + { + if (isset($config[$key])) + { + $method = 'set_'.$key; + if (method_exists($this, $method)) + { + $this->$method($config[$key]); + } + else + { + $this->$key = $config[$key]; + } + } + else + { + $this->$key = $val; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Perform the file upload + * + * @access public + * @return bool + */ + function do_upload($field = 'userfile') + { + // Is $_FILES[$field] set? If not, no reason to continue. + if ( ! isset($_FILES[$field])) + { + $this->set_error('upload_userfile_not_set'); + return FALSE; + } + + // Is the upload path valid? + if ( ! $this->validate_upload_path()) + { + return FALSE; + } + + // Was the file able to be uploaded? If not, determine the reason why. + if ( ! is_uploaded_file($_FILES[$field]['tmp_name'])) + { + $error = ( ! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error']; + + switch($error) + { + case 1 : $this->set_error('upload_file_exceeds_limit'); + break; + case 3 : $this->set_error('upload_file_partial'); + break; + case 4 : $this->set_error('upload_no_file_selected'); + break; + default : $this->set_error('upload_no_file_selected'); + break; + } + + return FALSE; + } + + // Set the uploaded data as class variables + $this->file_temp = $_FILES[$field]['tmp_name']; + $this->file_name = $_FILES[$field]['name']; + $this->file_size = $_FILES[$field]['size']; + $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']); + $this->file_type = strtolower($this->file_type); + $this->file_ext = $this->get_extension($_FILES[$field]['name']); + + // Convert the file size to kilobytes + if ($this->file_size > 0) + { + $this->file_size = round($this->file_size/1024, 2); + } + + // Is the file type allowed to be uploaded? + if ( ! $this->is_allowed_filetype()) + { + $this->set_error('upload_invalid_filetype'); + return FALSE; + } + + // Is the file size within the allowed maximum? + if ( ! $this->is_allowed_filesize()) + { + $this->set_error('upload_invalid_filesize'); + return FALSE; + } + + // Are the image dimensions within the allowed size? + // Note: This can fail if the server has an open_basdir restriction. + if ( ! $this->is_allowed_dimensions()) + { + $this->set_error('upload_invalid_dimensions'); + return FALSE; + } + + // Sanitize the file name for security + $this->file_name = $this->clean_file_name($this->file_name); + + // Remove white spaces in the name + if ($this->remove_spaces == TRUE) + { + $this->file_name = preg_replace("/\s+/", "_", $this->file_name); + } + + /* + * Validate the file name + * This function appends an number onto the end of + * the file if one with the same name already exists. + * If it returns false there was a problem. + */ + $this->orig_name = $this->file_name; + + if ($this->overwrite == FALSE) + { + $this->file_name = $this->set_filename($this->upload_path, $this->file_name); + + if ($this->file_name === FALSE) + { + return FALSE; + } + } + + /* + * Move the file to the final destination + * To deal with different server configurations + * we'll attempt to use copy() first. If that fails + * we'll use move_uploaded_file(). One of the two should + * reliably work in most environments + */ + if ( ! @copy($this->file_temp, $this->upload_path.$this->file_name)) + { + if ( ! @move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name)) + { + $this->set_error('upload_destination_error'); + return FALSE; + } + } + + /* + * Run the file through the XSS hacking filter + * This helps prevent malicious code from being + * embedded within a file. Scripts can easily + * be disguised as images or other file types. + */ + if ($this->xss_clean == TRUE) + { + $this->do_xss_clean(); + } + + /* + * Set the finalized image dimensions + * This sets the image width/height (assuming the + * file was an image). We use this information + * in the "data" function. + */ + $this->set_image_properties($this->upload_path.$this->file_name); + + 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 ( + 'file_name' => $this->file_name, + 'file_type' => $this->file_type, + 'file_path' => $this->upload_path, + 'full_path' => $this->upload_path.$this->file_name, + 'raw_name' => str_replace($this->file_ext, '', $this->file_name), + 'orig_name' => $this->orig_name, + 'file_ext' => $this->file_ext, + 'file_size' => $this->file_size, + 'is_image' => $this->is_image(), + 'image_width' => $this->image_width, + 'image_height' => $this->image_height, + 'image_type' => $this->image_type, + 'image_size_str' => $this->image_size_str, + ); + } + + // -------------------------------------------------------------------- + + /** + * Set Upload Path + * + * @access public + * @param string + * @return void + */ + function set_upload_path($path) + { + $this->upload_path = $path; + } + + // -------------------------------------------------------------------- + + /** + * Set the file name + * + * This function takes a filename/path as input and looks for the + * existence of a file with the same name. If found, it will append a + * number to the end of the filename to avoid overwriting a pre-existing file. + * + * @access public + * @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; + } + + 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; + break; + } + } + + if ($new_filename == '') + { + $this->set_error('upload_bad_filename'); + return FALSE; + } + else + { + return $new_filename; + } + } + + // -------------------------------------------------------------------- + + /** + * Set Maximum File Size + * + * @access public + * @param integer + * @return void + */ + function set_max_filesize($n) + { + $this->max_size = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + } + + // -------------------------------------------------------------------- + + /** + * Set Maximum Image Width + * + * @access public + * @param integer + * @return void + */ + function set_max_width($n) + { + $this->max_width = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + } + + // -------------------------------------------------------------------- + + /** + * Set Maximum Image Height + * + * @access public + * @param integer + * @return void + */ + function set_max_height($n) + { + $this->max_height = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + } + + // -------------------------------------------------------------------- + + /** + * Set Allowed File Types + * + * @access public + * @param string + * @return void + */ + function set_allowed_types($types) + { + $this->allowed_types = explode('|', $types); + } + + // -------------------------------------------------------------------- + + /** + * Set Image Properties + * + * Uses GD to determine the width/height/type of image + * + * @access public + * @param string + * @return void + */ + function set_image_properties($path = '') + { + if ( ! $this->is_image()) + { + return; + } + + if (function_exists('getimagesize')) + { + if (FALSE !== ($D = @getimagesize($path))) + { + $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); + + $this->image_width = $D['0']; + $this->image_height = $D['1']; + $this->image_type = ( ! isset($types[$D['2']])) ? 'unknown' : $types[$D['2']]; + $this->image_size_str = $D['3']; // string containing height and width + } + } + } + + // -------------------------------------------------------------------- + + /** + * Set XSS Clean + * + * Enables the XSS flag so that the file that was uploaded + * will be run through the XSS filter. + * + * @access public + * @param bool + * @return void + */ + function set_xss_clean($flag = FALSE) + { + $this->xss_clean = ($flag == TRUE) ? TRUE : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Validate the image + * + * @access public + * @return bool + */ + function is_image() + { + $img_mimes = array( + 'image/gif', + 'image/jpg', + 'image/jpe', + 'image/jpeg', + 'image/pjpeg', + 'image/png', + 'image/x-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() + { + if (count($this->allowed_types) == 0) + { + $this->set_error('upload_no_file_types'); + return FALSE; + } + + foreach ($this->allowed_types as $val) + { + $mime = $this->mimes_types(strtolower($val)); + + if (is_array($mime)) + { + if (in_array($this->file_type, $mime, TRUE)) + { + return TRUE; + } + } + else + { + if ($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) + { + return FALSE; + } + else + { + return TRUE; + } + } + + // -------------------------------------------------------------------- + + /** + * Verify that the image is within the allowed width/height + * + * @access public + * @return bool + */ + function is_allowed_dimensions() + { + if ( ! $this->is_image()) + { + return TRUE; + } + + if (function_exists('getimagesize')) + { + $D = @getimagesize($this->file_temp); + + if ($this->max_width > 0 AND $D['0'] > $this->max_width) + { + return FALSE; + } + + if ($this->max_height > 0 AND $D['1'] > $this->max_height) + { + return FALSE; + } + + return TRUE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Validate Upload Path + * + * Verifies that it is a valid upload path with proper permissions. + * + * + * @access public + * @return bool + */ + function validate_upload_path() + { + if ($this->upload_path == '') + { + $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)); + } + + if ( ! @is_dir($this->upload_path)) + { + $this->set_error('upload_no_filepath'); + return FALSE; + } + + if ( ! is_writable($this->upload_path)) + { + $this->set_error('upload_not_writable'); + return FALSE; + } + + $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( + "", + "'", + "<", + ">", + '"', + '&', + '$', + '=', + ';', + '?', + '/', + "%20", + "%22", + "%3c", // < + "%253c", // < + "%3e", // > + "%0e", // > + "%28", // ( + "%29", // ) + "%2528", // ( + "%26", // & + "%24", // $ + "%3f", // ? + "%3b", // ; + "%3d" // = + ); + + foreach ($bad as $val) + { + $filename = str_replace($val, '', $filename); + } + + return $filename; + } + + // -------------------------------------------------------------------- + + /** + * Runs the file through the XSS clean function + * + * This prevents people from embedding malicious code in their files. + * I'm not sure that it won't negatively affect certain files in unexpected ways, + * but so far I haven't found that it causes trouble. + * + * @access public + * @return void + */ + function do_xss_clean() + { + $file = $this->upload_path.$this->file_name; + + if (filesize($file) == 0) + { + return FALSE; + } + + if ( ! $fp = @fopen($file, 'rb')) + { + return FALSE; + } + + flock($fp, LOCK_EX); + + $data = fread($fp, filesize($file)); + + $CI =& get_instance(); + $data = $CI->input->xss_clean($data); + + fwrite($fp, $data); + flock($fp, LOCK_UN); + fclose($fp); + } + + // -------------------------------------------------------------------- + + /** + * Set an error message + * + * @access public + * @param string + * @return void + */ + function set_error($msg) + { + $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); + $this->error_msg[] = $msg; + log_message('error', $msg); + } + } + else + { + $msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg); + $this->error_msg[] = $msg; + log_message('error', $msg); + } + } + + // -------------------------------------------------------------------- + + /** + * Display the error message + * + * @access public + * @param string + * @param string + * @return string + */ + function display_errors($open = '

', $close = '

') + { + $str = ''; + foreach ($this->error_msg as $val) + { + $str .= $open.$val.$close; + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * List of Mime Types + * + * This is a list of mime types. We use it to validate + * the "allowed types" set by the developer + * + * @access public + * @param string + * @return string + */ + function mimes_types($mime) + { + if (count($this->mimes) == 0) + { + if (@include(APPPATH.'config/mimes'.EXT)) + { + $this->mimes = $mimes; + unset($mimes); + } + } + + return ( ! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime]; + } + +} +// END Upload Class ?> \ No newline at end of file diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index afd012e30..b93bd340e 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -1,12 +1,12 @@ '; - var $_error_suffix = '

'; - - - - /** - * Constructor - * - */ - function CI_Validation() - { - $this->CI =& get_instance(); - log_message('debug', "Validation Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Set Fields - * - * This function takes an array of field names as input - * and generates class variables with the same name, which will - * either be blank or contain the $_POST value corresponding to it - * - * @access public - * @param string - * @param string - * @return void - */ - function set_fields($data = '', $field = '') - { - if ($data == '') - { - if (count($this->_fields) == 0) - { - return FALSE; - } - } - else - { - if ( ! is_array($data)) - { - $data = array($data => $field); - } - - if (count($data) > 0) - { - $this->_fields = $data; - } - } - - foreach($this->_fields as $key => $val) - { - $this->$key = ( ! isset($_POST[$key]) OR is_array($_POST[$key])) ? '' : $this->prep_for_form($_POST[$key]); - - $error = $key.'_error'; - if ( ! isset($this->$error)) - { - $this->$error = ''; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Set Rules - * - * This function takes an array of field names and validation - * rules as input ad simply stores is for use later. - * - * @access public - * @param mixed - * @param string - * @return void - */ - function set_rules($data, $rules = '') - { - if ( ! is_array($data)) - { - if ($rules == '') - return; - - $data[$data] = $rules; - } - - foreach ($data as $key => $val) - { - $this->_rules[$key] = $val; - } - } - - // -------------------------------------------------------------------- - - /** - * Set Error Message - * - * Lets users set their own error messages on the fly. Note: The key - * name has to match the function name that it corresponds to. - * - * @access public - * @param string - * @param string - * @return string - */ - function set_message($lang, $val = '') - { - if ( ! is_array($lang)) - { - $lang = array($lang => $val); - } - - $this->_error_messages = array_merge($this->_error_messages, $lang); - } - - // -------------------------------------------------------------------- - - /** - * Set The Error Delimiter - * - * Permits a prefix/suffix to be added to each error message - * - * @access public - * @param string - * @param string - * @return void - */ - function set_error_delimiters($prefix = '

', $suffix = '

') - { - $this->_error_prefix = $prefix; - $this->_error_suffix = $suffix; - } - - // -------------------------------------------------------------------- - - /** - * Run the Validator - * - * This function does all the work. - * - * @access public - * @return bool - */ - function run() - { - // Do we even have any data to process? Mm? - if (count($_POST) == 0 OR count($this->_rules) == 0) - { - return FALSE; - } - - // Load the language file containing error messages - $this->CI->lang->load('validation'); - - // Cycle through the rules and test for errors - foreach ($this->_rules as $field => $rules) - { - //Explode out the rules! - $ex = explode('|', $rules); - - // Is the field required? If not, if the field is blank we'll move on to the next text - if ( ! in_array('required', $ex, TRUE) AND strpos($rules, 'callback_') === FALSE) - { - if ( ! isset($_POST[$field]) OR $_POST[$field] == '') - { - continue; - } - } - - /* - * Are we dealing with an "isset" rule? - * - * Before going further, we'll see if one of the rules - * is to check whether the item is set (typically this - * applies only to checkboxes). If so, we'll - * test for it here since there's not reason to go - * further - */ - if ( ! isset($_POST[$field])) - { - if (in_array('isset', $ex, TRUE) OR in_array('required', $ex)) - { - if ( ! isset($this->_error_messages['isset'])) - { - if (FALSE === ($line = $this->CI->lang->line('isset'))) - { - $line = 'The field was not set'; - } - } - else - { - $line = $this->_error_messages['isset']; - } - - $field = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; - $this->_error_array[] = sprintf($line, $field); - } - - continue; - } - - /* - * Set the current field - * - * The various prepping functions need to know the - * current field name so they can do this: - * - * $_POST[$this->_current_field] == 'bla bla'; - */ - $this->_current_field = $field; - - // Cycle through the rules! - foreach ($ex As $rule) - { - // 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; - if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match)) - { - $rule = $match[1]; - $param = $match[2]; - } - - // Call the function that corresponds to the rule - if ($callback === TRUE) - { - if ( ! method_exists($this->CI, $rule)) - { - continue; - } - - $result = $this->CI->$rule($_POST[$field], $param); - - // If the field isn't required and we just processed a callback we'll move on... - if ( ! in_array('required', $ex, TRUE) AND $result !== FALSE) - { - continue 2; - } - - } - else - { - if ( ! method_exists($this, $rule)) - { - /* - * Run the native PHP function if called for - * - * 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)) - { - $_POST[$field] = $rule($_POST[$field]); - $this->$field = $_POST[$field]; - } - - continue; - } - - $result = $this->$rule($_POST[$field], $param); - } - - // 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];; - } - - // Build the error message - $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; - $mparam = ( ! isset($this->_fields[$param])) ? $param : $this->_fields[$param]; - $message = sprintf($line, $mfield, $mparam); - - // Set the error variable. Example: $this->username_error - $error = $field.'_error'; - $this->$error = $this->_error_prefix.$message.$this->_error_suffix; - - // Add the error to the error array - $this->_error_array[] = $message; - continue 2; - } - } - - } - - $total_errors = count($this->_error_array); - - /* - * Recompile the class variables - * - * If any prepping functions were called the $_POST data - * might now be different then the corresponding class - * variables so we'll set them anew. - */ - if ($total_errors > 0) - { - $this->_safe_form_data = TRUE; - } - - $this->set_fields(); - - // Did we end up with any errors? - if ($total_errors == 0) - { - return TRUE; - } - - // Generate the error string - foreach ($this->_error_array as $val) - { - $this->error_string .= $this->_error_prefix.$val.$this->_error_suffix."\n"; - } - - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Required - * - * @access public - * @param string - * @return bool - */ - function required($str) - { - if ( ! is_array($str)) - { - return (trim($str) == '') ? FALSE : TRUE; - } - else - { - return ( ! empty($str)); - } - } - - // -------------------------------------------------------------------- - - /** - * Match one field to another - * - * @access public - * @param string - * @return bool - */ - function matches($str, $field) - { - if ( ! isset($_POST[$field])) - { - return FALSE; - } - - return ($str !== $_POST[$field]) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Minimum Length - * - * @access public - * @param string - * @return bool - */ - function min_length($str, $val) - { - if ( ! is_numeric($val)) - { - return FALSE; - } - - return (strlen($str) < $val) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Max Length - * - * @access public - * @param string - * @return bool - */ - function max_length($str, $val) - { - if ( ! is_numeric($val)) - { - return FALSE; - } - - return (strlen($str) > $val) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Exact Length - * - * @access public - * @param string - * @return bool - */ - function exact_length($str, $val) - { - if ( ! is_numeric($val)) - { - return FALSE; - } - - 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; - } - - // -------------------------------------------------------------------- - - /** - * Validate IP Address - * - * @access public - * @param string - * @return string - */ - function valid_ip($ip) - { - return ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * 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 int - * @return bool - */ - function numeric($str) - { - return ( ! ereg("^[0-9\.]+$", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Is Numeric - * - * @access public - * @param string - * @return bool - */ - function is_numeric($str) - { - return ( ! is_numeric($str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set Select - * - * Enables pull-down lists to be set to the value the user - * selected in the event of an error - * - * @access public - * @param string - * @param string - * @return string - */ - function set_select($field = '', $value = '') - { - if ($field == '' OR $value == '' OR ! isset($_POST[$field])) - { - return ''; - } - - if ($_POST[$field] == $value) - { - return ' selected="selected"'; - } - } - - // -------------------------------------------------------------------- - - /** - * Set Radio - * - * Enables radio buttons to be set to the value the user - * selected in the event of an error - * - * @access public - * @param string - * @param string - * @return string - */ - function set_radio($field = '', $value = '') - { - if ($field == '' OR $value == '' OR ! isset($_POST[$field])) - { - return ''; - } - - if ($_POST[$field] == $value) - { - return ' checked="checked"'; - } - } - - // -------------------------------------------------------------------- - - /** - * Set Checkbox - * - * Enables checkboxes to be set to the value the user - * selected in the event of an error - * - * @access public - * @param string - * @param string - * @return string - */ - function set_checkbox($field = '', $value = '') - { - if ($field == '' OR $value == '' OR ! isset($_POST[$field])) - { - return ''; - } - - if ($_POST[$field] == $value) - { - return ' checked="checked"'; - } - } - - // -------------------------------------------------------------------- - - /** - * Prep data for form - * - * This function allows HTML to be safely shown in a form. - * Special characters are converted. - * - * @access public - * @param string - * @return string - */ - function prep_for_form($str = '') - { - if ($this->_safe_form_data == FALSE OR $str == '') - { - return $str; - } - - return str_replace(array("'", '"', '<', '>'), array("'", """, '<', '>'), stripslashes($str)); - } - - // -------------------------------------------------------------------- - - /** - * Prep URL - * - * @access public - * @param string - * @return string - */ - function prep_url($str = '') - { - if ($str == 'http://' OR $str == '') - { - $_POST[$this->_current_field] = ''; - return; - } - - if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') - { - $str = 'http://'.$str; - } - - $_POST[$this->_current_field] = $str; - } - - // -------------------------------------------------------------------- - - /** - * Strip Image Tags - * - * @access public - * @param string - * @return string - */ - function strip_image_tags($str) - { - $_POST[$this->_current_field] = $this->input->strip_image_tags($str); - } - - // -------------------------------------------------------------------- - - /** - * XSS Clean - * - * @access public - * @param string - * @return string - */ - function xss_clean($str) - { - $_POST[$this->_current_field] = $this->CI->input->xss_clean($str); - } - - // -------------------------------------------------------------------- - - /** - * Convert PHP tags to entities - * - * @access public - * @param string - * @return string - */ - function encode_php_tags($str) - { - $_POST[$this->_current_field] = str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); - } - -} -// END Validation Class +'; + var $_error_suffix = '

'; + + + + /** + * Constructor + * + */ + function CI_Validation() + { + $this->CI =& get_instance(); + log_message('debug', "Validation Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Set Fields + * + * This function takes an array of field names as input + * and generates class variables with the same name, which will + * either be blank or contain the $_POST value corresponding to it + * + * @access public + * @param string + * @param string + * @return void + */ + function set_fields($data = '', $field = '') + { + if ($data == '') + { + if (count($this->_fields) == 0) + { + return FALSE; + } + } + else + { + if ( ! is_array($data)) + { + $data = array($data => $field); + } + + if (count($data) > 0) + { + $this->_fields = $data; + } + } + + foreach($this->_fields as $key => $val) + { + $this->$key = ( ! isset($_POST[$key]) OR is_array($_POST[$key])) ? '' : $this->prep_for_form($_POST[$key]); + + $error = $key.'_error'; + if ( ! isset($this->$error)) + { + $this->$error = ''; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Set Rules + * + * This function takes an array of field names and validation + * rules as input ad simply stores is for use later. + * + * @access public + * @param mixed + * @param string + * @return void + */ + function set_rules($data, $rules = '') + { + if ( ! is_array($data)) + { + if ($rules == '') + return; + + $data[$data] = $rules; + } + + foreach ($data as $key => $val) + { + $this->_rules[$key] = $val; + } + } + + // -------------------------------------------------------------------- + + /** + * Set Error Message + * + * Lets users set their own error messages on the fly. Note: The key + * name has to match the function name that it corresponds to. + * + * @access public + * @param string + * @param string + * @return string + */ + function set_message($lang, $val = '') + { + if ( ! is_array($lang)) + { + $lang = array($lang => $val); + } + + $this->_error_messages = array_merge($this->_error_messages, $lang); + } + + // -------------------------------------------------------------------- + + /** + * Set The Error Delimiter + * + * Permits a prefix/suffix to be added to each error message + * + * @access public + * @param string + * @param string + * @return void + */ + function set_error_delimiters($prefix = '

', $suffix = '

') + { + $this->_error_prefix = $prefix; + $this->_error_suffix = $suffix; + } + + // -------------------------------------------------------------------- + + /** + * Run the Validator + * + * This function does all the work. + * + * @access public + * @return bool + */ + function run() + { + // Do we even have any data to process? Mm? + if (count($_POST) == 0 OR count($this->_rules) == 0) + { + return FALSE; + } + + // Load the language file containing error messages + $this->CI->lang->load('validation'); + + // Cycle through the rules and test for errors + foreach ($this->_rules as $field => $rules) + { + //Explode out the rules! + $ex = explode('|', $rules); + + // Is the field required? If not, if the field is blank we'll move on to the next text + if ( ! in_array('required', $ex, TRUE) AND strpos($rules, 'callback_') === FALSE) + { + if ( ! isset($_POST[$field]) OR $_POST[$field] == '') + { + continue; + } + } + + /* + * Are we dealing with an "isset" rule? + * + * Before going further, we'll see if one of the rules + * is to check whether the item is set (typically this + * applies only to checkboxes). If so, we'll + * test for it here since there's not reason to go + * further + */ + if ( ! isset($_POST[$field])) + { + if (in_array('isset', $ex, TRUE) OR in_array('required', $ex)) + { + if ( ! isset($this->_error_messages['isset'])) + { + if (FALSE === ($line = $this->CI->lang->line('isset'))) + { + $line = 'The field was not set'; + } + } + else + { + $line = $this->_error_messages['isset']; + } + + $field = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; + $this->_error_array[] = sprintf($line, $field); + } + + continue; + } + + /* + * Set the current field + * + * The various prepping functions need to know the + * current field name so they can do this: + * + * $_POST[$this->_current_field] == 'bla bla'; + */ + $this->_current_field = $field; + + // Cycle through the rules! + foreach ($ex As $rule) + { + // 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; + if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match)) + { + $rule = $match[1]; + $param = $match[2]; + } + + // Call the function that corresponds to the rule + if ($callback === TRUE) + { + if ( ! method_exists($this->CI, $rule)) + { + continue; + } + + $result = $this->CI->$rule($_POST[$field], $param); + + // If the field isn't required and we just processed a callback we'll move on... + if ( ! in_array('required', $ex, TRUE) AND $result !== FALSE) + { + continue 2; + } + + } + else + { + if ( ! method_exists($this, $rule)) + { + /* + * Run the native PHP function if called for + * + * 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)) + { + $_POST[$field] = $rule($_POST[$field]); + $this->$field = $_POST[$field]; + } + + continue; + } + + $result = $this->$rule($_POST[$field], $param); + } + + // 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];; + } + + // Build the error message + $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; + $mparam = ( ! isset($this->_fields[$param])) ? $param : $this->_fields[$param]; + $message = sprintf($line, $mfield, $mparam); + + // Set the error variable. Example: $this->username_error + $error = $field.'_error'; + $this->$error = $this->_error_prefix.$message.$this->_error_suffix; + + // Add the error to the error array + $this->_error_array[] = $message; + continue 2; + } + } + + } + + $total_errors = count($this->_error_array); + + /* + * Recompile the class variables + * + * If any prepping functions were called the $_POST data + * might now be different then the corresponding class + * variables so we'll set them anew. + */ + if ($total_errors > 0) + { + $this->_safe_form_data = TRUE; + } + + $this->set_fields(); + + // Did we end up with any errors? + if ($total_errors == 0) + { + return TRUE; + } + + // Generate the error string + foreach ($this->_error_array as $val) + { + $this->error_string .= $this->_error_prefix.$val.$this->_error_suffix."\n"; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Required + * + * @access public + * @param string + * @return bool + */ + function required($str) + { + if ( ! is_array($str)) + { + return (trim($str) == '') ? FALSE : TRUE; + } + else + { + return ( ! empty($str)); + } + } + + // -------------------------------------------------------------------- + + /** + * Match one field to another + * + * @access public + * @param string + * @return bool + */ + function matches($str, $field) + { + if ( ! isset($_POST[$field])) + { + return FALSE; + } + + return ($str !== $_POST[$field]) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Minimum Length + * + * @access public + * @param string + * @return bool + */ + function min_length($str, $val) + { + if ( ! is_numeric($val)) + { + return FALSE; + } + + return (strlen($str) < $val) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Max Length + * + * @access public + * @param string + * @return bool + */ + function max_length($str, $val) + { + if ( ! is_numeric($val)) + { + return FALSE; + } + + return (strlen($str) > $val) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Exact Length + * + * @access public + * @param string + * @return bool + */ + function exact_length($str, $val) + { + if ( ! is_numeric($val)) + { + return FALSE; + } + + 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; + } + + // -------------------------------------------------------------------- + + /** + * Validate IP Address + * + * @access public + * @param string + * @return string + */ + function valid_ip($ip) + { + return ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * 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 int + * @return bool + */ + function numeric($str) + { + return ( ! ereg("^[0-9\.]+$", $str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Is Numeric + * + * @access public + * @param string + * @return bool + */ + function is_numeric($str) + { + return ( ! is_numeric($str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Set Select + * + * Enables pull-down lists to be set to the value the user + * selected in the event of an error + * + * @access public + * @param string + * @param string + * @return string + */ + function set_select($field = '', $value = '') + { + if ($field == '' OR $value == '' OR ! isset($_POST[$field])) + { + return ''; + } + + if ($_POST[$field] == $value) + { + return ' selected="selected"'; + } + } + + // -------------------------------------------------------------------- + + /** + * Set Radio + * + * Enables radio buttons to be set to the value the user + * selected in the event of an error + * + * @access public + * @param string + * @param string + * @return string + */ + function set_radio($field = '', $value = '') + { + if ($field == '' OR $value == '' OR ! isset($_POST[$field])) + { + return ''; + } + + if ($_POST[$field] == $value) + { + return ' checked="checked"'; + } + } + + // -------------------------------------------------------------------- + + /** + * Set Checkbox + * + * Enables checkboxes to be set to the value the user + * selected in the event of an error + * + * @access public + * @param string + * @param string + * @return string + */ + function set_checkbox($field = '', $value = '') + { + if ($field == '' OR $value == '' OR ! isset($_POST[$field])) + { + return ''; + } + + if ($_POST[$field] == $value) + { + return ' checked="checked"'; + } + } + + // -------------------------------------------------------------------- + + /** + * Prep data for form + * + * This function allows HTML to be safely shown in a form. + * Special characters are converted. + * + * @access public + * @param string + * @return string + */ + function prep_for_form($str = '') + { + if ($this->_safe_form_data == FALSE OR $str == '') + { + return $str; + } + + return str_replace(array("'", '"', '<', '>'), array("'", """, '<', '>'), stripslashes($str)); + } + + // -------------------------------------------------------------------- + + /** + * Prep URL + * + * @access public + * @param string + * @return string + */ + function prep_url($str = '') + { + if ($str == 'http://' OR $str == '') + { + $_POST[$this->_current_field] = ''; + return; + } + + if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') + { + $str = 'http://'.$str; + } + + $_POST[$this->_current_field] = $str; + } + + // -------------------------------------------------------------------- + + /** + * Strip Image Tags + * + * @access public + * @param string + * @return string + */ + function strip_image_tags($str) + { + $_POST[$this->_current_field] = $this->input->strip_image_tags($str); + } + + // -------------------------------------------------------------------- + + /** + * XSS Clean + * + * @access public + * @param string + * @return string + */ + function xss_clean($str) + { + $_POST[$this->_current_field] = $this->CI->input->xss_clean($str); + } + + // -------------------------------------------------------------------- + + /** + * Convert PHP tags to entities + * + * @access public + * @param string + * @return string + */ + function encode_php_tags($str) + { + $_POST[$this->_current_field] = str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); + } + +} +// END Validation Class ?> \ No newline at end of file diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 2d9a4c11b..49747e481 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -1,1412 +1,1412 @@ -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' - ); - - // Array of Valid Parents for Various XML-RPC elements - $this->valid_parents = array('BOOLEAN' => array('VALUE'), - 'I4' => array('VALUE'), - 'INT' => array('VALUE'), - 'STRING' => array('VALUE'), - 'DOUBLE' => array('VALUE'), - 'DATETIME.ISO8601' => array('VALUE'), - 'BASE64' => array('VALUE'), - 'ARRAY' => array('VALUE'), - 'STRUCT' => array('VALUE'), - 'PARAM' => array('PARAMS'), - 'METHODNAME' => array('METHODCALL'), - 'PARAMS' => array('METHODCALL', 'METHODRESPONSE'), - 'MEMBER' => array('STRUCT'), - 'NAME' => array('MEMBER'), - 'DATA' => array('ARRAY'), - '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'; - $this->xmlrpcerr['invalid_return'] = '2'; - $this->xmlrpcstr['invalid_return'] = 'The XML data receieved was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.'; - $this->xmlrpcerr['incorrect_params'] = '3'; - $this->xmlrpcstr['incorrect_params'] = 'Incorrect parameters were passed to method'; - $this->xmlrpcerr['introspect_unknown'] = '4'; - $this->xmlrpcstr['introspect_unknown'] = "Cannot inspect signature for request: method unknown"; - $this->xmlrpcerr['http_error'] = '5'; - $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 - //------------------------------------- - - function initialize($config = array()) - { - if (sizeof($config) > 0) - { - foreach ($config as $key => $val) - { - if (isset($this->$key)) - { - $this->$key = $val; - } - } - } - } - // END - - //------------------------------------- - // Take URL and parse it - //------------------------------------- - - function server($url, $port=80) - { - if (substr($url, 0, 4) != "http") - { - $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 - //------------------------------------- - - function timeout($seconds=5) - { - if ( ! is_null($this->client) && is_int($seconds)) - { - $this->client->timeout = $seconds; - } - } - // END - - //------------------------------------- - // Set Methods - //------------------------------------- - - function method($function) - { - $this->method = $function; - } - // END - - //------------------------------------- - // Take Array of Data and Create Objects - //------------------------------------- - - function request($incoming) - { - if ( ! is_array($incoming)) - { - // Send Error - } - - foreach($incoming as $key => $value) - { - $this->data[$key] = $this->values_parsing($value); - } - } - // END - - - //------------------------------------- - // Set Debug - //------------------------------------- - - function set_debug($flag = TRUE) - { - $this->debug = ($flag == TRUE) ? TRUE : FALSE; - } - - //------------------------------------- - // Values Parsing - //------------------------------------- - - function values_parsing($value, $return = FALSE) - { - if (is_array($value) && isset($value['0'])) - { - if ( ! isset($value['1']) OR ! isset($this->xmlrpcTypes[strtolower($value['1'])])) - { - $temp = new XML_RPC_Values($value['0'], 'string'); - } - elseif(is_array($value['0']) && ($value['1'] == 'struct' OR $value['1'] == 'array')) - { - while (list($k) = each($value['0'])) - { - $value['0'][$k] = $this->values_parsing($value['0'][$k], TRUE); - } - - $temp = new XML_RPC_Values($value['0'], $value['1']); - } - else - { - $temp = new XML_RPC_Values($value['0'], $value['1']); - } - } - else - { - $temp = new XML_RPC_Values($value, 'string'); - } - - return $temp; - } - // END - - - //------------------------------------- - // Sends XML-RPC Request - //------------------------------------- - - function send_request() - { - $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; - return FALSE; - } - elseif( ! is_object($this->result->val)) - { - $this->error = $this->result->errstr; - return FALSE; - } - - $this->response = $this->result->decode(); - - return TRUE; - } - // END - - //------------------------------------- - // Returns Error - //------------------------------------- - - function display_error() - { - return $this->error; - } - // END - - //------------------------------------- - // Returns Remote Server Response - //------------------------------------- - - function display_response() - { - 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 - * - * @category XML-RPC - * @author Paul Burdick - * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html - */ -class XML_RPC_Client extends CI_Xmlrpc -{ - var $path = ''; - var $server = ''; - var $port = 80; - var $errno = ''; - var $errstring = ''; - var $timeout = 5; - var $no_multicall = false; - - 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)) - { - // Multi-call disabled - $r = new XML_RPC_Response(0, $this->xmlrpcerr['multicall_recursion'],$this->xmlrpcstr['multicall_recursion']); - return $r; - } - - return $this->sendPayload($msg); - } - - 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"; - $op .= "Content-Type: text/xml$r"; - $op .= "User-Agent: {$this->xmlrpcName}$r"; - $op .= "Content-Length: ".strlen($msg->payload). "$r$r"; - $op .= $msg->payload; - - - if (!fputs($fp, $op, strlen($op))) - { - error_log($this->xmlrpcstr['http_error']); - $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']); - return $r; - } - $resp = $msg->parseResponse($fp); - fclose($fp); - return $resp; - } - -} // end class XML_RPC_Client - - -/** - * XML-RPC Response class - * - * @category XML-RPC - * @author Paul Burdick - * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html - */ -class XML_RPC_Response -{ - var $val = 0; - var $errno = 0; - var $errstr = ''; - var $headers = array(); - - function XML_RPC_Response($val, $code = 0, $fstr = '') - { - if ($code != 0) - { - // error - $this->errno = $code; - $this->errstr = htmlentities($fstr); - } - else if (!is_object($val)) - { - // programmer error, not an object - error_log("Invalid type '" . gettype($val) . "' (value: $val) passed to XML_RPC_Response. Defaulting to empty value."); - $this->val = new XML_RPC_Values(); - } - else - { - $this->val = $val; - } - } - - function faultCode() - { - return $this->errno; - } - - function faultString() - { - return $this->errstr; - } - - function value() - { - return $this->val; - } - - function prepare_response() - { - $result = "\n"; - if ($this->errno) - { - $result .= ' - - - - faultCode - ' . $this->errno . ' - - - faultString - ' . $this->errstr . ' - - - -'; - } - else - { - $result .= "\n\n" . - $this->val->serialize_class() . - "\n"; - } - $result .= "\n"; - return $result; - } - - function decode($array=FALSE) - { - $CI =& get_instance(); - - if ($array !== FALSE && is_array($array)) - { - while (list($key) = each($array)) - { - if (is_array($array[$key])) - { - $array[$key] = $this->decode($array[$key]); - } - else - { - $array[$key] = $CI->input->xss_clean($array[$key]); - } - } - - $result = $array; - } - else - { - $result = $this->xmlrpc_decoder($this->val); - - if (is_array($result)) - { - $result = $this->decode($result); - } - else - { - $result = $CI->input->xss_clean($result); - } - } - - return $result; - } - - - - //------------------------------------- - // XML-RPC Object to PHP Types - //------------------------------------- - - function xmlrpc_decoder($xmlrpc_val) - { - $kind = $xmlrpc_val->kindOf(); - - if($kind == 'scalar') - { - return $xmlrpc_val->scalarval(); - } - elseif($kind == 'array') - { - reset($xmlrpc_val->me); - list($a,$b) = each($xmlrpc_val->me); - $size = sizeof($b); - - $arr = array(); - - for($i = 0; $i < $size; $i++) - { - $arr[] = $this->xmlrpc_decoder($xmlrpc_val->me['array'][$i]); - } - return $arr; - } - elseif($kind == 'struct') - { - reset($xmlrpc_val->me['struct']); - $arr = array(); - - while(list($key,$value) = each($xmlrpc_val->me['struct'])) - { - $arr[$key] = $this->xmlrpc_decoder($value); - } - return $arr; - } - } - - - //------------------------------------- - // ISO-8601 time to server or UTC time - //------------------------------------- - - function iso8601_decode($time, $utc=0) - { - // return a timet in the localtime, or UTC - $t = 0; - if (ereg("([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})", $time, $regs)) - { - if ($utc == 1) - $t = gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); - else - $t = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); - } - return $t; - } - -} // End Response Class - - - -/** - * XML-RPC Message class - * - * @category XML-RPC - * @author Paul Burdick - * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html - */ -class XML_RPC_Message extends CI_Xmlrpc -{ - var $payload; - var $method_name; - var $params = array(); - var $xh = array(); - - function XML_RPC_Message($method, $pars=0) - { - parent::CI_Xmlrpc(); - - $this->method_name = $method; - if (is_array($pars) && sizeof($pars) > 0) - { - for($i=0; $iparams[] = $pars[$i]; - } - } - } - - //------------------------------------- - // Create Payload to Send - //------------------------------------- - - function createPayload() - { - $this->payload = "\r\n\r\n"; - $this->payload .= '' . $this->method_name . "\r\n"; - $this->payload .= "\r\n"; - - for($i=0; $iparams); $i++) - { - // $p = XML_RPC_Values - $p = $this->params[$i]; - $this->payload .= "\r\n".$p->serialize_class()."\r\n"; - } - - $this->payload .= "\r\n\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 "
";
-			echo "---DATA---\n" . htmlspecialchars($data) . "\n---END DATA---\n\n";
-			echo "
"; - } - - //------------------------------------- - // Check for data - //------------------------------------- - - if($data == "") - { - error_log($this->xmlrpcstr['no_data']); - $r = new XML_RPC_Response(0, $this->xmlrpcerr['no_data'], $this->xmlrpcstr['no_data']); - return $r; - } - - - //------------------------------------- - // Check for HTTP 200 Response - //------------------------------------- - - if(ereg("^HTTP",$data) && !ereg("^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; - - xml_set_object($parser, $this); - xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true); - xml_set_element_handler($parser, 'open_tag', 'closing_tag'); - xml_set_character_data_handler($parser, 'character_data'); - //xml_set_default_handler($parser, 'default_handler'); - - - //------------------------------------- - // GET HEADERS - //------------------------------------- - - $lines = explode("\r\n", $data); - while (($line = array_shift($lines))) - { - if (strlen($line) < 1) - { - break; - } - $this->xh[$parser]['headers'][] = $line; - } - $data = implode("\r\n", $lines); - - - //------------------------------------- - // PARSE XML DATA - //------------------------------------- - - if (!xml_parse($parser, $data, sizeof($data))) - { - $errstr = sprintf('XML error: %s at line %d', - xml_error_string(xml_get_error_code($parser)), - xml_get_current_line_number($parser)); - //error_log($errstr); - $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']); - xml_parser_free($parser); - return $r; - } - xml_parser_free($parser); - - // --------------------------------------- - // Got Ourselves Some Badness, It Seems - // --------------------------------------- - - if ($this->xh[$parser]['isf'] > 1) - { - if ($this->debug === TRUE) - { - echo "---Invalid Return---\n"; - 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; - } - elseif ( ! is_object($this->xh[$parser]['value'])) - { - $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 "
";
-			
-			if (count($this->xh[$parser]['headers'] > 0))
-			{
-				echo "---HEADERS---\n";
-				foreach ($this->xh[$parser]['headers'] as $header)
-				{
-					echo "$header\n";
-				}
-				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---
"; - } - - //------------------------------------- - // SEND RESPONSE - //------------------------------------- - - $v = $this->xh[$parser]['value']; - - if ($this->xh[$parser]['isf']) - { - $errno_v = $v->me['struct']['faultCode']; - $errstr_v = $v->me['struct']['faultString']; - $errno = $errno_v->scalarval(); - - if ($errno == 0) - { - // FAULT returned, errno needs to reflect that - $errno = -1; - } - - $r = new XML_RPC_Response($v, $errno, $errstr_v->scalarval()); - } - else - { - $r = new XML_RPC_Response($v); - } - - $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 - // lv - used to indicate "looking for a value": implements - // the logic to allow values with no types to be strings - // params - used to store parameters in method calls - // method - used to store method name - // stack - array with parent tree of the xml element, - // used to validate the nesting of elements - - //------------------------------------- - // Start Element Handler - //------------------------------------- - - function open_tag($the_parser, $name, $attrs) - { - // 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') - { - $this->xh[$the_parser]['isf'] = 2; - $this->xh[$the_parser]['isf_reason'] = 'Top level XML-RPC element is missing'; - return; - } - } - else - { - // not top level element: see if parent is OK - if (!in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name], TRUE)) - { - $this->xh[$the_parser]['isf'] = 2; - $this->xh[$the_parser]['isf_reason'] = "XML-RPC element $name cannot be child of ".$this->xh[$the_parser]['stack'][0]; - 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': - case 'NAME': - $this->xh[$the_parser]['ac'] = ''; - break; - case 'FAULT': - $this->xh[$the_parser]['isf'] = 1; - break; - case 'PARAM': - $this->xh[$the_parser]['value'] = null; - break; - case 'VALUE': - $this->xh[$the_parser]['vt'] = 'value'; - $this->xh[$the_parser]['ac'] = ''; - $this->xh[$the_parser]['lv'] = 1; - break; - case 'I4': - case 'INT': - case 'STRING': - case 'BOOLEAN': - case 'DOUBLE': - case 'DATETIME.ISO8601': - case 'BASE64': - if ($this->xh[$the_parser]['vt'] != 'value') - { - //two data elements inside a value: an error occurred! - $this->xh[$the_parser]['isf'] = 2; - $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 to nothing to prevent errors later if no 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; - case 'DATA': - case 'METHODCALL': - case 'METHODRESPONSE': - case 'PARAMS': - // valid elements that add little to processing - break; - default: - /// An Invalid Element is Found, so we have trouble - $this->xh[$the_parser]['isf'] = 2; - $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); - - if ($name != 'VALUE') $this->xh[$the_parser]['lv'] = 0; - } - // END - - - //------------------------------------- - // End Element Handler - //------------------------------------- - - 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': - case 'ARRAY': - $cur_val = array_shift($this->xh[$the_parser]['valuestack']); - $this->xh[$the_parser]['value'] = ( ! isset($cur_val['values'])) ? array() : $cur_val['values']; - $this->xh[$the_parser]['vt'] = strtolower($name); - break; - case 'NAME': - $this->xh[$the_parser]['valuestack'][0]['name'] = $this->xh[$the_parser]['ac']; - break; - case 'BOOLEAN': - case 'I4': - case 'INT': - case 'STRING': - case 'DOUBLE': - 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']; - } - elseif ($name=='DATETIME.ISO8601') - { - $this->xh[$the_parser]['vt'] = $this->xmlrpcDateTime; - $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; - } - elseif ($name=='BASE64') - { - $this->xh[$the_parser]['value'] = base64_decode($this->xh[$the_parser]['ac']); - } - elseif ($name=='BOOLEAN') - { - // Translated BOOLEAN values to TRUE AND FALSE - if ($this->xh[$the_parser]['ac'] == '1') - { - $this->xh[$the_parser]['value'] = TRUE; - } - else - { - $this->xh[$the_parser]['value'] = FALSE; - } - } - elseif ($name=='DOUBLE') - { - // we have a DOUBLE - // we must check that only 0123456789-. are characters here - if (!ereg("^[+-]?[eE0123456789 \\t\\.]+$", $this->xh[$the_parser]['ac'])) - { - $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND'; - } - else - { - $this->xh[$the_parser]['value'] = (double)$this->xh[$the_parser]['ac']; - } - } - else - { - // we have an I4/INT - // we must check that only 0123456789- are characters here - if (!ereg("^[+-]?[0123456789 \\t]+$", $this->xh[$the_parser]['ac'])) - { - $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND'; - } - else - { - $this->xh[$the_parser]['value'] = (int)$this->xh[$the_parser]['ac']; - } - } - $this->xh[$the_parser]['ac'] = ''; - $this->xh[$the_parser]['lv'] = 3; // indicate we've found a value - break; - case 'VALUE': - // This if() detects if no scalar was inside - if ($this->xh[$the_parser]['vt']=='value') - { - $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 - $this->xh[$the_parser]['valuestack'][0]['values'][] = $temp; - } - else - { - // Struct - $this->xh[$the_parser]['value'] = $temp; - } - 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']) - { - $this->xh[$the_parser]['valuestack'][0]['values'][$this->xh[$the_parser]['valuestack'][0]['name']] = $this->xh[$the_parser]['value']; - } - break; - case 'DATA': - $this->xh[$the_parser]['ac']=''; - break; - case 'PARAM': - if ($this->xh[$the_parser]['value']) - { - $this->xh[$the_parser]['params'][] = $this->xh[$the_parser]['value']; - } - break; - case 'METHODNAME': - $this->xh[$the_parser]['method'] = ereg_replace("^[\n\r\t ]+", '', $this->xh[$the_parser]['ac']); - break; - case 'PARAMS': - case 'FAULT': - case 'METHODCALL': - case 'METHORESPONSE': - // We're all good kids with nuthin' to do - break; - default: - // End of an Invalid Element. Taken care of during the opening tag though - break; - } - } - - //------------------------------------- - // Parses Character Data - //------------------------------------- - - 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) - { - if ($this->xh[$the_parser]['lv'] == 1) - { - $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(); - - if ($array !== FALSE && is_array($array)) - { - while (list($key) = each($array)) - { - if (is_array($array[$key])) - { - $array[$key] = $this->output_parameters($array[$key]); - } - else - { - $array[$key] = $CI->input->xss_clean($array[$key]); - } - } - - $parameters = $array; - } - else - { - $parameters = array(); - - for ($i = 0; $i < sizeof($this->params); $i++) - { - $a_param = $this->decode_message($this->params[$i]); - - if (is_array($a_param)) - { - $parameters[] = $this->output_parameters($a_param); - } - else - { - $parameters[] = $CI->input->xss_clean($a_param); - } - } - } - - return $parameters; - } - - - function decode_message($param) - { - $kind = $param->kindOf(); - - if($kind == 'scalar') - { - return $param->scalarval(); - } - elseif($kind == 'array') - { - reset($param->me); - list($a,$b) = each($param->me); - - $arr = array(); - - for($i = 0; $i < sizeof($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 - - - -/** - * XML-RPC Values class - * - * @category XML-RPC - * @author Paul Burdick - * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html - */ -class XML_RPC_Values extends CI_Xmlrpc -{ - var $me = array(); - var $mytype = 0; - - function XML_RPC_Values($val=-1, $type='') - { - parent::CI_Xmlrpc(); - - if ($val != -1 || $type != '') - { - $type = $type == '' ? 'string' : $type; - - if ($this->xmlrpcTypes[$type] == 1) - { - $this->addScalar($val,$type); - } - elseif ($this->xmlrpcTypes[$type] == 2) - { - $this->addArray($val); - } - elseif ($this->xmlrpcTypes[$type] == 3) - { - $this->addStruct($val); - } - } - } - - function addScalar($val, $type='string') - { - $typeof = $this->xmlrpcTypes[$type]; - - if ($this->mytype==1) - { - echo 'XML_RPC_Values: scalar can have only one value
'; - return 0; - } - - if ($typeof != 1) - { - echo 'XML_RPC_Values: not a scalar type (${typeof})
'; - return 0; - } - - if ($type == $this->xmlrpcBoolean) - { - if (strcasecmp($val,'true')==0 || $val==1 || ($val==true && strcasecmp($val,'false'))) - { - $val = 1; - } - else - { - $val=0; - } - } - - if ($this->mytype == 2) - { - // adding to an array here - $ar = $this->me['array']; - $ar[] = new XML_RPC_Values($val, $type); - $this->me['array'] = $ar; - } - else - { - // a scalar, so set the value and remember we're scalar - $this->me[$type] = $val; - $this->mytype = $typeof; - } - return 1; - } - - function addArray($vals) - { - if ($this->mytype != 0) - { - echo 'XML_RPC_Values: already initialized as a [' . $this->kindOf() . ']
'; - return 0; - } - - $this->mytype = $this->xmlrpcTypes['array']; - $this->me['array'] = $vals; - return 1; - } - - function addStruct($vals) - { - if ($this->mytype != 0) - { - echo 'XML_RPC_Values: already initialized as a [' . $this->kindOf() . ']
'; - return 0; - } - $this->mytype = $this->xmlrpcTypes['struct']; - $this->me['struct'] = $vals; - return 1; - } - - function kindOf() - { - switch($this->mytype) - { - case 3: - return 'struct'; - break; - case 2: - return 'array'; - break; - case 1: - return 'scalar'; - break; - default: - return 'undef'; - } - } - - function serializedata($typ, $val) - { - $rs = ''; - - switch($this->xmlrpcTypes[$typ]) - { - case 3: - // struct - $rs .= "\n"; - reset($val); - while(list($key2, $val2) = each($val)) - { - $rs .= "\n{$key2}\n"; - $rs .= $this->serializeval($val2); - $rs .= "\n"; - } - $rs .= ''; - break; - case 2: - // array - $rs .= "\n\n"; - for($i=0; $i < sizeof($val); $i++) - { - $rs .= $this->serializeval($val[$i]); - } - $rs.="\n\n"; - break; - case 1: - // others - switch ($typ) - { - case $this->xmlrpcBase64: - $rs .= "<{$typ}>" . base64_encode($val) . "\n"; - break; - case $this->xmlrpcBoolean: - $rs .= "<{$typ}>" . ($val ? '1' : '0') . "\n"; - break; - case $this->xmlrpcString: - $rs .= "<{$typ}>" . htmlspecialchars($val). "\n"; - break; - default: - $rs .= "<{$typ}>{$val}\n"; - break; - } - default: - break; - } - return $rs; - } - - function serialize_class() - { - return $this->serializeval($this); - } - - function serializeval($o) - { - - $ar = $o->me; - reset($ar); - - list($typ, $val) = each($ar); - $rs = "\n".$this->serializedata($typ, $val)."\n"; - return $rs; - } - - function scalarval() - { - reset($this->me); - list($a,$b) = each($this->me); - return $b; - } - - - //------------------------------------- - // 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); - } - else - { - if (function_exists('gmstrftime')) - $t = gmstrftime("%Y%m%dT%H:%M:%S", $time); - else - $t = strftime("%Y%m%dT%H:%M:%S", $time - date('Z')); - } - return $t; - } - -} -// END XML_RPC_Values Class +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' + ); + + // Array of Valid Parents for Various XML-RPC elements + $this->valid_parents = array('BOOLEAN' => array('VALUE'), + 'I4' => array('VALUE'), + 'INT' => array('VALUE'), + 'STRING' => array('VALUE'), + 'DOUBLE' => array('VALUE'), + 'DATETIME.ISO8601' => array('VALUE'), + 'BASE64' => array('VALUE'), + 'ARRAY' => array('VALUE'), + 'STRUCT' => array('VALUE'), + 'PARAM' => array('PARAMS'), + 'METHODNAME' => array('METHODCALL'), + 'PARAMS' => array('METHODCALL', 'METHODRESPONSE'), + 'MEMBER' => array('STRUCT'), + 'NAME' => array('MEMBER'), + 'DATA' => array('ARRAY'), + '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'; + $this->xmlrpcerr['invalid_return'] = '2'; + $this->xmlrpcstr['invalid_return'] = 'The XML data receieved was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.'; + $this->xmlrpcerr['incorrect_params'] = '3'; + $this->xmlrpcstr['incorrect_params'] = 'Incorrect parameters were passed to method'; + $this->xmlrpcerr['introspect_unknown'] = '4'; + $this->xmlrpcstr['introspect_unknown'] = "Cannot inspect signature for request: method unknown"; + $this->xmlrpcerr['http_error'] = '5'; + $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 + //------------------------------------- + + function initialize($config = array()) + { + if (sizeof($config) > 0) + { + foreach ($config as $key => $val) + { + if (isset($this->$key)) + { + $this->$key = $val; + } + } + } + } + // END + + //------------------------------------- + // Take URL and parse it + //------------------------------------- + + function server($url, $port=80) + { + if (substr($url, 0, 4) != "http") + { + $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 + //------------------------------------- + + function timeout($seconds=5) + { + if ( ! is_null($this->client) && is_int($seconds)) + { + $this->client->timeout = $seconds; + } + } + // END + + //------------------------------------- + // Set Methods + //------------------------------------- + + function method($function) + { + $this->method = $function; + } + // END + + //------------------------------------- + // Take Array of Data and Create Objects + //------------------------------------- + + function request($incoming) + { + if ( ! is_array($incoming)) + { + // Send Error + } + + foreach($incoming as $key => $value) + { + $this->data[$key] = $this->values_parsing($value); + } + } + // END + + + //------------------------------------- + // Set Debug + //------------------------------------- + + function set_debug($flag = TRUE) + { + $this->debug = ($flag == TRUE) ? TRUE : FALSE; + } + + //------------------------------------- + // Values Parsing + //------------------------------------- + + function values_parsing($value, $return = FALSE) + { + if (is_array($value) && isset($value['0'])) + { + if ( ! isset($value['1']) OR ! isset($this->xmlrpcTypes[strtolower($value['1'])])) + { + $temp = new XML_RPC_Values($value['0'], 'string'); + } + elseif(is_array($value['0']) && ($value['1'] == 'struct' OR $value['1'] == 'array')) + { + while (list($k) = each($value['0'])) + { + $value['0'][$k] = $this->values_parsing($value['0'][$k], TRUE); + } + + $temp = new XML_RPC_Values($value['0'], $value['1']); + } + else + { + $temp = new XML_RPC_Values($value['0'], $value['1']); + } + } + else + { + $temp = new XML_RPC_Values($value, 'string'); + } + + return $temp; + } + // END + + + //------------------------------------- + // Sends XML-RPC Request + //------------------------------------- + + function send_request() + { + $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; + return FALSE; + } + elseif( ! is_object($this->result->val)) + { + $this->error = $this->result->errstr; + return FALSE; + } + + $this->response = $this->result->decode(); + + return TRUE; + } + // END + + //------------------------------------- + // Returns Error + //------------------------------------- + + function display_error() + { + return $this->error; + } + // END + + //------------------------------------- + // Returns Remote Server Response + //------------------------------------- + + function display_response() + { + 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 + * + * @category XML-RPC + * @author Paul Burdick + * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html + */ +class XML_RPC_Client extends CI_Xmlrpc +{ + var $path = ''; + var $server = ''; + var $port = 80; + var $errno = ''; + var $errstring = ''; + var $timeout = 5; + var $no_multicall = false; + + 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)) + { + // Multi-call disabled + $r = new XML_RPC_Response(0, $this->xmlrpcerr['multicall_recursion'],$this->xmlrpcstr['multicall_recursion']); + return $r; + } + + return $this->sendPayload($msg); + } + + 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"; + $op .= "Content-Type: text/xml$r"; + $op .= "User-Agent: {$this->xmlrpcName}$r"; + $op .= "Content-Length: ".strlen($msg->payload). "$r$r"; + $op .= $msg->payload; + + + if (!fputs($fp, $op, strlen($op))) + { + error_log($this->xmlrpcstr['http_error']); + $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']); + return $r; + } + $resp = $msg->parseResponse($fp); + fclose($fp); + return $resp; + } + +} // end class XML_RPC_Client + + +/** + * XML-RPC Response class + * + * @category XML-RPC + * @author Paul Burdick + * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html + */ +class XML_RPC_Response +{ + var $val = 0; + var $errno = 0; + var $errstr = ''; + var $headers = array(); + + function XML_RPC_Response($val, $code = 0, $fstr = '') + { + if ($code != 0) + { + // error + $this->errno = $code; + $this->errstr = htmlentities($fstr); + } + else if (!is_object($val)) + { + // programmer error, not an object + error_log("Invalid type '" . gettype($val) . "' (value: $val) passed to XML_RPC_Response. Defaulting to empty value."); + $this->val = new XML_RPC_Values(); + } + else + { + $this->val = $val; + } + } + + function faultCode() + { + return $this->errno; + } + + function faultString() + { + return $this->errstr; + } + + function value() + { + return $this->val; + } + + function prepare_response() + { + $result = "\n"; + if ($this->errno) + { + $result .= ' + + + + faultCode + ' . $this->errno . ' + + + faultString + ' . $this->errstr . ' + + + +'; + } + else + { + $result .= "\n\n" . + $this->val->serialize_class() . + "\n"; + } + $result .= "\n"; + return $result; + } + + function decode($array=FALSE) + { + $CI =& get_instance(); + + if ($array !== FALSE && is_array($array)) + { + while (list($key) = each($array)) + { + if (is_array($array[$key])) + { + $array[$key] = $this->decode($array[$key]); + } + else + { + $array[$key] = $CI->input->xss_clean($array[$key]); + } + } + + $result = $array; + } + else + { + $result = $this->xmlrpc_decoder($this->val); + + if (is_array($result)) + { + $result = $this->decode($result); + } + else + { + $result = $CI->input->xss_clean($result); + } + } + + return $result; + } + + + + //------------------------------------- + // XML-RPC Object to PHP Types + //------------------------------------- + + function xmlrpc_decoder($xmlrpc_val) + { + $kind = $xmlrpc_val->kindOf(); + + if($kind == 'scalar') + { + return $xmlrpc_val->scalarval(); + } + elseif($kind == 'array') + { + reset($xmlrpc_val->me); + list($a,$b) = each($xmlrpc_val->me); + $size = sizeof($b); + + $arr = array(); + + for($i = 0; $i < $size; $i++) + { + $arr[] = $this->xmlrpc_decoder($xmlrpc_val->me['array'][$i]); + } + return $arr; + } + elseif($kind == 'struct') + { + reset($xmlrpc_val->me['struct']); + $arr = array(); + + while(list($key,$value) = each($xmlrpc_val->me['struct'])) + { + $arr[$key] = $this->xmlrpc_decoder($value); + } + return $arr; + } + } + + + //------------------------------------- + // ISO-8601 time to server or UTC time + //------------------------------------- + + function iso8601_decode($time, $utc=0) + { + // return a timet in the localtime, or UTC + $t = 0; + if (ereg("([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})", $time, $regs)) + { + if ($utc == 1) + $t = gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); + else + $t = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); + } + return $t; + } + +} // End Response Class + + + +/** + * XML-RPC Message class + * + * @category XML-RPC + * @author Paul Burdick + * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html + */ +class XML_RPC_Message extends CI_Xmlrpc +{ + var $payload; + var $method_name; + var $params = array(); + var $xh = array(); + + function XML_RPC_Message($method, $pars=0) + { + parent::CI_Xmlrpc(); + + $this->method_name = $method; + if (is_array($pars) && sizeof($pars) > 0) + { + for($i=0; $iparams[] = $pars[$i]; + } + } + } + + //------------------------------------- + // Create Payload to Send + //------------------------------------- + + function createPayload() + { + $this->payload = "\r\n\r\n"; + $this->payload .= '' . $this->method_name . "\r\n"; + $this->payload .= "\r\n"; + + for($i=0; $iparams); $i++) + { + // $p = XML_RPC_Values + $p = $this->params[$i]; + $this->payload .= "\r\n".$p->serialize_class()."\r\n"; + } + + $this->payload .= "\r\n\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 "
";
+			echo "---DATA---\n" . htmlspecialchars($data) . "\n---END DATA---\n\n";
+			echo "
"; + } + + //------------------------------------- + // Check for data + //------------------------------------- + + if($data == "") + { + error_log($this->xmlrpcstr['no_data']); + $r = new XML_RPC_Response(0, $this->xmlrpcerr['no_data'], $this->xmlrpcstr['no_data']); + return $r; + } + + + //------------------------------------- + // Check for HTTP 200 Response + //------------------------------------- + + if(ereg("^HTTP",$data) && !ereg("^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; + + xml_set_object($parser, $this); + xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true); + xml_set_element_handler($parser, 'open_tag', 'closing_tag'); + xml_set_character_data_handler($parser, 'character_data'); + //xml_set_default_handler($parser, 'default_handler'); + + + //------------------------------------- + // GET HEADERS + //------------------------------------- + + $lines = explode("\r\n", $data); + while (($line = array_shift($lines))) + { + if (strlen($line) < 1) + { + break; + } + $this->xh[$parser]['headers'][] = $line; + } + $data = implode("\r\n", $lines); + + + //------------------------------------- + // PARSE XML DATA + //------------------------------------- + + if (!xml_parse($parser, $data, sizeof($data))) + { + $errstr = sprintf('XML error: %s at line %d', + xml_error_string(xml_get_error_code($parser)), + xml_get_current_line_number($parser)); + //error_log($errstr); + $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']); + xml_parser_free($parser); + return $r; + } + xml_parser_free($parser); + + // --------------------------------------- + // Got Ourselves Some Badness, It Seems + // --------------------------------------- + + if ($this->xh[$parser]['isf'] > 1) + { + if ($this->debug === TRUE) + { + echo "---Invalid Return---\n"; + 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; + } + elseif ( ! is_object($this->xh[$parser]['value'])) + { + $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 "
";
+			
+			if (count($this->xh[$parser]['headers'] > 0))
+			{
+				echo "---HEADERS---\n";
+				foreach ($this->xh[$parser]['headers'] as $header)
+				{
+					echo "$header\n";
+				}
+				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---
"; + } + + //------------------------------------- + // SEND RESPONSE + //------------------------------------- + + $v = $this->xh[$parser]['value']; + + if ($this->xh[$parser]['isf']) + { + $errno_v = $v->me['struct']['faultCode']; + $errstr_v = $v->me['struct']['faultString']; + $errno = $errno_v->scalarval(); + + if ($errno == 0) + { + // FAULT returned, errno needs to reflect that + $errno = -1; + } + + $r = new XML_RPC_Response($v, $errno, $errstr_v->scalarval()); + } + else + { + $r = new XML_RPC_Response($v); + } + + $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 + // lv - used to indicate "looking for a value": implements + // the logic to allow values with no types to be strings + // params - used to store parameters in method calls + // method - used to store method name + // stack - array with parent tree of the xml element, + // used to validate the nesting of elements + + //------------------------------------- + // Start Element Handler + //------------------------------------- + + function open_tag($the_parser, $name, $attrs) + { + // 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') + { + $this->xh[$the_parser]['isf'] = 2; + $this->xh[$the_parser]['isf_reason'] = 'Top level XML-RPC element is missing'; + return; + } + } + else + { + // not top level element: see if parent is OK + if (!in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name], TRUE)) + { + $this->xh[$the_parser]['isf'] = 2; + $this->xh[$the_parser]['isf_reason'] = "XML-RPC element $name cannot be child of ".$this->xh[$the_parser]['stack'][0]; + 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': + case 'NAME': + $this->xh[$the_parser]['ac'] = ''; + break; + case 'FAULT': + $this->xh[$the_parser]['isf'] = 1; + break; + case 'PARAM': + $this->xh[$the_parser]['value'] = null; + break; + case 'VALUE': + $this->xh[$the_parser]['vt'] = 'value'; + $this->xh[$the_parser]['ac'] = ''; + $this->xh[$the_parser]['lv'] = 1; + break; + case 'I4': + case 'INT': + case 'STRING': + case 'BOOLEAN': + case 'DOUBLE': + case 'DATETIME.ISO8601': + case 'BASE64': + if ($this->xh[$the_parser]['vt'] != 'value') + { + //two data elements inside a value: an error occurred! + $this->xh[$the_parser]['isf'] = 2; + $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 to nothing to prevent errors later if no 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; + case 'DATA': + case 'METHODCALL': + case 'METHODRESPONSE': + case 'PARAMS': + // valid elements that add little to processing + break; + default: + /// An Invalid Element is Found, so we have trouble + $this->xh[$the_parser]['isf'] = 2; + $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); + + if ($name != 'VALUE') $this->xh[$the_parser]['lv'] = 0; + } + // END + + + //------------------------------------- + // End Element Handler + //------------------------------------- + + 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': + case 'ARRAY': + $cur_val = array_shift($this->xh[$the_parser]['valuestack']); + $this->xh[$the_parser]['value'] = ( ! isset($cur_val['values'])) ? array() : $cur_val['values']; + $this->xh[$the_parser]['vt'] = strtolower($name); + break; + case 'NAME': + $this->xh[$the_parser]['valuestack'][0]['name'] = $this->xh[$the_parser]['ac']; + break; + case 'BOOLEAN': + case 'I4': + case 'INT': + case 'STRING': + case 'DOUBLE': + 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']; + } + elseif ($name=='DATETIME.ISO8601') + { + $this->xh[$the_parser]['vt'] = $this->xmlrpcDateTime; + $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; + } + elseif ($name=='BASE64') + { + $this->xh[$the_parser]['value'] = base64_decode($this->xh[$the_parser]['ac']); + } + elseif ($name=='BOOLEAN') + { + // Translated BOOLEAN values to TRUE AND FALSE + if ($this->xh[$the_parser]['ac'] == '1') + { + $this->xh[$the_parser]['value'] = TRUE; + } + else + { + $this->xh[$the_parser]['value'] = FALSE; + } + } + elseif ($name=='DOUBLE') + { + // we have a DOUBLE + // we must check that only 0123456789-. are characters here + if (!ereg("^[+-]?[eE0123456789 \\t\\.]+$", $this->xh[$the_parser]['ac'])) + { + $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND'; + } + else + { + $this->xh[$the_parser]['value'] = (double)$this->xh[$the_parser]['ac']; + } + } + else + { + // we have an I4/INT + // we must check that only 0123456789- are characters here + if (!ereg("^[+-]?[0123456789 \\t]+$", $this->xh[$the_parser]['ac'])) + { + $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND'; + } + else + { + $this->xh[$the_parser]['value'] = (int)$this->xh[$the_parser]['ac']; + } + } + $this->xh[$the_parser]['ac'] = ''; + $this->xh[$the_parser]['lv'] = 3; // indicate we've found a value + break; + case 'VALUE': + // This if() detects if no scalar was inside + if ($this->xh[$the_parser]['vt']=='value') + { + $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 + $this->xh[$the_parser]['valuestack'][0]['values'][] = $temp; + } + else + { + // Struct + $this->xh[$the_parser]['value'] = $temp; + } + 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']) + { + $this->xh[$the_parser]['valuestack'][0]['values'][$this->xh[$the_parser]['valuestack'][0]['name']] = $this->xh[$the_parser]['value']; + } + break; + case 'DATA': + $this->xh[$the_parser]['ac']=''; + break; + case 'PARAM': + if ($this->xh[$the_parser]['value']) + { + $this->xh[$the_parser]['params'][] = $this->xh[$the_parser]['value']; + } + break; + case 'METHODNAME': + $this->xh[$the_parser]['method'] = ereg_replace("^[\n\r\t ]+", '', $this->xh[$the_parser]['ac']); + break; + case 'PARAMS': + case 'FAULT': + case 'METHODCALL': + case 'METHORESPONSE': + // We're all good kids with nuthin' to do + break; + default: + // End of an Invalid Element. Taken care of during the opening tag though + break; + } + } + + //------------------------------------- + // Parses Character Data + //------------------------------------- + + 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) + { + if ($this->xh[$the_parser]['lv'] == 1) + { + $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(); + + if ($array !== FALSE && is_array($array)) + { + while (list($key) = each($array)) + { + if (is_array($array[$key])) + { + $array[$key] = $this->output_parameters($array[$key]); + } + else + { + $array[$key] = $CI->input->xss_clean($array[$key]); + } + } + + $parameters = $array; + } + else + { + $parameters = array(); + + for ($i = 0; $i < sizeof($this->params); $i++) + { + $a_param = $this->decode_message($this->params[$i]); + + if (is_array($a_param)) + { + $parameters[] = $this->output_parameters($a_param); + } + else + { + $parameters[] = $CI->input->xss_clean($a_param); + } + } + } + + return $parameters; + } + + + function decode_message($param) + { + $kind = $param->kindOf(); + + if($kind == 'scalar') + { + return $param->scalarval(); + } + elseif($kind == 'array') + { + reset($param->me); + list($a,$b) = each($param->me); + + $arr = array(); + + for($i = 0; $i < sizeof($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 + + + +/** + * XML-RPC Values class + * + * @category XML-RPC + * @author Paul Burdick + * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html + */ +class XML_RPC_Values extends CI_Xmlrpc +{ + var $me = array(); + var $mytype = 0; + + function XML_RPC_Values($val=-1, $type='') + { + parent::CI_Xmlrpc(); + + if ($val != -1 || $type != '') + { + $type = $type == '' ? 'string' : $type; + + if ($this->xmlrpcTypes[$type] == 1) + { + $this->addScalar($val,$type); + } + elseif ($this->xmlrpcTypes[$type] == 2) + { + $this->addArray($val); + } + elseif ($this->xmlrpcTypes[$type] == 3) + { + $this->addStruct($val); + } + } + } + + function addScalar($val, $type='string') + { + $typeof = $this->xmlrpcTypes[$type]; + + if ($this->mytype==1) + { + echo 'XML_RPC_Values: scalar can have only one value
'; + return 0; + } + + if ($typeof != 1) + { + echo 'XML_RPC_Values: not a scalar type (${typeof})
'; + return 0; + } + + if ($type == $this->xmlrpcBoolean) + { + if (strcasecmp($val,'true')==0 || $val==1 || ($val==true && strcasecmp($val,'false'))) + { + $val = 1; + } + else + { + $val=0; + } + } + + if ($this->mytype == 2) + { + // adding to an array here + $ar = $this->me['array']; + $ar[] = new XML_RPC_Values($val, $type); + $this->me['array'] = $ar; + } + else + { + // a scalar, so set the value and remember we're scalar + $this->me[$type] = $val; + $this->mytype = $typeof; + } + return 1; + } + + function addArray($vals) + { + if ($this->mytype != 0) + { + echo 'XML_RPC_Values: already initialized as a [' . $this->kindOf() . ']
'; + return 0; + } + + $this->mytype = $this->xmlrpcTypes['array']; + $this->me['array'] = $vals; + return 1; + } + + function addStruct($vals) + { + if ($this->mytype != 0) + { + echo 'XML_RPC_Values: already initialized as a [' . $this->kindOf() . ']
'; + return 0; + } + $this->mytype = $this->xmlrpcTypes['struct']; + $this->me['struct'] = $vals; + return 1; + } + + function kindOf() + { + switch($this->mytype) + { + case 3: + return 'struct'; + break; + case 2: + return 'array'; + break; + case 1: + return 'scalar'; + break; + default: + return 'undef'; + } + } + + function serializedata($typ, $val) + { + $rs = ''; + + switch($this->xmlrpcTypes[$typ]) + { + case 3: + // struct + $rs .= "\n"; + reset($val); + while(list($key2, $val2) = each($val)) + { + $rs .= "\n{$key2}\n"; + $rs .= $this->serializeval($val2); + $rs .= "\n"; + } + $rs .= ''; + break; + case 2: + // array + $rs .= "\n\n"; + for($i=0; $i < sizeof($val); $i++) + { + $rs .= $this->serializeval($val[$i]); + } + $rs.="\n\n"; + break; + case 1: + // others + switch ($typ) + { + case $this->xmlrpcBase64: + $rs .= "<{$typ}>" . base64_encode($val) . "\n"; + break; + case $this->xmlrpcBoolean: + $rs .= "<{$typ}>" . ($val ? '1' : '0') . "\n"; + break; + case $this->xmlrpcString: + $rs .= "<{$typ}>" . htmlspecialchars($val). "\n"; + break; + default: + $rs .= "<{$typ}>{$val}\n"; + break; + } + default: + break; + } + return $rs; + } + + function serialize_class() + { + return $this->serializeval($this); + } + + function serializeval($o) + { + + $ar = $o->me; + reset($ar); + + list($typ, $val) = each($ar); + $rs = "\n".$this->serializedata($typ, $val)."\n"; + return $rs; + } + + function scalarval() + { + reset($this->me); + list($a,$b) = each($this->me); + return $b; + } + + + //------------------------------------- + // 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); + } + else + { + if (function_exists('gmstrftime')) + $t = gmstrftime("%Y%m%dT%H:%M:%S", $time); + else + $t = strftime("%Y%m%dT%H:%M:%S", $time - date('Z')); + } + return $t; + } + +} +// END XML_RPC_Values Class ?> \ No newline at end of file diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index bdb058e82..fe55e36d6 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -1,503 +1,503 @@ -set_system_methods(); - - if (isset($config['functions']) && is_array($config['functions'])) - { - $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 = $config['functions']; - } - - if (isset($config['debug'])) - { - $this->debug = $config['debug']; - } - } - - //------------------------------------- - // Setting of System Methods - //------------------------------------- - - function set_system_methods () - { - $system_methods = array( - 'system.listMethods' => array( - 'function' => 'this.listMethods', - 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString), array($this->xmlrpcArray)), - 'docstring' => 'Returns an array of available methods on this server'), - 'system.methodHelp' => array( - 'function' => 'this.methodHelp', - 'signature' => array(array($this->xmlrpcString, $this->xmlrpcString)), - 'docstring' => 'Returns a documentation string for the specified method'), - 'system.methodSignature' => array( - 'function' => 'this.methodSignature', - 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString)), - 'docstring' => 'Returns an array describing the return type and required parameters of a method'), - 'system.multicall' => array( - 'function' => 'this.multicall', - 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcArray)), - 'docstring' => 'Combine multiple RPC calls in one request. See http://www.xmlrpc.com/discuss/msgReader$1208 for details') - ); - } - - - //------------------------------------- - // Main Server Function - //------------------------------------- - - function serve() - { - $r = $this->parseRequest(); - $payload = 'xmlrpc_defencoding.'"?'.'>'."\n"; - $payload .= $this->debug_msg; - $payload .= $r->prepare_response(); - - header("Content-Type: text/xml"); - header("Content-Length: ".strlen($payload)); - echo $payload; - } - - //------------------------------------- - // Add Method to Class - //------------------------------------- - - function add_to_map($methodname,$function,$sig,$doc) - { - $this->methods[$methodname] = array( - 'function' => $function, - 'signature' => $sig, - 'docstring' => $doc - ); - } - - - //------------------------------------- - // Parse Server Request - //------------------------------------- - - function parseRequest($data='') - { - global $HTTP_RAW_POST_DATA; - - //------------------------------------- - // Get Data - //------------------------------------- - - if ($data == '') - { - $data = $HTTP_RAW_POST_DATA; - } - - - //------------------------------------- - // 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'] = ''; - $parser_object->xh[$parser]['params'] = array(); - $parser_object->xh[$parser]['stack'] = array(); - $parser_object->xh[$parser]['valuestack'] = array(); - $parser_object->xh[$parser]['method'] = ''; - - xml_set_object($parser, $parser_object); - xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true); - 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 - $r = new XML_RPC_Response(0, - $this->xmlrpcerrxml + xml_get_error_code($parser), - sprintf('XML error: %s at line %d', - xml_error_string(xml_get_error_code($parser)), - xml_get_current_line_number($parser))); - xml_parser_free($parser); - } - elseif($parser_object->xh[$parser]['isf']) - { - return new XML_RPC_Response(0, - $this->xmlrpcerr['invalid_return'], - $this->xmlrpcstr['invalid_retrun']); - } - else - { - xml_parser_free($parser); - - $m = new XML_RPC_Message($parser_object->xh[$parser]['method']); - $plist=''; - - for($i=0; $i < sizeof($parser_object->xh[$parser]['params']); $i++) - { - $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 "
";
-				echo "---PLIST---\n" . $plist . "\n---PLIST END---\n\n";
-				echo "
"; - } - - $r = $this->_execute($m); - } - - //------------------------------------- - // SET DEBUGGING MESSAGE - //------------------------------------- - - if ($this->debug === TRUE) - { - $this->debug_msg = "\n"; - } - - return $r; - } - - //------------------------------------- - // Executes the Method - //------------------------------------- - - function _execute($m) - { - $methName = $m->method_name; - - // Check to see if it is a system call - // If so, load the system_methods - $sysCall = ereg("^system\.", $methName); - $methods = $sysCall ? $this->system_methods : $this->methods; - - //------------------------------------- - // Check for Function - //------------------------------------- - - if (!isset($methods[$methName]['function'])) - { - return new XML_RPC_Response(0, - $this->xmlrpcerr['unknown_method'], - $this->xmlrpcstr['unknown_method']); - } - else - { - // See if we are calling function in an object - - $method_parts = explode(".",$methods[$methName]['function']); - $objectCall = (isset($method_parts['1']) && $method_parts['1'] != "") ? true : false; - - if ($objectCall && !is_callable(array($method_parts['0'],$method_parts['1']))) - { - return new XML_RPC_Response(0, - $this->xmlrpcerr['unknown_method'], - $this->xmlrpcstr['unknown_method']); - } - elseif (!$objectCall && !is_callable($methods[$methName]['function'])) - { - return new XML_RPC_Response(0, - $this->xmlrpcerr['unknown_method'], - $this->xmlrpcstr['unknown_method']); - } - } - - //------------------------------------- - // Checking Methods Signature - //------------------------------------- - - if (isset($methods[$methName]['signature'])) - { - $sig = $methods[$methName]['signature']; - for($i=0; $iparams)+1) - { - for($n=0; $n < sizeof($m->params); $n++) - { - $p = $m->params[$n]; - $pt = ($p->kindOf() == 'scalar') ? $p->scalartyp() : $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'] . - ": Wanted {$wanted}, got {$pt} at param {$pno})"); - } - } - } - } - } - - //------------------------------------- - // Calls the Function - //------------------------------------- - - if ($objectCall) - { - if ($method_parts['1'] == "this") - { - return call_user_func(array($this, $method_parts['0']), $m); - } - else - { - $CI =& get_instance(); - return $CI->$method_parts['1']($m); - //$class = new $method_parts['0']; - //return $class->$method_parts['1']($m); - //return call_user_func(array(&$method_parts['0'],$method_parts['1']), $m); - } - } - else - { - return call_user_func($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'); - } - - $v->addArray($output); - return new XML_RPC_Response($v); - } - - //------------------------------------- - // Server Function: Return Signature for Method - //------------------------------------- - - function methodSignature($m) - { - $methName = $m->getParam(0); - $method_name = $methName->scalarval(); - - $methods = ereg("^system\.", $method_name) ? $this->system_methods : $this->methods; - - if (isset($methods[$method_name])) - { - if ($methods[$method_name]['signature']) - { - $sigs = array(); - $signature = $methods[$method_name]['signature']; - - for($i=0; $i < sizeof($signature); $i++) - { - $cursig = array(); - $inSig = $signature[$i]; - for($j=0; $jxmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); - } - return $r; - } - - //------------------------------------- - // Server Function: Doc String for Method - //------------------------------------- - - function methodHelp($m) - { - $methName = $m->getParam(0); - $method_name = $methName->scalarval(); - - $methods = ereg("^system\.", $method_name) ? $this->system_methods : $this->methods; - - if (isset($methods[$methName])) - { - $docstring = isset($methods[$method_name]['docstring']) ? $methods[$method_name]['docstring'] : ''; - $r = new XML_RPC_Response(new XML_RPC_Values($docstring, 'string')); - } - else - { - $r = new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); - } - return $r; - } - - //------------------------------------- - // Server Function: Multi-call - //------------------------------------- - - function multicall($m) - { - $calls = $m->getParam(0); - list($a,$b)=each($calls->me); - $result = array(); - - for ($i = 0; $i < sizeof($b); $i++) - { - $call = $calls->me['array'][$i]; - $result[$i] = $this->do_multicall($call); - } - - return new XML_RPC_Response(new XML_RPC_Values($result, 'array')); - } - - - //------------------------------------- - // Multi-call Function: Error Handling - //------------------------------------- - - function multicall_error($err) - { - $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' || $scalar_type != 'string') - return $this->multicall_error('notstring'); - elseif ($scalar_value == 'system.multicall') - return $this->multicall_error('recursion'); - elseif (!$params = $call->me['struct']['params']) - return $this->multicall_error('noparams'); - elseif ($params->kindOf() != 'array') - return $this->multicall_error('notarray'); - - list($a,$b)=each($params->me); - $numParams = sizeof($b); - - $msg = new XML_RPC_Message($scalar_value); - for ($i = 0; $i < $numParams; $i++) - { - $msg->params[] = $params->me['array'][$i]; - } - - $result = $this->_execute($msg); - - if ($result->faultCode() != 0) - { - return $this->multicall_error($result); - } - - return new XML_RPC_Values(array($result->value()), 'array'); - } - -} -// END XML_RPC_Server class - +set_system_methods(); + + if (isset($config['functions']) && is_array($config['functions'])) + { + $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 = $config['functions']; + } + + if (isset($config['debug'])) + { + $this->debug = $config['debug']; + } + } + + //------------------------------------- + // Setting of System Methods + //------------------------------------- + + function set_system_methods () + { + $system_methods = array( + 'system.listMethods' => array( + 'function' => 'this.listMethods', + 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString), array($this->xmlrpcArray)), + 'docstring' => 'Returns an array of available methods on this server'), + 'system.methodHelp' => array( + 'function' => 'this.methodHelp', + 'signature' => array(array($this->xmlrpcString, $this->xmlrpcString)), + 'docstring' => 'Returns a documentation string for the specified method'), + 'system.methodSignature' => array( + 'function' => 'this.methodSignature', + 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString)), + 'docstring' => 'Returns an array describing the return type and required parameters of a method'), + 'system.multicall' => array( + 'function' => 'this.multicall', + 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcArray)), + 'docstring' => 'Combine multiple RPC calls in one request. See http://www.xmlrpc.com/discuss/msgReader$1208 for details') + ); + } + + + //------------------------------------- + // Main Server Function + //------------------------------------- + + function serve() + { + $r = $this->parseRequest(); + $payload = 'xmlrpc_defencoding.'"?'.'>'."\n"; + $payload .= $this->debug_msg; + $payload .= $r->prepare_response(); + + header("Content-Type: text/xml"); + header("Content-Length: ".strlen($payload)); + echo $payload; + } + + //------------------------------------- + // Add Method to Class + //------------------------------------- + + function add_to_map($methodname,$function,$sig,$doc) + { + $this->methods[$methodname] = array( + 'function' => $function, + 'signature' => $sig, + 'docstring' => $doc + ); + } + + + //------------------------------------- + // Parse Server Request + //------------------------------------- + + function parseRequest($data='') + { + global $HTTP_RAW_POST_DATA; + + //------------------------------------- + // Get Data + //------------------------------------- + + if ($data == '') + { + $data = $HTTP_RAW_POST_DATA; + } + + + //------------------------------------- + // 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'] = ''; + $parser_object->xh[$parser]['params'] = array(); + $parser_object->xh[$parser]['stack'] = array(); + $parser_object->xh[$parser]['valuestack'] = array(); + $parser_object->xh[$parser]['method'] = ''; + + xml_set_object($parser, $parser_object); + xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true); + 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 + $r = new XML_RPC_Response(0, + $this->xmlrpcerrxml + xml_get_error_code($parser), + sprintf('XML error: %s at line %d', + xml_error_string(xml_get_error_code($parser)), + xml_get_current_line_number($parser))); + xml_parser_free($parser); + } + elseif($parser_object->xh[$parser]['isf']) + { + return new XML_RPC_Response(0, + $this->xmlrpcerr['invalid_return'], + $this->xmlrpcstr['invalid_retrun']); + } + else + { + xml_parser_free($parser); + + $m = new XML_RPC_Message($parser_object->xh[$parser]['method']); + $plist=''; + + for($i=0; $i < sizeof($parser_object->xh[$parser]['params']); $i++) + { + $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 "
";
+				echo "---PLIST---\n" . $plist . "\n---PLIST END---\n\n";
+				echo "
"; + } + + $r = $this->_execute($m); + } + + //------------------------------------- + // SET DEBUGGING MESSAGE + //------------------------------------- + + if ($this->debug === TRUE) + { + $this->debug_msg = "\n"; + } + + return $r; + } + + //------------------------------------- + // Executes the Method + //------------------------------------- + + function _execute($m) + { + $methName = $m->method_name; + + // Check to see if it is a system call + // If so, load the system_methods + $sysCall = ereg("^system\.", $methName); + $methods = $sysCall ? $this->system_methods : $this->methods; + + //------------------------------------- + // Check for Function + //------------------------------------- + + if (!isset($methods[$methName]['function'])) + { + return new XML_RPC_Response(0, + $this->xmlrpcerr['unknown_method'], + $this->xmlrpcstr['unknown_method']); + } + else + { + // See if we are calling function in an object + + $method_parts = explode(".",$methods[$methName]['function']); + $objectCall = (isset($method_parts['1']) && $method_parts['1'] != "") ? true : false; + + if ($objectCall && !is_callable(array($method_parts['0'],$method_parts['1']))) + { + return new XML_RPC_Response(0, + $this->xmlrpcerr['unknown_method'], + $this->xmlrpcstr['unknown_method']); + } + elseif (!$objectCall && !is_callable($methods[$methName]['function'])) + { + return new XML_RPC_Response(0, + $this->xmlrpcerr['unknown_method'], + $this->xmlrpcstr['unknown_method']); + } + } + + //------------------------------------- + // Checking Methods Signature + //------------------------------------- + + if (isset($methods[$methName]['signature'])) + { + $sig = $methods[$methName]['signature']; + for($i=0; $iparams)+1) + { + for($n=0; $n < sizeof($m->params); $n++) + { + $p = $m->params[$n]; + $pt = ($p->kindOf() == 'scalar') ? $p->scalartyp() : $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'] . + ": Wanted {$wanted}, got {$pt} at param {$pno})"); + } + } + } + } + } + + //------------------------------------- + // Calls the Function + //------------------------------------- + + if ($objectCall) + { + if ($method_parts['1'] == "this") + { + return call_user_func(array($this, $method_parts['0']), $m); + } + else + { + $CI =& get_instance(); + return $CI->$method_parts['1']($m); + //$class = new $method_parts['0']; + //return $class->$method_parts['1']($m); + //return call_user_func(array(&$method_parts['0'],$method_parts['1']), $m); + } + } + else + { + return call_user_func($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'); + } + + $v->addArray($output); + return new XML_RPC_Response($v); + } + + //------------------------------------- + // Server Function: Return Signature for Method + //------------------------------------- + + function methodSignature($m) + { + $methName = $m->getParam(0); + $method_name = $methName->scalarval(); + + $methods = ereg("^system\.", $method_name) ? $this->system_methods : $this->methods; + + if (isset($methods[$method_name])) + { + if ($methods[$method_name]['signature']) + { + $sigs = array(); + $signature = $methods[$method_name]['signature']; + + for($i=0; $i < sizeof($signature); $i++) + { + $cursig = array(); + $inSig = $signature[$i]; + for($j=0; $jxmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); + } + return $r; + } + + //------------------------------------- + // Server Function: Doc String for Method + //------------------------------------- + + function methodHelp($m) + { + $methName = $m->getParam(0); + $method_name = $methName->scalarval(); + + $methods = ereg("^system\.", $method_name) ? $this->system_methods : $this->methods; + + if (isset($methods[$methName])) + { + $docstring = isset($methods[$method_name]['docstring']) ? $methods[$method_name]['docstring'] : ''; + $r = new XML_RPC_Response(new XML_RPC_Values($docstring, 'string')); + } + else + { + $r = new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); + } + return $r; + } + + //------------------------------------- + // Server Function: Multi-call + //------------------------------------- + + function multicall($m) + { + $calls = $m->getParam(0); + list($a,$b)=each($calls->me); + $result = array(); + + for ($i = 0; $i < sizeof($b); $i++) + { + $call = $calls->me['array'][$i]; + $result[$i] = $this->do_multicall($call); + } + + return new XML_RPC_Response(new XML_RPC_Values($result, 'array')); + } + + + //------------------------------------- + // Multi-call Function: Error Handling + //------------------------------------- + + function multicall_error($err) + { + $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' || $scalar_type != 'string') + return $this->multicall_error('notstring'); + elseif ($scalar_value == 'system.multicall') + return $this->multicall_error('recursion'); + elseif (!$params = $call->me['struct']['params']) + return $this->multicall_error('noparams'); + elseif ($params->kindOf() != 'array') + return $this->multicall_error('notarray'); + + list($a,$b)=each($params->me); + $numParams = sizeof($b); + + $msg = new XML_RPC_Message($scalar_value); + for ($i = 0; $i < $numParams; $i++) + { + $msg->params[] = $params->me['array'][$i]; + } + + $result = $this->_execute($msg); + + if ($result->faultCode() != 0) + { + return $this->multicall_error($result); + } + + return new XML_RPC_Values(array($result->value()), 'array'); + } + +} +// END XML_RPC_Server class + ?> \ No newline at end of file diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 1ff175fe2..377c38741 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -1,380 +1,380 @@ -_add_dir($dir); - } - } - - // -------------------------------------------------------------------- - - /** - * Add Directory - * - * @access private - * @param string the directory name - * @return void - */ - function _add_dir($dir) - { - $dir = str_replace("\\", "/", $dir); - - $this->zipdata[] = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" - .pack('V', 0) - .pack('V', 0) - .pack('V', 0) - .pack('v', strlen($dir)) - .pack('v', 0) - .$dir - .pack('V', 0) - .pack('V', 0) - .pack('V', 0); - - $newoffset = strlen(implode('', $this->zipdata)); - - $record = "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" - .pack('V',0) - .pack('V',0) - .pack('V',0) - .pack('v', strlen($dir)) - .pack('v', 0) - .pack('v', 0) - .pack('v', 0) - .pack('v', 0) - .pack('V', 16) - .pack('V', $this->offset) - .$dir; - - $this->offset = $newoffset; - $this->directory[] = $record; - } - - // -------------------------------------------------------------------- - - /** - * Add Data to Zip - * - * Lets you add files to the archive. If the path is included - * in the filename it will be placed within a directory. Make - * sure you use add_dir() first to create the folder. - * - * @access public - * @param mixed - * @param string - * @return void - */ - function add_data($filepath, $data = NULL) - { - if (is_array($filepath)) - { - foreach ($filepath as $path => $data) - { - $this->_add_data($path, $data); - } - } - else - { - $this->_add_data($filepath, $data); - } - } - - // -------------------------------------------------------------------- - - /** - * Add Data to Zip - * - * @access private - * @param string the file name/path - * @param string the data to be encoded - * @return void - */ - function _add_data($filepath, $data) - { - $filepath = str_replace("\\", "/", $filepath); - - $oldlen = strlen($data); - $crc32 = crc32($data); - - $gzdata = gzcompress($data); - $gzdata = substr(substr($gzdata, 0, strlen($gzdata) - 4), 2); - $newlen = strlen($gzdata); - - $this->zipdata[] = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" - .pack('V', $crc32) - .pack('V', $newlen) - .pack('V', $oldlen) - .pack('v', strlen($filepath)) - .pack('v', 0) - .$filepath - .$gzdata - .pack('V', $crc32) - .pack('V', $newlen) - .pack('V', $oldlen); - - $newoffset = strlen(implode("", $this->zipdata)); - - $record = "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" - .pack('V', $crc32) - .pack('V', $newlen) - .pack('V', $oldlen) - .pack('v', strlen($filepath)) - .pack('v', 0) - .pack('v', 0) - .pack('v', 0) - .pack('v', 0) - .pack('V', 32) - .pack('V', $this->offset); - - $this->offset = $newoffset; - $this->directory[] = $record.$filepath; - } - - // -------------------------------------------------------------------- - - /** - * Read the contents of a file and add it to the zip - * - * @access public - * @return bool - */ - function read_file($path, $preserve_filepath = FALSE) - { - if ( ! file_exists($path)) - { - return FALSE; - } - - if (FALSE !== ($data = file_get_contents($path))) - { - $name = str_replace("\\", "/", $path); - - if ($preserve_filepath === FALSE) - { - $name = preg_replace("|.*/(.+)|", "\\1", $name); - } - - $this->add_data($name, $data); - return TRUE; - } - return FALSE; - } - - // ------------------------------------------------------------------------ - - /** - * Read a directory and add it to the zip. - * - * This function recursively reads a folder and everything it contains (including - * sub-folders) and creates a zip based on it. Whatever directory structure - * is in the original file path will be recreated in the zip file. - * - * @access public - * @param string path to source - * @return bool - */ - function read_dir($path) - { - if ($fp = @opendir($path)) - { - while (FALSE !== ($file = readdir($fp))) - { - if (@is_dir($path.$file) && substr($file, 0, 1) != '.') - { - $this->read_dir($path.$file."/"); - } - elseif (substr($file, 0, 1) != ".") - { - if (FALSE !== ($data = file_get_contents($path.$file))) - { - $this->add_data(str_replace("\\", "/", $path).$file, $data); - } - } - } - return TRUE; - } - } - - // -------------------------------------------------------------------- - - /** - * Get the Zip file - * - * @access public - * @return binary string - */ - function get_zip() - { - // We cache the zip data so multiple calls - // do not require recompiling - if ($this->zipfile != '') - { - return $this->zipfile; - } - - // Is there any data to return? - if (count($this->zipdata) == 0) - { - return FALSE; - } - - $data = implode('', $this->zipdata); - $dir = implode('', $this->directory); - - $this->zipfile = $data.$dir."\x50\x4b\x05\x06\x00\x00\x00\x00" - .pack('v', sizeof($this->directory)) - .pack('v', sizeof($this->directory)) - .pack('V', strlen($dir)) - .pack('V', strlen($data)) - ."\x00\x00"; - - return $this->zipfile; - } - - // -------------------------------------------------------------------- - - /** - * Write File to the specified directory - * - * Lets you write a file - * - * @access public - * @param string the file name - * @param string the data to be encoded - * @return bool - */ - function archive($filepath) - { - if ( ! ($fp = @fopen($filepath, "wb"))) - { - return FALSE; - } - - flock($fp, LOCK_EX); - fwrite($fp, $this->get_zip()); - flock($fp, LOCK_UN); - fclose($fp); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Download - * - * @access public - * @param string the file name - * @param string the data to be encoded - * @return bool - */ - function download($filename = 'backup.zip') - { - if ( ! preg_match("|.+?\.zip$|", $filename)) - { - $filename .= '.zip'; - } - - if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) - { - header('Content-Type: application/x-zip'); - header('Content-Disposition: inline; filename="'.$filename.'"'); - header('Expires: 0'); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header("Content-Transfer-Encoding: binary"); - header('Pragma: public'); - header("Content-Length: ".strlen($this->get_zip())); - } - else - { - header('Content-Type: application/x-zip'); - header('Content-Disposition: attachment; filename="'.$filename.'"'); - header("Content-Transfer-Encoding: binary"); - header('Expires: 0'); - header('Pragma: no-cache'); - header("Content-Length: ".strlen($this->get_zip())); - } - - echo $this->get_zip(); - } - - // -------------------------------------------------------------------- - - /** - * Initialize Data - * - * Lets you clear current zip data. Useful if you need to create - * multiple zips with different data. - * - * @access public - * @return void - */ - function clear_data() - { - $this->zipfile = ''; - $this->zipdata = array(); - $this->directory = array(); - $this->offset = array(); - } - -} +_add_dir($dir); + } + } + + // -------------------------------------------------------------------- + + /** + * Add Directory + * + * @access private + * @param string the directory name + * @return void + */ + function _add_dir($dir) + { + $dir = str_replace("\\", "/", $dir); + + $this->zipdata[] = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" + .pack('V', 0) + .pack('V', 0) + .pack('V', 0) + .pack('v', strlen($dir)) + .pack('v', 0) + .$dir + .pack('V', 0) + .pack('V', 0) + .pack('V', 0); + + $newoffset = strlen(implode('', $this->zipdata)); + + $record = "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" + .pack('V',0) + .pack('V',0) + .pack('V',0) + .pack('v', strlen($dir)) + .pack('v', 0) + .pack('v', 0) + .pack('v', 0) + .pack('v', 0) + .pack('V', 16) + .pack('V', $this->offset) + .$dir; + + $this->offset = $newoffset; + $this->directory[] = $record; + } + + // -------------------------------------------------------------------- + + /** + * Add Data to Zip + * + * Lets you add files to the archive. If the path is included + * in the filename it will be placed within a directory. Make + * sure you use add_dir() first to create the folder. + * + * @access public + * @param mixed + * @param string + * @return void + */ + function add_data($filepath, $data = NULL) + { + if (is_array($filepath)) + { + foreach ($filepath as $path => $data) + { + $this->_add_data($path, $data); + } + } + else + { + $this->_add_data($filepath, $data); + } + } + + // -------------------------------------------------------------------- + + /** + * Add Data to Zip + * + * @access private + * @param string the file name/path + * @param string the data to be encoded + * @return void + */ + function _add_data($filepath, $data) + { + $filepath = str_replace("\\", "/", $filepath); + + $oldlen = strlen($data); + $crc32 = crc32($data); + + $gzdata = gzcompress($data); + $gzdata = substr(substr($gzdata, 0, strlen($gzdata) - 4), 2); + $newlen = strlen($gzdata); + + $this->zipdata[] = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" + .pack('V', $crc32) + .pack('V', $newlen) + .pack('V', $oldlen) + .pack('v', strlen($filepath)) + .pack('v', 0) + .$filepath + .$gzdata + .pack('V', $crc32) + .pack('V', $newlen) + .pack('V', $oldlen); + + $newoffset = strlen(implode("", $this->zipdata)); + + $record = "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" + .pack('V', $crc32) + .pack('V', $newlen) + .pack('V', $oldlen) + .pack('v', strlen($filepath)) + .pack('v', 0) + .pack('v', 0) + .pack('v', 0) + .pack('v', 0) + .pack('V', 32) + .pack('V', $this->offset); + + $this->offset = $newoffset; + $this->directory[] = $record.$filepath; + } + + // -------------------------------------------------------------------- + + /** + * Read the contents of a file and add it to the zip + * + * @access public + * @return bool + */ + function read_file($path, $preserve_filepath = FALSE) + { + if ( ! file_exists($path)) + { + return FALSE; + } + + if (FALSE !== ($data = file_get_contents($path))) + { + $name = str_replace("\\", "/", $path); + + if ($preserve_filepath === FALSE) + { + $name = preg_replace("|.*/(.+)|", "\\1", $name); + } + + $this->add_data($name, $data); + return TRUE; + } + return FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * Read a directory and add it to the zip. + * + * This function recursively reads a folder and everything it contains (including + * sub-folders) and creates a zip based on it. Whatever directory structure + * is in the original file path will be recreated in the zip file. + * + * @access public + * @param string path to source + * @return bool + */ + function read_dir($path) + { + if ($fp = @opendir($path)) + { + while (FALSE !== ($file = readdir($fp))) + { + if (@is_dir($path.$file) && substr($file, 0, 1) != '.') + { + $this->read_dir($path.$file."/"); + } + elseif (substr($file, 0, 1) != ".") + { + if (FALSE !== ($data = file_get_contents($path.$file))) + { + $this->add_data(str_replace("\\", "/", $path).$file, $data); + } + } + } + return TRUE; + } + } + + // -------------------------------------------------------------------- + + /** + * Get the Zip file + * + * @access public + * @return binary string + */ + function get_zip() + { + // We cache the zip data so multiple calls + // do not require recompiling + if ($this->zipfile != '') + { + return $this->zipfile; + } + + // Is there any data to return? + if (count($this->zipdata) == 0) + { + return FALSE; + } + + $data = implode('', $this->zipdata); + $dir = implode('', $this->directory); + + $this->zipfile = $data.$dir."\x50\x4b\x05\x06\x00\x00\x00\x00" + .pack('v', sizeof($this->directory)) + .pack('v', sizeof($this->directory)) + .pack('V', strlen($dir)) + .pack('V', strlen($data)) + ."\x00\x00"; + + return $this->zipfile; + } + + // -------------------------------------------------------------------- + + /** + * Write File to the specified directory + * + * Lets you write a file + * + * @access public + * @param string the file name + * @param string the data to be encoded + * @return bool + */ + function archive($filepath) + { + if ( ! ($fp = @fopen($filepath, "wb"))) + { + return FALSE; + } + + flock($fp, LOCK_EX); + fwrite($fp, $this->get_zip()); + flock($fp, LOCK_UN); + fclose($fp); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Download + * + * @access public + * @param string the file name + * @param string the data to be encoded + * @return bool + */ + function download($filename = 'backup.zip') + { + if ( ! preg_match("|.+?\.zip$|", $filename)) + { + $filename .= '.zip'; + } + + if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) + { + header('Content-Type: application/x-zip'); + header('Content-Disposition: inline; filename="'.$filename.'"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header("Content-Transfer-Encoding: binary"); + header('Pragma: public'); + header("Content-Length: ".strlen($this->get_zip())); + } + else + { + header('Content-Type: application/x-zip'); + header('Content-Disposition: attachment; filename="'.$filename.'"'); + header("Content-Transfer-Encoding: binary"); + header('Expires: 0'); + header('Pragma: no-cache'); + header("Content-Length: ".strlen($this->get_zip())); + } + + echo $this->get_zip(); + } + + // -------------------------------------------------------------------- + + /** + * Initialize Data + * + * Lets you clear current zip data. Useful if you need to create + * multiple zips with different data. + * + * @access public + * @return void + */ + function clear_data() + { + $this->zipfile = ''; + $this->zipdata = array(); + $this->directory = array(); + $this->offset = array(); + } + +} ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 445b24d4b377013eb3946383409b7668cd54e060 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 24 Apr 2007 12:48:19 +0000 Subject: fixed router but that was ignoring the scaffolding route for optimization --- system/libraries/Router.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 64becf535..e44d9a4db 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -428,12 +428,13 @@ class CI_Router { function _parse_routes() { // Do we even have any custom routing to deal with? - if (count($this->routes) == 0) + // There is a default scaffolding trigger, so we'll look just for 1 + if (count($this->routes) == 1) { $this->_compile_segments($this->segments); return; } - + // Turn the segment array into a URI string $uri = implode('/', $this->segments); $num = count($this->segments); -- cgit v1.2.3-24-g4f1b From 44a736f74bd6a7852cba442e5ad4126068caf626 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 27 Apr 2007 17:03:10 +0000 Subject: modified _add_data() to be compatible with OS X (removed CRC and length from end of file stream) --- system/libraries/Zip.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 377c38741..518c97836 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -156,7 +156,7 @@ class CI_Zip { $crc32 = crc32($data); $gzdata = gzcompress($data); - $gzdata = substr(substr($gzdata, 0, strlen($gzdata) - 4), 2); + $gzdata = substr($gzdata, 2, -4); $newlen = strlen($gzdata); $this->zipdata[] = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" @@ -166,10 +166,7 @@ class CI_Zip { .pack('v', strlen($filepath)) .pack('v', 0) .$filepath - .$gzdata - .pack('V', $crc32) - .pack('V', $newlen) - .pack('V', $oldlen); + .$gzdata; $newoffset = strlen(implode("", $this->zipdata)); -- cgit v1.2.3-24-g4f1b From a1b05a1c6505fe2afce28c0268a51582c655a190 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 27 Apr 2007 21:20:38 +0000 Subject: --- system/libraries/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 7ad8509a3..c28713c1b 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -194,7 +194,7 @@ class CI_Validation { //Explode out the rules! $ex = explode('|', $rules); - // Is the field required? If not, if the field is blank we'll move on to the next text + // Is the field required? If not, if the field is blank we'll move on to the next test if ( ! in_array('required', $ex, TRUE) AND strpos($rules, 'callback_') === FALSE) { if ( ! isset($_POST[$field]) OR $_POST[$field] == '') -- cgit v1.2.3-24-g4f1b From 74c46a16d1ae6b52eb53c46eee305bc1b19ccb26 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 30 Apr 2007 01:39:39 +0000 Subject: fixed a typo in rpcs.php library --- system/libraries/Xmlrpcs.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index fe55e36d6..018530216 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -191,7 +191,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc { return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], - $this->xmlrpcstr['invalid_retrun']); + $this->xmlrpcstr['invalid_return']); } else { -- cgit v1.2.3-24-g4f1b From e6c4f7b7bcf96117bdcbd885b3ea4a4f1a7b570d Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 30 Apr 2007 11:54:45 +0000 Subject: fixed bug in output --- system/libraries/Profiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index cdc4f6fc9..ffd664a88 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -166,7 +166,7 @@ class CI_Profiler { } // $output .= "$_POST[".$key."]  ".htmlspecialchars(stripslashes($val))."\n"; - $output .= "$_POST[".$key."] "; + $output .= "".$_POST[$key]." "; if (is_array($val)) { $output .= "
" . htmlspecialchars(stripslashes(print_r($val, true))) . "
"; -- cgit v1.2.3-24-g4f1b From 971af995fb3ba4268dd4ba434254d35001013b5b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 1 May 2007 20:21:28 +0000 Subject: fixed a bug in the calendar library --- system/libraries/Calendar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index ef6a3f841..5fec40e1c 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -270,7 +270,7 @@ class CI_Calendar { } else { - $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_names = array('01' => 'cal_january', '02' => 'cal_february', '03' => 'cal_march', '04' => 'cal_april', '05' => 'cal_may', '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]; -- cgit v1.2.3-24-g4f1b From 31d363b39fe8ec09e1af3b4441f9bd5844bf8224 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 2 May 2007 01:18:58 +0000 Subject: // Prep the current page - no funny business! $this->cur_page = preg_replace("/[a-z\-]/", "", $this->cur_page); became // Prep the current page - no funny business! $this->cur_page = (int) $this->cur_page; --- system/libraries/Pagination.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 27104c95c..8ea0dab19 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -122,7 +122,7 @@ class CI_Pagination { $this->cur_page = $CI->uri->segment($this->uri_segment); // Prep the current page - no funny business! - $this->cur_page = preg_replace("/[a-z\-]/", "", $this->cur_page); + $this->cur_page = (int) $this->cur_page; } if ( ! is_numeric($this->cur_page)) -- cgit v1.2.3-24-g4f1b From bbc5ec2a660c960873f7c41437859fa1d82703d6 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 2 May 2007 11:34:08 +0000 Subject: $this->base_url = preg_replace("/(.+?)\/*$/", "\\1/", $this->base_url); changed to $this->base_url = rtrim($this->base_url, '/') .'/'; --- system/libraries/Pagination.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 8ea0dab19..c5c718dee 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -146,8 +146,8 @@ class CI_Pagination { $end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages; // Add a trailing slash to the base URL if needed - $this->base_url = preg_replace("/(.+?)\/*$/", "\\1/", $this->base_url); - + $this->base_url = rtrim($this->base_url, '/') .'/'; + // And here we go... $output = ''; -- cgit v1.2.3-24-g4f1b From 01f72ca6c27d99938cd1f814f812c5b844d51b83 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 4 May 2007 18:19:17 +0000 Subject: Modified XSS Cleaning routine to be more performance friendly and compatible with PHP 5.2's new PCRE backtrack and recursion limits. - replaced link and image tag javascript sanitization preg_replace()'s with callback functions to avoid excessive backtracks on strings with many links / image tags. --- system/libraries/Input.php | 55 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 8 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 64c0ed418..63a6833d6 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -499,8 +499,10 @@ class CI_Input { * Note: Normally urldecode() would be easier but it removes plus signs * */ + $str = preg_replace("/(%20)+/", '9u3iovBnRThju941s89rKozm', $str); $str = preg_replace("/%u0([a-z0-9]{3})/i", "&#x\\1;", $str); - $str = preg_replace("/%([a-z0-9]{2})/i", "&#x\\1;", $str); + $str = preg_replace("/%([a-z0-9]{2})/i", "&#x\\1;", $str); + $str = str_replace('9u3iovBnRThju941s89rKozm', "%20", $str); /* * Convert character entities to ASCII @@ -575,17 +577,17 @@ class CI_Input { $temp .= substr($word, $i, 1)."\s*"; } - $temp = substr($temp, 0, -3); - $str = preg_replace('#'.$temp.'#s', $word, $str); - $str = preg_replace('#'.ucfirst($temp).'#s', ucfirst($word), $str); + // We only want to do this when it is followed by a non-word character + // That way valid stuff like "dealer to" does not become "dealerto" + $str = preg_replace('#('.substr($temp, 0, -3).')(\W)#ise', "preg_replace('/\s+/s', '', '\\1').'\\2'", $str); } /* * Remove disallowed Javascript in links or img tags */ - $str = preg_replace("#.*?#si", "", $str); - $str = preg_replace("##si", "", $str); - $str = preg_replace("#<(script|xss).*?\>#si", "", $str); + $str = preg_replace_callback("##si", array($this, '_js_link_removal'), $str); + $str = preg_replace_callback("##si", array($this, '_js_img_removal'), $str); + $str = preg_replace("#<(script|xss).*?\>#si", "", $str); /* * Remove JavaScript Event Handlers @@ -595,7 +597,8 @@ class CI_Input { * but it's unlikely to be a problem. * */ - $str = preg_replace('#(<[^>]+.*?)(onblur|onchange|onclick|onfocus|onload|onmouseover|onmouseup|onmousedown|onselect|onsubmit|onunload|onkeypress|onkeydown|onkeyup|onresize)[^>]*>#iU',"\\1>",$str); + $event_handlers = array('onblur','onchange','onclick','onfocus','onload','onmouseover','onmouseup','onmousedown','onselect','onsubmit','onunload','onkeypress','onkeydown','onkeyup','onresize', 'xmlns'); + $str = preg_replace("#<([^>]+)(".implode('|', $event_handlers).")([^>]*)>#iU", "<\\1\\2\\3>", $str); /* * Sanitize naughty HTML elements @@ -652,7 +655,43 @@ class CI_Input { } // -------------------------------------------------------------------- + + /** + * JS Link Removal + * + * Callback function for xss_clean() to sanitize links + * This limits the PCRE backtracks, making it more performance friendly + * and prevents PREG_BACKTRACK_LIMIT_ERROR from being triggered in + * PHP 5.2+ on link-heavy strings + * + * @access private + * @param array + * @return string + */ + function _js_link_removal($match) + { + return preg_replace("#.*?#si", "", $match[0]); + } + + /** + * JS Image Removal + * + * Callback function for xss_clean() to sanitize image tags + * This limits the PCRE backtracks, making it more performance friendly + * and prevents PREG_BACKTRACK_LIMIT_ERROR from being triggered in + * PHP 5.2+ on image tag heavy strings + * + * @access private + * @param array + * @return string + */ + function _js_img_removal($match) + { + return preg_replace("##si", "", $match[0]); + } + // -------------------------------------------------------------------- + /** * HTML Entities Decode * -- cgit v1.2.3-24-g4f1b From d885680948438cf59ad3d67820fb3ac2c6f7a8c6 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 24 May 2007 03:49:37 +0000 Subject: typo fix --- system/libraries/Output.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 743228e53..756d4b4cc 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -275,7 +275,7 @@ class CI_Output { if ( ! $fp = @fopen($cache_path, 'wb')) { - log_message('error', "Unable to write ache file: ".$cache_path); + log_message('error', "Unable to write cache file: ".$cache_path); return; } -- cgit v1.2.3-24-g4f1b From bb2041dc4e5a121de9321fbf87846b7358d59d39 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sat, 9 Jun 2007 00:16:13 +0000 Subject: --- system/libraries/Input.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 63a6833d6..f113cff71 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -68,7 +68,8 @@ class CI_Input { */ function _sanitize_globals() { - // Unset globals. This is effectively the same as register_globals = off + // Unset globals for securiy. + // This is effectively the same as register_globals = off foreach (array($_GET, $_POST, $_COOKIE) as $global) { if ( ! is_array($global)) @@ -147,6 +148,13 @@ class CI_Input { return $new_array; } + // We strip slashes if magic quotes is on to keep things consistent + if (get_magic_quotes_gpc()) + { + $str = stripslashes($str); + } + + // Should we filter the input data? if ($this->use_xss_clean === TRUE) { $str = $this->xss_clean($str); @@ -175,12 +183,7 @@ class CI_Input { { exit('Disallowed Key Characters.'); } - - if ( ! get_magic_quotes_gpc()) - { - return addslashes($str); - } - + return $str; } -- cgit v1.2.3-24-g4f1b From 8c501b3ba6d1aa0c18e749550f0ee3435a9272d6 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sat, 9 Jun 2007 01:13:36 +0000 Subject: --- system/libraries/Loader.php | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index ff5ffbfe4..abe3a1c37 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -681,17 +681,30 @@ class CI_Loader { // We'll test for both lowercase and capitalized versions of the file name foreach (array(ucfirst($class), strtolower($class)) as $class) { - // Is this a class extension request? - if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT)) + $subclass = APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT; + + // Is this a class extension request? + if (file_exists($subclass)) { - if ( ! file_exists(BASEPATH.'libraries/'.ucfirst($class).EXT)) + $baseclass = BASEPATH.'libraries/'.ucfirst($class).EXT; + + if ( ! file_exists($baseclass)) { log_message('error', "Unable to load the requested class: ".$class); show_error("Unable to load the requested class: ".$class); } + + // Safety: Was the class already loaded by a previous call? + if (in_array($subclass, $this->_ci_classes)) + { + $is_duplicate = TRUE; + log_message('debug', $class." class already loaded. Second attempt ignored."); + return; + } - include(BASEPATH.'libraries/'.ucfirst($class).EXT); - include(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT); + include($baseclass); + include($subclass); + $this->_ci_classes[] = $subclass; return $this->_ci_init_class($class, config_item('subclass_prefix'), $params); } @@ -701,24 +714,24 @@ class CI_Loader { for ($i = 1; $i < 3; $i++) { $path = ($i % 2) ? APPPATH : BASEPATH; - $fp = $path.'libraries/'.$class.EXT; + $filepath = $path.'libraries/'.$class.EXT; // Does the file exist? No? Bummer... - if ( ! file_exists($fp)) + if ( ! file_exists($filepath)) { continue; } // Safety: Was the class already loaded by a previous call? - if (in_array($fp, $this->_ci_classes)) + if (in_array($filepath, $this->_ci_classes)) { $is_duplicate = TRUE; log_message('debug', $class." class already loaded. Second attempt ignored."); return; } - include($fp); - $this->_ci_classes[] = $fp; + include($filepath); + $this->_ci_classes[] = $filepath; return $this->_ci_init_class($class, '', $params); } } // END FOREACH -- cgit v1.2.3-24-g4f1b From f660315a3cea96279a755ece825aabb9dcfd5a1d Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sat, 9 Jun 2007 01:16:00 +0000 Subject: --- system/libraries/Router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index e44d9a4db..6c3062c07 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -303,7 +303,7 @@ class CI_Router { // Is there a PATH_INFO variable? // Note: some servers seem to have trouble with getenv() so we'll test it two ways - $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); + $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); if ($path != '' AND $path != "/".SELF) { return $path; -- cgit v1.2.3-24-g4f1b From e6b4a80ed09aa9d171db6abf2af2bca3cbac4945 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 11 Jun 2007 04:20:44 +0000 Subject: --- system/libraries/Upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 564e29937..4cea9cd71 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -709,7 +709,7 @@ class CI_Upload { return FALSE; } - if ( ! $fp = @fopen($file, 'rb')) + if ( ! $fp = @fopen($file, 'r+b')) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 64bbd04d8a3c92e577254513504e9c9d617fe676 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 11 Jun 2007 04:35:52 +0000 Subject: --- system/libraries/Upload.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 4cea9cd71..d8a8f69a7 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -708,19 +708,21 @@ class CI_Upload { { return FALSE; } - + + if ( ! $data = file_get_contents($file)) + { + return FALSE; + } + if ( ! $fp = @fopen($file, 'r+b')) { return FALSE; } - - flock($fp, LOCK_EX); - $data = fread($fp, filesize($file)); - $CI =& get_instance(); $data = $CI->input->xss_clean($data); - + + flock($fp, LOCK_EX); fwrite($fp, $data); flock($fp, LOCK_UN); fclose($fp); -- cgit v1.2.3-24-g4f1b From 8de97ffd0629a4fe1f7dfe97276935793591a179 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 11 Jun 2007 04:38:47 +0000 Subject: --- system/libraries/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index c28713c1b..79ab76c6b 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -518,7 +518,7 @@ class CI_Validation { */ function alpha_numeric($str) { - return ( ! preg_match("/^([-a-z0-9])+$/i", $str)) ? FALSE : TRUE; + return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 63966df193cb275d957ffc64398f6fe941c00e31 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 11 Jun 2007 04:44:11 +0000 Subject: --- system/libraries/Upload.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index d8a8f69a7..dc3fd4a12 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -708,8 +708,8 @@ class CI_Upload { { return FALSE; } - - if ( ! $data = file_get_contents($file)) + + if (($data = @file_get_contents($file)) !== FALSE) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 1adf1db17260090e2678f209ad429b0b186e3dbc Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 11 Jun 2007 04:46:57 +0000 Subject: --- system/libraries/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 79ab76c6b..960053426 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -504,7 +504,7 @@ class CI_Validation { */ function alpha($str) { - return ( ! preg_match("/^([-a-z])+$/i", $str)) ? FALSE : TRUE; + return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 8d127c78fe0a1d6034cb503529dc548b566156c8 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 11 Jun 2007 04:47:58 +0000 Subject: --- system/libraries/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index a8acec674..7b7dc091c 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -484,7 +484,7 @@ class CI_Email { */ function set_newline($newline = "\n") { - if ($newline != "\n" OR $newline != "\r\n" OR $newline != "\r") + if ($newline != "\n" AND $newline != "\r\n" AND $newline != "\r") { $this->newline = "\n"; return; -- cgit v1.2.3-24-g4f1b From e666afc7eaf8c8224c4e6cf6f7e415966f22783e Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 11 Jun 2007 05:03:11 +0000 Subject: --- system/libraries/Input.php | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index f113cff71..e493f6d33 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -379,36 +379,34 @@ class CI_Input { /** * Validate IP Address * + * Updated version suggested by Geert De Deckere + * * @access public * @param string * @return string */ function valid_ip($ip) { - if ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) + $ip_segments = explode('.', $ip); + + // Always 4 segments needed + if (count($ip_segments) != 4) { return FALSE; } - - $octets = explode('.', $ip); - - for ($i = 1; $i <= 4; $i++) + // IP cannot start with 0 + if (substr($ip_segments[0], 0, 1) == 0) { - $octet = intval($octets[($i-1)]); - if ($i === 1) - { - if ($octet > 223 OR $octet < 1) - return FALSE; - } - elseif ($i === 4) - { - if ($octet < 1) - return FALSE; - } - else + return FALSE; + } + // Check each segment + foreach ($ip_segments as $segment) + { + // IP segments must be digits and can not be + // longer than 3 digits or greater then 255 + if ( ! ctype_digit($segment) OR $segment > 255 OR strlen($segment) > 3) { - if ($octet > 254) - return FALSE; + return FALSE; } } -- cgit v1.2.3-24-g4f1b From a405117ece2113aa58dff481834abc6fe103a546 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 11 Jun 2007 05:08:11 +0000 Subject: --- system/libraries/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 960053426..896cd39d7 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -490,7 +490,7 @@ class CI_Validation { */ function valid_ip($ip) { - return ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) ? FALSE : TRUE; + return $this->CI->valid_ip($ip); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From ba648939ddc1ed86e36fa7cdf20d3d05401e4ffe Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 12 Jun 2007 03:39:38 +0000 Subject: --- system/libraries/Input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index e493f6d33..7b0282418 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -404,7 +404,7 @@ class CI_Input { { // IP segments must be digits and can not be // longer than 3 digits or greater then 255 - if ( ! ctype_digit($segment) OR $segment > 255 OR strlen($segment) > 3) + if (preg_match("/[^0-9]/", $segment) OR $segment > 255 OR strlen($segment) > 3) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 3921314954fb851cf2b0980cabc750e0481d0de5 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 12 Jun 2007 03:53:12 +0000 Subject: --- system/libraries/Input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 7b0282418..102e3b5eb 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -395,7 +395,7 @@ class CI_Input { return FALSE; } // IP cannot start with 0 - if (substr($ip_segments[0], 0, 1) == 0) + if (substr($ip_segments[0], 0, 1) == '0') { return FALSE; } -- cgit v1.2.3-24-g4f1b From 65e8f0e0833dac10362775b9edf3cffae126abb8 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 12 Jun 2007 03:53:21 +0000 Subject: --- system/libraries/Input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 102e3b5eb..1ff72877b 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -394,7 +394,7 @@ class CI_Input { { return FALSE; } - // IP cannot start with 0 + // IP can not start with 0 if (substr($ip_segments[0], 0, 1) == '0') { return FALSE; -- cgit v1.2.3-24-g4f1b From 001e25623f7dc53e38999adce07188088ac6e032 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Wed, 13 Jun 2007 22:01:30 +0000 Subject: --- system/libraries/Validation.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 896cd39d7..6b6ec0c68 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -419,7 +419,7 @@ class CI_Validation { */ function min_length($str, $val) { - if ( ! is_numeric($val)) + if (preg_match("/[^0-9]/", $val)) { return FALSE; } @@ -438,7 +438,7 @@ class CI_Validation { */ function max_length($str, $val) { - if ( ! is_numeric($val)) + if (preg_match("/[^0-9]/", $val)) { return FALSE; } @@ -457,7 +457,7 @@ class CI_Validation { */ function exact_length($str, $val) { - if ( ! is_numeric($val)) + if (preg_match("/[^0-9]/", $val)) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 83ec240297a25342748846df84ad3c5ecb7cd623 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 18 Jun 2007 00:14:44 +0000 Subject: typo in comments --- system/libraries/Encrypt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 758c0f0a5..dc952dde3 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -318,7 +318,7 @@ class CI_Encrypt { // -------------------------------------------------------------------- /** - * Get Mcrypt MOde Value + * Get Mcrypt Mode Value * * @access private * @return string -- cgit v1.2.3-24-g4f1b From 3c5e373a2c95ba06b8d5b9820f53a72bea2f5681 Mon Sep 17 00:00:00 2001 From: paulburdick Date: Sun, 24 Jun 2007 20:27:42 +0000 Subject: Fixed the do_xss_clean() method so that if file_get_contents returns FALSE, then we return FALSE... Previously, if it did NOT return FALSE we returned FALSE and that is simply idiotic. --- system/libraries/Upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index dc3fd4a12..9d2bae2ae 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -709,7 +709,7 @@ class CI_Upload { return FALSE; } - if (($data = @file_get_contents($file)) !== FALSE) + if (($data = @file_get_contents($file)) === FALSE) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 2f35c4b91526d2d813601401a3e6563255f2b639 Mon Sep 17 00:00:00 2001 From: paulburdick Date: Sun, 24 Jun 2007 20:29:09 +0000 Subject: Modified the is_image() method in the Upload library to take into account Windows IE 6/7 eccentricities when dealing with MIMEs --- system/libraries/Upload.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 9d2bae2ae..fa1cf1e73 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -477,17 +477,28 @@ class CI_Upload { */ function is_image() { + // IE will sometimes return odd mime-types during upload, so here we just standardize all + // jpegs or pngs to the same file type. + + $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'; + } + $img_mimes = array( 'image/gif', - 'image/jpg', - 'image/jpe', 'image/jpeg', - 'image/pjpeg', 'image/png', - 'image/x-png' ); - return (in_array($this->file_type, $img_mimes, TRUE)) ? TRUE : FALSE; } -- cgit v1.2.3-24-g4f1b From 033ef02392d70dbc873deacc50ee76a800d0d228 Mon Sep 17 00:00:00 2001 From: paulburdick Date: Tue, 26 Jun 2007 21:52:52 +0000 Subject: *Updated the XSS Filtering to take into account the IE expression() ability --- system/libraries/Input.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 1ff72877b..dc4e605b8 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -528,9 +528,12 @@ class CI_Input { */ $bad = array( 'document.cookie' => '[removed]', + '.parentNode' => '[removed]', + '.innerHTML' => '[removed]', 'document.write' => '[removed]', 'window.location' => '[removed]', "javascript\s*:" => '[removed]', + "expression\s*\(" => '[removed]', // CSS and IE "Redirect\s+302" => '[removed]', '' => '-->' @@ -626,7 +629,7 @@ class CI_Input { * Becomes: eval('some code') * */ - $str = preg_replace('#(alert|cmd|passthru|eval|exec|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)\((.*?)\)#si', "\\1\\2(\\3)", $str); + $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 @@ -637,9 +640,12 @@ class CI_Input { */ $bad = array( 'document.cookie' => '[removed]', + '.parentNode' => '[removed]', + '.innerHTML' => '[removed]', 'document.write' => '[removed]', 'window.location' => '[removed]', "javascript\s*:" => '[removed]', + "expression\s*\(" => '[removed]', // CSS and IE "Redirect\s+302" => '[removed]', '' => '-->' -- cgit v1.2.3-24-g4f1b From b614d392ccafd1decadbdc11afd7c0dcc4baec34 Mon Sep 17 00:00:00 2001 From: paulburdick Date: Tue, 26 Jun 2007 21:58:56 +0000 Subject: --- system/libraries/Input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index dc4e605b8..51d4ed288 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -572,7 +572,7 @@ class CI_Input { * These words are compacted back to their correct state. * */ - $words = array('javascript', 'vbscript', 'script', 'applet', 'alert', 'document', 'write', 'cookie', 'window'); + $words = array('javascript', 'expression', 'vbscript', 'script', 'applet', 'alert', 'document', 'write', 'cookie', 'window'); foreach ($words as $word) { $temp = ''; -- cgit v1.2.3-24-g4f1b From 391eb03004deee85b9b0e978982950723b9742b5 Mon Sep 17 00:00:00 2001 From: paulburdick Date: Wed, 27 Jun 2007 22:58:24 +0000 Subject: Improved XSS clean to not allowing this: xss_clean("ss ipt a='>'>alert/**/('!');//*/>"); --- system/libraries/Input.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 51d4ed288..f9d23ae79 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -588,10 +588,18 @@ class CI_Input { /* * Remove disallowed Javascript in links or img tags - */ - $str = preg_replace_callback("##si", array($this, '_js_link_removal'), $str); - $str = preg_replace_callback("##si", array($this, '_js_img_removal'), $str); - $str = preg_replace("#<(script|xss).*?\>#si", "", $str); + */ + do + { + $original = $str; + + $str = preg_replace_callback("##si", array($this, '_js_link_removal'), $str); + $str = preg_replace_callback("##si", array($this, '_js_img_removal'), $str); + $str = preg_replace("##si", "", $str); + } + while($original != $str); + + unset($original); /* * Remove JavaScript Event Handlers -- cgit v1.2.3-24-g4f1b From 8816aaab7ac21d4e3ccd1eedd86462bc94aff2c1 Mon Sep 17 00:00:00 2001 From: paulburdick Date: Wed, 27 Jun 2007 23:07:36 +0000 Subject: --- system/libraries/Input.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index f9d23ae79..9a73ab9b9 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -68,21 +68,30 @@ class CI_Input { */ function _sanitize_globals() { + // Would kind of be "wrong" to unset any of these GLOBALS. + $protected = array('_SERVER', '_GET', '_POST', '_FILES', '_REQUEST', '_SESSION', '_ENV', 'GLOBALS', 'HTTP_RAW_POST_DATA'); + // Unset globals for securiy. // This is effectively the same as register_globals = off foreach (array($_GET, $_POST, $_COOKIE) as $global) { if ( ! is_array($global)) { - global $global; - $$global = NULL; + if ( ! in_array($global, $protected)) + { + global $global; + $$global = NULL; + } } else { foreach ($global as $key => $val) { - global $$key; - $$key = NULL; + if ( ! in_array($key, $protected)) + { + global $$key; + $$key = NULL; + } } } } -- cgit v1.2.3-24-g4f1b From 3541313e896794514b7d44a5f0aab1e47b340ef7 Mon Sep 17 00:00:00 2001 From: paulburdick Date: Wed, 27 Jun 2007 23:25:19 +0000 Subject: *Modified the Router so that when Query Strings are Enabled, the controller trigger and function trigger values are sanitized for filename include security. --- system/libraries/Router.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 6c3062c07..e2a14800d 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -49,6 +49,7 @@ class CI_Router { function CI_Router() { $this->config =& load_class('Config'); + $this->input =& load_class('Input'); $this->_set_route_mapping(); log_message('debug', "Router Class Initialized"); } @@ -482,7 +483,7 @@ class CI_Router { */ function set_class($class) { - $this->class = $class; + $this->class = $this->input->filename_security($class); } // -------------------------------------------------------------------- @@ -509,7 +510,7 @@ class CI_Router { */ function set_method($method) { - $this->method = $method; + $this->method = $this->input->filename_security($method); } // -------------------------------------------------------------------- @@ -541,7 +542,7 @@ class CI_Router { */ function set_directory($dir) { - $this->directory = $dir.'/'; + $this->directory = $this->input->filename_security($dir).'/'; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 763064b8661f92953497d6ca094d687e9078903f Mon Sep 17 00:00:00 2001 From: paulburdick Date: Wed, 27 Jun 2007 23:25:55 +0000 Subject: *Added filename_security() method to Input library *Modified the Router so that when Query Strings are Enabled, the controller trigger and function trigger values are sanitized for filename include security. --- system/libraries/Input.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 9a73ab9b9..337eeff30 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -444,6 +444,56 @@ class CI_Input { // -------------------------------------------------------------------- + /** + * Filename Security + * + * @access public + * @param string + * @return string + */ + function filename_security($str) + { + $bad = array( + "../", + "./", + "", + "<", + ">", + "'", + '"', + '&', + '$', + '#', + '{', + '}', + '[', + ']', + '=', + ';', + '?', + '/', + "%20", + "%22", + "%3c", // < + "%253c", // < + "%3e", // > + "%0e", // > + "%28", // ( + "%29", // ) + "%2528", // ( + "%26", // & + "%24", // $ + "%3f", // ? + "%3b", // ; + "%3d" // = + ); + + return stripslashes(str_replace($bad, '', $str)); + } + + // -------------------------------------------------------------------- + /** * XSS Clean * -- cgit v1.2.3-24-g4f1b From 01f0888f7d574b92104f8aedf77ab5426d753fd3 Mon Sep 17 00:00:00 2001 From: paulburdick Date: Wed, 27 Jun 2007 23:47:39 +0000 Subject: --- system/libraries/Input.php | 1 - 1 file changed, 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 337eeff30..33f288688 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -472,7 +472,6 @@ class CI_Input { '=', ';', '?', - '/', "%20", "%22", "%3c", // < -- cgit v1.2.3-24-g4f1b From 691010e72ec7fb4a05740332a10b5f046a82c666 Mon Sep 17 00:00:00 2001 From: paulburdick Date: Thu, 28 Jun 2007 00:02:30 +0000 Subject: Instead of doing file name security for Enable Query Strings, I am using the already existin _filter_uri() --- system/libraries/Router.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index e2a14800d..6af6ad380 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -49,7 +49,6 @@ class CI_Router { function CI_Router() { $this->config =& load_class('Config'); - $this->input =& load_class('Input'); $this->_set_route_mapping(); log_message('debug', "Router Class Initialized"); } @@ -71,11 +70,11 @@ class CI_Router { // If so, we're done since segment based URIs are not used with query strings. if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) { - $this->set_class($_GET[$this->config->item('controller_trigger')]); + $this->set_class(trim($this->_filter_uri($_GET[$this->config->item('controller_trigger')]))); if (isset($_GET[$this->config->item('function_trigger')])) { - $this->set_method($_GET[$this->config->item('function_trigger')]); + $this->set_method(trim($this->_filter_uri($_GET[$this->config->item('function_trigger')]))); } return; @@ -483,7 +482,7 @@ class CI_Router { */ function set_class($class) { - $this->class = $this->input->filename_security($class); + $this->class = $class; } // -------------------------------------------------------------------- @@ -510,7 +509,7 @@ class CI_Router { */ function set_method($method) { - $this->method = $this->input->filename_security($method); + $this->method = $method; } // -------------------------------------------------------------------- @@ -542,7 +541,7 @@ class CI_Router { */ function set_directory($dir) { - $this->directory = $this->input->filename_security($dir).'/'; + $this->directory = $dir.'/'; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From c39a41f4615378b9b7b112a1b6cd37f358533493 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 11 Jul 2007 17:26:21 +0000 Subject: fixed log message typo --- system/libraries/User_agent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index b93bd340e..ea5db4d78 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -71,7 +71,7 @@ class CI_User_agent { } } - log_message('debug', "Table Class Initialized"); + log_message('debug', "User Agent Class Initialized"); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 9687c493de92eb71a91ed89723abd4ede977bb3d Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 11 Jul 2007 21:43:23 +0000 Subject: bugfix for profiler output: POST keys were not being displayed properly, and queries needed htmlspecialchars() --- system/libraries/Profiler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index ffd664a88..6b1d5ea71 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -123,7 +123,7 @@ class CI_Profiler { foreach ($this->CI->db->queries as $val) { $output .= '
'; - $output .= $val; + $output .= htmlspecialchars($val, ENT_QUOTES); $output .= "
\n"; } } @@ -166,7 +166,7 @@ class CI_Profiler { } // $output .= "$_POST[".$key."]  ".htmlspecialchars(stripslashes($val))."\n"; - $output .= "".$_POST[$key]." "; + $output .= "$_POST[".$key."]   "; if (is_array($val)) { $output .= "
" . htmlspecialchars(stripslashes(print_r($val, true))) . "
"; -- cgit v1.2.3-24-g4f1b From 2d2437edf10edf2669dd85e5943bd4061216eef0 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 12 Jul 2007 11:32:37 +0000 Subject: fixed quoted-printable in HTML emails, and added htmlspecialchars() to email debugging output --- system/libraries/Email.php | 104 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 100 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 7b7dc091c..c7aeb33c8 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -45,6 +45,11 @@ class CI_Email { var $validate = FALSE; // true/false. Enables email validation var $priority = "3"; // Default priority (1 - 5) var $newline = "\n"; // Default newline. "\r\n" or "\n" (Use "\r\n" to comply with RFC 822) + + var $crlf = "\n"; // The RFC 2045 compliant CRLF for quoted-printable is "\r\n". Apparently some servers, + // even on the receiving end think they need to muck with CRLFs, so using "\n", while + // distasteful, is the only thing that seems to work for all environments. + var $bcc_batch_mode = FALSE; // true/false Turns on/off Bcc batch feature var $bcc_batch_size = 200; // If bcc_batch_mode = true, sets max number of Bccs in each batch var $_subject = ""; @@ -924,7 +929,7 @@ class CI_Email { break; case 'html' : - + $hdr .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline; $hdr .= $this->_get_mime_message() . $this->newline . $this->newline; $hdr .= "--" . $this->_alt_boundary . $this->newline; @@ -934,7 +939,9 @@ class CI_Email { $hdr .= $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline; $hdr .= "Content-Type: text/html; charset=" . $this->charset . $this->newline; - $hdr .= "Content-Transfer-Encoding: quoted/printable"; + $hdr .= "Content-Transfer-Encoding: quoted-printable"; + + $this->_body = $this->_prep_quoted_printable($this->_body); if ($this->_get_protocol() == 'mail') { @@ -985,7 +992,9 @@ class CI_Email { $hdr .= $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline; $hdr .= "Content-Type: text/html; charset=" . $this->charset . $this->newline; - $hdr .= "Content-Transfer-Encoding: quoted/printable"; + $hdr .= "Content-Transfer-Encoding: quoted-printable"; + + $this->_body = $this->_prep_quoted_printable($this->_body); if ($this->_get_protocol() == 'mail') { @@ -1050,7 +1059,94 @@ class CI_Email { } // -------------------------------------------------------------------- + + /** + * Prep Quoted Printable + * + * Prepares string for Quoted-Printable Content-Transfer-Encoding + * Refer to RFC 2045 http://www.ietf.org/rfc/rfc2045.txt + * + * @access public + * @param string + * @param integer + * @return string + */ + function _prep_quoted_printable($str, $charlim = '') + { + // Set the character limit + // Don't allow over 76, as that will make servers and MUAs barf + // all over quoted-printable data + if ($charlim == '' OR $charlim > '76') + { + $charlim = '76'; + } + + // Reduce multiple spaces + $str = preg_replace("| +|", " ", $str); + + // Standardize newlines + $str = preg_replace("/\r\n|\r/", "\n", $str); + + // We are intentionally wrapping so mail servers will encode characters + // properly and MUAs will behave, so {unwrap} must go! + $str = str_replace(array('{unwrap}', '{/unwrap}'), '', $str); + + // Break into an array of lines + $lines = preg_split("/\n/", $str); + $escape = '='; + $output = ''; + + foreach ($lines as $line) + { + $length = strlen($line); + $temp = ''; + + // Loop through each character in the line to add soft-wrap + // characters at the end of a line " =\r\n" and add the newly + // processed line(s) to the output (see comment on $crlf class property) + for ($i = 0; $i < $length; $i++) + { + // Grab the next character + $char = substr($line, $i, 1); + $ascii = ord($char); + + // Convert spaces and tabs but only if it's the end of the line + if ($i == ($length - 1)) + { + $char = ($ascii == '32' OR $ascii == '9') ? $escape.sprintf('%02s', dechex($char)) : $char; + } + + // encode = signs + if ($ascii == '61') + { + $char = $escape.strtoupper(sprintf('%02s', dechex($ascii))); // =3D + } + + // If we're at the character limit, add the line to the output, + // reset our temp variable, and keep on chuggin' + if ((strlen($temp) + strlen($char)) >= $charlim) + { + $output .= $temp.$escape.$this->crlf; + $temp = ''; + } + + // Add the character to our temporary line + $temp .= $char; + } + + // Add our completed line to the output + $output .= $temp.$this->crlf; + } + + // get rid of extra CRLF tacked onto the end + $output = substr($output, 0, strlen($this->crlf) * -1); + + return $output; + } + + // -------------------------------------------------------------------- + /** * Send Email * @@ -1583,7 +1679,7 @@ class CI_Email { } } - $msg .= "
".$this->_header_str."\n".$this->_subject."\n".$this->_finalbody.'
'; + $msg .= "
".$this->_header_str."\n".htmlspecialchars($this->_subject)."\n".htmlspecialchars($this->_finalbody).'
'; return $msg; } -- cgit v1.2.3-24-g4f1b From c9e2b10f08a3c718e52e287e2dd14b880e4e3057 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 12 Jul 2007 12:14:45 +0000 Subject: added language files to autoload --- system/libraries/Language.php | 5 ----- system/libraries/Loader.php | 25 ++++++++++++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Language.php b/system/libraries/Language.php index 26775ec7e..94923a3e7 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -89,11 +89,6 @@ class CI_Language { return; } - if ($return == TRUE) - { - return $lang; - } - $this->is_loaded[] = $langfile; $this->language = array_merge($this->language, $lang); unset($lang); diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index abe3a1c37..7fa46c3ad 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -481,13 +481,24 @@ class CI_Loader { * Loads a language file * * @access public + * @param array * @param string + * @param bool * @return void */ - function language($file = '', $lang = '', $return = FALSE) + function language($file = array(), $lang = '') { $CI =& get_instance(); - return $CI->lang->load($file, $lang, $return); + + if ( ! is_array($file)) + { + $file = array($file); + } + + foreach ($file as $langfile) + { + $CI->lang->load($langfile, $lang); + } } // -------------------------------------------------------------------- @@ -813,7 +824,7 @@ class CI_Loader { return FALSE; } - // Load any custome config file + // Load any custom config file if (count($autoload['config']) > 0) { $CI =& get_instance(); @@ -823,15 +834,15 @@ class CI_Loader { } } - // Load plugins, helpers, and scripts - foreach (array('helper', 'plugin', 'script') as $type) - { + // Autoload plugins, helpers, scripts and languages + foreach (array('helper', 'plugin', 'script', 'language') as $type) + { if (isset($autoload[$type]) AND count($autoload[$type]) > 0) { $this->$type($autoload[$type]); } } - + // A little tweak to remain backward compatible // The $autoload['core'] item was deprecated if ( ! isset($autoload['libraries'])) -- cgit v1.2.3-24-g4f1b From 48bb32aece18e9dce381602e242609adfc71b0d0 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 12 Jul 2007 13:10:42 +0000 Subject: further xss_clean() enhancements --- system/libraries/Input.php | 97 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 67 insertions(+), 30 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 33f288688..fcca722b7 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -538,15 +538,15 @@ class CI_Input { * the conversion of entities to ASCII later. * */ - $str = preg_replace('#(&\#*\w+)[\x00-\x20]+;#u',"\\1;",$str); + $str = preg_replace('#(&\#?[0-9a-z]+)[\x00-\x20]*;?#i', "\\1;", $str); /* - * Validate UTF16 two byte encoding (x00) + * Validate UTF16 two byte encoding (x00) * * Just as above, adds a semicolon if missing. * */ - $str = preg_replace('#(&\#x*)([0-9A-F]+);*#iu',"\\1\\2;",$str); + $str = preg_replace('#(&\#x?)([0-9A-F]+);?#i',"\\1\\2;",$str); /* * URL Decode @@ -580,37 +580,50 @@ class CI_Input { $str); } } - + + /* + * Convert all tabs to spaces + * + * This prevents strings like this: ja vascript + * NOTE: we deal with spaces between characters later. + * NOTE: preg_replace was found to be amazingly slow here on large blocks of data, + * so we use str_replace. + * + */ + + $str = str_replace("\t", " ", $str); + /* * Not Allowed Under Any Conditions */ $bad = array( 'document.cookie' => '[removed]', + 'document.write' => '[removed]', '.parentNode' => '[removed]', '.innerHTML' => '[removed]', - 'document.write' => '[removed]', 'window.location' => '[removed]', + '-moz-binding' => '[removed]', + '' => '-->', + ' '<![CDATA[' + ); + + foreach ($bad as $key => $val) + { + $str = str_replace($key, $val, $str); + } + + $bad = array( "javascript\s*:" => '[removed]', "expression\s*\(" => '[removed]', // CSS and IE - "Redirect\s+302" => '[removed]', - '' => '-->' + "Redirect\s+302" => '[removed]' ); - + foreach ($bad as $key => $val) { $str = preg_replace("#".$key."#i", $val, $str); } - /* - * Convert all tabs to spaces - * - * This prevents strings like this: ja vascript - * Note: we deal with spaces between characters later. - * - */ - $str = preg_replace("#\t+#", " ", $str); - /* * Makes PHP tags safe * @@ -621,7 +634,7 @@ class CI_Input { * But it doesn't seem to pose a problem. * */ - $str = str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); + $str = str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); /* * Compact any exploded words @@ -650,10 +663,24 @@ class CI_Input { do { $original = $str; - - $str = preg_replace_callback("##si", array($this, '_js_link_removal'), $str); - $str = preg_replace_callback("##si", array($this, '_js_img_removal'), $str); - $str = preg_replace("##si", "", $str); + + if ((version_compare(PHP_VERSION, '5.0', '>=') === TRUE && stripos($str, '') !== FALSE) OR + preg_match("/<\/a>/i", $str)) + { + $str = preg_replace_callback("##si", array($this, '_js_link_removal'), $str); + } + + if ((version_compare(PHP_VERSION, '5.0', '>=') === TRUE && stripos($str, '#si", array($this, '_js_img_removal'), $str); + } + + if ((version_compare(PHP_VERSION, '5.0', '>=') === TRUE && (stripos($str, 'script') !== FALSE OR stripos($str, 'xss') !== FALSE)) OR + preg_match("/(script|xss)/i", $str)) + { + $str = preg_replace("##si", "", $str); + } } while($original != $str); @@ -706,20 +733,30 @@ class CI_Input { */ $bad = array( 'document.cookie' => '[removed]', + 'document.write' => '[removed]', '.parentNode' => '[removed]', '.innerHTML' => '[removed]', - 'document.write' => '[removed]', 'window.location' => '[removed]', + '-moz-binding' => '[removed]', + '' => '-->', + ' '<![CDATA[' + ); + + foreach ($bad as $key => $val) + { + $str = str_replace($key, $val, $str); + } + + $bad = array( "javascript\s*:" => '[removed]', "expression\s*\(" => '[removed]', // CSS and IE - "Redirect\s+302" => '[removed]', - '' => '-->' + "Redirect\s+302" => '[removed]' ); - + foreach ($bad as $key => $val) { - $str = preg_replace("#".$key."#i", $val, $str); + $str = preg_replace("#".$key."#i", $val, $str); } @@ -764,7 +801,7 @@ class CI_Input { } // -------------------------------------------------------------------- - + /** * HTML Entities Decode * -- cgit v1.2.3-24-g4f1b From e5808cf64d1177127cc9f26e6f681b412a192339 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 12 Jul 2007 13:36:56 +0000 Subject: removed $return argument from load() --- system/libraries/Language.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Language.php b/system/libraries/Language.php index 94923a3e7..bcf84cf67 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -49,7 +49,7 @@ class CI_Language { * @param string the language (english, etc.) * @return void */ - function load($langfile = '', $idiom = '', $return = FALSE) + function load($langfile = '', $idiom = '') { $langfile = str_replace(EXT, '', str_replace('_lang.', '', $langfile)).'_lang'.EXT; @@ -82,7 +82,6 @@ class CI_Language { } } - if ( ! isset($lang)) { log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile); -- cgit v1.2.3-24-g4f1b From 303c9cb958a52ef2d13e985da397cb49590113b0 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 12 Jul 2007 19:12:37 +0000 Subject: added attribute and html entity decode callbacks to xss_clean() --- system/libraries/Input.php | 80 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 69 insertions(+), 11 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index fcca722b7..ba94d854f 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -519,7 +519,7 @@ class CI_Input { * @param string * @return string */ - function xss_clean($str, $charset = 'ISO-8859-1') + function xss_clean($str) { /* * Remove Null Characters @@ -564,23 +564,46 @@ class CI_Input { $str = str_replace('9u3iovBnRThju941s89rKozm', "%20", $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 * these are the ones that will pose security problems. * */ - if (preg_match_all("/<(.+?)>/si", $str, $matches)) - { - for ($i = 0; $i < count($matches['0']); $i++) + + $str = preg_replace_callback("/[a-z]+=([\'\"]).*?\\1/si", array($this, '_attribute_conversion'), $str); + + $str = preg_replace_callback("/<([\w]+)[^>]*>/si", array($this, '_html_entity_decode_callback'), $str); + + /* + + Old Code that when modified to use preg_replace()'s above became more efficient memory-wise + + if (preg_match_all("/[a-z]+=([\'\"]).*?\\1/si", $str, $matches)) + { + for ($i = 0; $i < count($matches[0]); $i++) + { + if (stristr($matches[0][$i], '>')) + { + $str = str_replace( $matches['0'][$i], + str_replace('>', '<', $matches[0][$i]), + $str); + } + } + } + + if (preg_match_all("/<([\w]+)[^>]*>/si", $str, $matches)) + { + for ($i = 0; $i < count($matches[0]); $i++) { - $str = str_replace($matches['1'][$i], - $this->_html_entity_decode($matches['1'][$i], $charset), + $str = str_replace($matches[0][$i], + $this->_html_entity_decode($matches[0][$i], $charset), $str); } } - + */ + /* * Convert all tabs to spaces * @@ -801,7 +824,42 @@ class CI_Input { } // -------------------------------------------------------------------- - + + /** + * Attribute Conversion + * + * Used as a callback for XSS Clean + * + * @access public + * @param array + * @return string + */ + function _attribute_conversion($match) + { + return str_replace('>', '<', $match[0]); + } + + // -------------------------------------------------------------------- + + /** + * HTML Entity Decode Callback + * + * Used as a callback for XSS Clean + * + * @access public + * @param array + * @return string + */ + function _html_entity_decode_callback($match) + { + $CI =& get_instance(); + $charset = $CI->config->item('charset'); + + return $this->_html_entity_decode($match[0], strtoupper($charset)); + } + + // -------------------------------------------------------------------- + /** * HTML Entities Decode * @@ -826,10 +884,10 @@ class CI_Input { character set, and the PHP developers said they were not back porting the fix to versions other than PHP 5.x. */ - function _html_entity_decode($str, $charset='ISO-8859-1') + function _html_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 -- cgit v1.2.3-24-g4f1b From 79ecefd0ec2cc7e2bcf35fad4f80e22d9ac70e16 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 15 Jul 2007 22:49:07 +0000 Subject: fix for scaffolding --- system/libraries/Language.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Language.php b/system/libraries/Language.php index bcf84cf67..26775ec7e 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -49,7 +49,7 @@ class CI_Language { * @param string the language (english, etc.) * @return void */ - function load($langfile = '', $idiom = '') + function load($langfile = '', $idiom = '', $return = FALSE) { $langfile = str_replace(EXT, '', str_replace('_lang.', '', $langfile)).'_lang'.EXT; @@ -82,12 +82,18 @@ class CI_Language { } } + if ( ! isset($lang)) { log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile); return; } + if ($return == TRUE) + { + return $lang; + } + $this->is_loaded[] = $langfile; $this->language = array_merge($this->language, $lang); unset($lang); -- cgit v1.2.3-24-g4f1b From 873c722774f8cc43c737b5ee0befd8e6a0796bc8 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 15 Jul 2007 23:03:05 +0000 Subject: further scaffolding language fixes --- system/libraries/Loader.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 7fa46c3ad..ee99696a0 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -500,6 +500,19 @@ class CI_Loader { $CI->lang->load($langfile, $lang); } } + + /** + * Loads a language file + * + * @access public + * @param string + * @return void + */ + function scaffold_language($file = '', $lang = '', $return = FALSE) + { + $CI =& get_instance(); + return $CI->lang->load($file, $lang, $return); + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 5808a11cedc9bc825450dc3d652e0a4a45b02b4f Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 15 Jul 2007 23:19:08 +0000 Subject: comment clean up --- system/libraries/Loader.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index ee99696a0..2e762e9f1 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -483,7 +483,6 @@ class CI_Loader { * @access public * @param array * @param string - * @param bool * @return void */ function language($file = array(), $lang = '') @@ -502,11 +501,11 @@ class CI_Loader { } /** - * Loads a language file + * Loads language files for scaffolding * * @access public * @param string - * @return void + * @return arra */ function scaffold_language($file = '', $lang = '', $return = FALSE) { -- cgit v1.2.3-24-g4f1b From 6159d1dd0945490d1425ae3269dc3172680a3c91 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 16 Jul 2007 13:04:46 +0000 Subject: Switched from CI super object to $CFG to fetch charset --- system/libraries/Input.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index ba94d854f..b41dcfb29 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -852,8 +852,8 @@ class CI_Input { */ function _html_entity_decode_callback($match) { - $CI =& get_instance(); - $charset = $CI->config->item('charset'); + global $CFG; + $charset = $CFG->item('charset'); return $this->_html_entity_decode($match[0], strtoupper($charset)); } -- cgit v1.2.3-24-g4f1b From 30b40153739419d50c64e2dce338166a5c58ab58 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 20 Jul 2007 00:01:13 +0000 Subject: --- system/libraries/Output.php | 4 +- system/libraries/Router.php | 247 +++++--------------------------------------- system/libraries/URI.php | 244 +++++++++++++++++++++++++++++++++++++++++-- system/libraries/Xmlrpc.php | 1 - 4 files changed, 262 insertions(+), 234 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 756d4b4cc..53003f180 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -301,7 +301,7 @@ class CI_Output { function _display_cache(&$CFG, &$RTR) { $CFG =& load_class('Config'); - $RTR =& load_class('Router'); + $URI =& load_class('URI'); $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); @@ -313,7 +313,7 @@ class CI_Output { // Build the file path. The file name is an MD5 hash of the full URI $uri = $CFG->item('base_url'). $CFG->item('index_page'). - $RTR->uri_string; + $URI->uri_string; $filepath = $cache_path.md5($uri); diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 6af6ad380..6fca45227 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -28,10 +28,7 @@ */ class CI_Router { - var $config; - var $uri_string = ''; - var $segments = array(); - var $rsegments = array(); + var $config; var $routes = array(); var $error_routes = array(); var $class = ''; @@ -49,7 +46,8 @@ class CI_Router { function CI_Router() { $this->config =& load_class('Config'); - $this->_set_route_mapping(); + $this->uri =& load_class('URI'); + $this->_set_routing(); log_message('debug', "Router Class Initialized"); } @@ -64,17 +62,17 @@ class CI_Router { * @access private * @return void */ - function _set_route_mapping() + function _set_routing() { // Are query strings enabled in the config file? // If so, we're done since segment based URIs are not used with query strings. if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) { - $this->set_class(trim($this->_filter_uri($_GET[$this->config->item('controller_trigger')]))); + $this->set_class(trim($this->uri->_filter_uri($_GET[$this->config->item('controller_trigger')]))); if (isset($_GET[$this->config->item('function_trigger')])) { - $this->set_method(trim($this->_filter_uri($_GET[$this->config->item('function_trigger')]))); + $this->set_method(trim($this->uri->_filter_uri($_GET[$this->config->item('function_trigger')]))); } return; @@ -90,16 +88,10 @@ class CI_Router { $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); // Fetch the complete URI string - $this->uri_string = $this->_get_uri_string(); - - // If the URI contains only a slash we'll kill it - if ($this->uri_string == '/') - { - $this->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_string == '') + if ($this->uri->uri_string == '') { if ($this->default_controller === FALSE) { @@ -114,47 +106,35 @@ class CI_Router { } unset($this->routes['default_controller']); - // Do we need to remove the suffix specified in the config file? - if ($this->config->item('url_suffix') != "") - { - $this->uri_string = preg_replace("|".preg_quote($this->config->item('url_suffix'))."$|", "", $this->uri_string); - } + // Do we need to remove the URL suffix? + $this->uri->_remove_url_suffix(); - // Explode the URI Segments. The individual segments will - // be stored in the $this->segments array. - foreach(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val) - { - // Filter segments for security - $val = trim($this->_filter_uri($val)); - - if ($val != '') - $this->segments[] = $val; - } + // Compile the segments into an array + $this->uri->_explode_segments(); // Parse any custom routing that may exist $this->_parse_routes(); // Re-index the segment array so that it starts with 1 rather than 0 - $this->_reindex_segments(); + $this->uri->_reindex_segments(); } // -------------------------------------------------------------------- /** - * Compile Segments + * Set the Route * * This function takes an array of URI segments as - * input, and puts it into the $this->segments array. - * It also sets the current class/method + * input, and sets the current class/method * * @access private * @param array * @param bool * @return void */ - function _compile_segments($segments = array()) + function _set_request($segments = array()) { - $segments = $this->_validate_segments($segments); + $segments = $this->_validate_request($segments); if (count($segments) == 0) { @@ -180,8 +160,8 @@ class CI_Router { // Update our "routed" segment array to contain the segments. // Note: If there is no custom routing, this array will be - // identical to $this->segments - $this->rsegments = $segments; + // identical to $this->uri->segments + $this->uri->rsegments = $segments; } // -------------------------------------------------------------------- @@ -194,7 +174,7 @@ class CI_Router { * @param array * @return array */ - function _validate_segments($segments) + function _validate_request($segments) { // Does the requested controller exist in the root folder? if (file_exists(APPPATH.'controllers/'.$segments[0].EXT)) @@ -237,182 +217,7 @@ class CI_Router { // Can't find the requested controller... show_404(); } - - // -------------------------------------------------------------------- - /** - * Re-index Segments - * - * This function re-indexes the $this->segment array so that it - * starts at 1 rather then 0. Doing so makes it simpler to - * use functions like $this->uri->segment(n) since there is - * a 1:1 relationship between the segment array and the actual segments. - * - * @access private - * @return void - */ - function _reindex_segments() - { - // Is the routed segment array different then the main segment array? - $diff = (count(array_diff($this->rsegments, $this->segments)) == 0) ? FALSE : TRUE; - - $i = 1; - foreach ($this->segments as $val) - { - $this->segments[$i++] = $val; - } - unset($this->segments[0]); - if ($diff == FALSE) - { - $this->rsegments = $this->segments; - } - else - { - $i = 1; - foreach ($this->rsegments as $val) - { - $this->rsegments[$i++] = $val; - } - unset($this->rsegments[0]); - } - } - - // -------------------------------------------------------------------- - - /** - * Get the URI String - * - * @access private - * @return string - */ - function _get_uri_string() - { - if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') - { - // If the URL has a question mark then it's simplest to just - // build the URI string from the zero index of the $_GET array. - // This avoids having to deal with $_SERVER variables, which - // can be unreliable in some environments - if (is_array($_GET) AND count($_GET) == 1) - { - // Note: Due to a bug in current() that affects some versions - // of PHP we can not pass function call directly into it - $keys = array_keys($_GET); - return current($keys); - } - - // Is there a PATH_INFO variable? - // Note: some servers seem to have trouble with getenv() so we'll test it two ways - $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); - if ($path != '' AND $path != "/".SELF) - { - return $path; - } - - // No PATH_INFO?... What about QUERY_STRING? - $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); - if ($path != '') - { - return $path; - } - - // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists? - $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); - if ($path != '' AND $path != "/".SELF) - { - return $path; - } - - // We've exhausted all our options... - return ''; - } - else - { - $uri = strtoupper($this->config->item('uri_protocol')); - - if ($uri == 'REQUEST_URI') - { - return $this->_parse_request_uri(); - } - - return (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); - } - } - - // -------------------------------------------------------------------- - - /** - * Parse the REQUEST_URI - * - * Due to the way REQUEST_URI works it usually contains path info - * that makes it unusable as URI data. We'll trim off the unnecessary - * data, hopefully arriving at a valid URI that we can use. - * - * @access private - * @return string - */ - function _parse_request_uri() - { - if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '') - { - return ''; - } - - $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI'])); - - if ($request_uri == '' OR $request_uri == SELF) - { - return ''; - } - - $fc_path = FCPATH; - if (strpos($request_uri, '?') !== FALSE) - { - $fc_path .= '?'; - } - - $parsed_uri = explode("/", $request_uri); - - $i = 0; - foreach(explode("/", $fc_path) as $segment) - { - if (isset($parsed_uri[$i]) AND $segment == $parsed_uri[$i]) - { - $i++; - } - } - - $parsed_uri = implode("/", array_slice($parsed_uri, $i)); - - if ($parsed_uri != '') - { - $parsed_uri = '/'.$parsed_uri; - } - - return $parsed_uri; - } - - // -------------------------------------------------------------------- - - /** - * Filter segments for malicious characters - * - * @access private - * @param string - * @return string - */ - function _filter_uri($str) - { - if ($this->config->item('permitted_uri_chars') != '') - { - if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) - { - exit('The URI you submitted has disallowed characters.'); - } - } - return $str; - } - // -------------------------------------------------------------------- /** @@ -431,18 +236,18 @@ class CI_Router { // There is a default scaffolding trigger, so we'll look just for 1 if (count($this->routes) == 1) { - $this->_compile_segments($this->segments); + $this->_set_request($this->uri->segments); return; } // Turn the segment array into a URI string - $uri = implode('/', $this->segments); - $num = count($this->segments); + $uri = implode('/', $this->uri->segments); + $num = count($this->uri->segments); // Is there a literal match? If so we're done if (isset($this->routes[$uri])) { - $this->_compile_segments(explode('/', $this->routes[$uri])); + $this->_set_request(explode('/', $this->routes[$uri])); return; } @@ -461,14 +266,14 @@ class CI_Router { $val = preg_replace('#^'.$key.'$#', $val, $uri); } - $this->_compile_segments(explode('/', $val)); + $this->_set_request(explode('/', $val)); return; } } // If we got this far it means we didn't encounter a // matching route so we'll set the site default route - $this->_compile_segments($this->segments); + $this->_set_request($this->uri->segments); } // -------------------------------------------------------------------- diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 5cedd8e0f..2777e2f18 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -28,8 +28,10 @@ */ class CI_URI { - var $router; var $keyval = array(); + var $uri_string; + var $segments = array(); + var $rsegments = array(); /** * Constructor @@ -42,10 +44,229 @@ class CI_URI { */ function CI_URI() { - $this->router =& load_class('Router'); + $this->config =& load_class('Config'); log_message('debug', "URI Class Initialized"); } + + // -------------------------------------------------------------------- + + /** + * Get the URI String + * + * @access private + * @return string + */ + function _fetch_uri_string() + { + if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') + { + // If the URL has a question mark then it's simplest to just + // build the URI string from the zero index of the $_GET array. + // This avoids having to deal with $_SERVER variables, which + // can be unreliable in some environments + if (is_array($_GET) AND count($_GET) == 1) + { + // Note: Due to a bug in current() that affects some versions + // of PHP we can not pass function call directly into it + $keys = array_keys($_GET); + $this->uri_string = current($keys); + } + + // Is there a PATH_INFO variable? + // Note: some servers seem to have trouble with getenv() so we'll test it two ways + $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); + if ($path != '' AND $path != "/".SELF) + { + $this->uri_string = $path; + } + + // No PATH_INFO?... What about QUERY_STRING? + $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); + if ($path != '') + { + $this->uri_string = $path; + } + + // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists? + $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); + if ($path != '' AND $path != "/".SELF) + { + $this->uri_string = $path; + } + + // We've exhausted all our options... + $this->uri_string = ''; + } + else + { + $uri = strtoupper($this->config->item('uri_protocol')); + + if ($uri == 'REQUEST_URI') + { + $this->uri_string = $this->_parse_request_uri(); + } + + $this->uri_string = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); + } + + // If the URI contains only a slash we'll kill it + if ($this->uri_string == '/') + { + $this->uri_string = ''; + } + } + + // -------------------------------------------------------------------- + + /** + * Parse the REQUEST_URI + * + * Due to the way REQUEST_URI works it usually contains path info + * that makes it unusable as URI data. We'll trim off the unnecessary + * data, hopefully arriving at a valid URI that we can use. + * + * @access private + * @return string + */ + function _parse_request_uri() + { + if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '') + { + return ''; + } + + $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI'])); + + if ($request_uri == '' OR $request_uri == SELF) + { + return ''; + } + + $fc_path = FCPATH; + if (strpos($request_uri, '?') !== FALSE) + { + $fc_path .= '?'; + } + + $parsed_uri = explode("/", $request_uri); + + $i = 0; + foreach(explode("/", $fc_path) as $segment) + { + if (isset($parsed_uri[$i]) AND $segment == $parsed_uri[$i]) + { + $i++; + } + } + + $parsed_uri = implode("/", array_slice($parsed_uri, $i)); + + if ($parsed_uri != '') + { + $parsed_uri = '/'.$parsed_uri; + } + + return $parsed_uri; + } + + // -------------------------------------------------------------------- + + /** + * Filter segments for malicious characters + * + * @access private + * @param string + * @return string + */ + function _filter_uri($str) + { + if ($this->config->item('permitted_uri_chars') != '') + { + if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) + { + exit('The URI you submitted has disallowed characters.'); + } + } + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Remove the suffix from the URL if needed + * + * @access private + * @return void + */ + function _remove_url_suffix() + { + if ($this->config->item('url_suffix') != "") + { + $this->uri_string = preg_replace("|".preg_quote($this->config->item('url_suffix'))."$|", "", $this->uri_string); + } + } + + // -------------------------------------------------------------------- + + /** + * Explode the URI Segments. The individual segments will + * be stored in the $this->segments array. + * + * @access private + * @return void + */ + function _explode_segments() + { + foreach(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val) + { + // Filter segments for security + $val = trim($this->_filter_uri($val)); + + if ($val != '') + $this->segments[] = $val; + } + } + + // -------------------------------------------------------------------- + /** + * Re-index Segments + * + * This function re-indexes the $this->segment array so that it + * starts at 1 rather then 0. Doing so makes it simpler to + * use functions like $this->uri->segment(n) since there is + * a 1:1 relationship between the segment array and the actual segments. + * + * @access private + * @return void + */ + function _reindex_segments() + { + // Is the routed segment array different then the main segment array? + $diff = (count(array_diff($this->rsegments, $this->segments)) == 0) ? FALSE : TRUE; + + $i = 1; + foreach ($this->segments as $val) + { + $this->segments[$i++] = $val; + } + unset($this->segments[0]); + + if ($diff == FALSE) + { + $this->rsegments = $this->segments; + } + else + { + $i = 1; + foreach ($this->rsegments as $val) + { + $this->rsegments[$i++] = $val; + } + unset($this->rsegments[0]); + } + } + // -------------------------------------------------------------------- /** @@ -60,7 +281,7 @@ class CI_URI { */ function segment($n, $no_result = FALSE) { - return ( ! isset($this->router->segments[$n])) ? $no_result : $this->router->segments[$n]; + return ( ! isset($this->segments[$n])) ? $no_result : $this->segments[$n]; } // -------------------------------------------------------------------- @@ -79,7 +300,7 @@ class CI_URI { */ function rsegment($n, $no_result = FALSE) { - return ( ! isset($this->router->rsegments[$n])) ? $no_result : $this->router->rsegments[$n]; + return ( ! isset($this->rsegments[$n])) ? $no_result : $this->rsegments[$n]; } // -------------------------------------------------------------------- @@ -203,6 +424,8 @@ class CI_URI { return $retval; } + // -------------------------------------------------------------------- + /** * Generate a URI string from an associative array * @@ -210,7 +433,8 @@ class CI_URI { * @access public * @param array an associative array of key/values * @return array - */ function assoc_to_uri($array) + */ + function assoc_to_uri($array) { $temp = array(); foreach ((array)$array as $key => $val) @@ -293,7 +517,7 @@ class CI_URI { */ function segment_array() { - return $this->router->segments; + return $this->segments; } // -------------------------------------------------------------------- @@ -306,7 +530,7 @@ class CI_URI { */ function rsegment_array() { - return $this->router->rsegments; + return $this->rsegments; } // -------------------------------------------------------------------- @@ -319,7 +543,7 @@ class CI_URI { */ function total_segments() { - return count($this->router->segments); + return count($this->segments); } // -------------------------------------------------------------------- @@ -332,7 +556,7 @@ class CI_URI { */ function total_rsegments() { - return count($this->router->rsegments); + return count($this->rsegments); } // -------------------------------------------------------------------- @@ -345,7 +569,7 @@ class CI_URI { */ function uri_string() { - return $this->router->uri_string; + return $this->uri_string; } diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 49747e481..fc6208e94 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -70,7 +70,6 @@ class CI_Xmlrpc { function CI_Xmlrpc ($config = array()) { - $this->xmlrpcName = $this->xmlrpcName; $this->xmlrpc_backslash = chr(92).chr(92); -- cgit v1.2.3-24-g4f1b From de2623c7a748e2e40ce4f6d64161915ed5141c4e Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sat, 21 Jul 2007 18:28:24 +0000 Subject: --- system/libraries/URI.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 2777e2f18..254a8a6e9 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -58,7 +58,7 @@ class CI_URI { * @return string */ function _fetch_uri_string() - { + { if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') { // If the URL has a question mark then it's simplest to just @@ -71,6 +71,7 @@ class CI_URI { // of PHP we can not pass function call directly into it $keys = array_keys($_GET); $this->uri_string = current($keys); + return; } // Is there a PATH_INFO variable? @@ -79,6 +80,7 @@ class CI_URI { if ($path != '' AND $path != "/".SELF) { $this->uri_string = $path; + return; } // No PATH_INFO?... What about QUERY_STRING? @@ -86,6 +88,7 @@ class CI_URI { if ($path != '') { $this->uri_string = $path; + return; } // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists? @@ -93,6 +96,7 @@ class CI_URI { if ($path != '' AND $path != "/".SELF) { $this->uri_string = $path; + return; } // We've exhausted all our options... @@ -105,6 +109,7 @@ class CI_URI { if ($uri == 'REQUEST_URI') { $this->uri_string = $this->_parse_request_uri(); + return; } $this->uri_string = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); @@ -116,7 +121,7 @@ class CI_URI { $this->uri_string = ''; } } - + // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From 183fe844a99da30c4bc2b4b8d881f6b94310dbc5 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sun, 22 Jul 2007 02:09:13 +0000 Subject: --- system/libraries/Router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 6fca45227..501a8ee82 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -252,7 +252,7 @@ class CI_Router { } // Loop through the route array looking for wild-cards - foreach (array_slice($this->routes, 1) as $key => $val) + foreach ($this->routes as $key => $val) { // Convert wild-cards to RegEx $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); -- cgit v1.2.3-24-g4f1b From 5fbffd780bb24c0fb925ffb26a9036f008d9b664 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Wed, 25 Jul 2007 18:47:11 +0000 Subject: --- system/libraries/URI.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 254a8a6e9..e3cf9c55b 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -69,8 +69,9 @@ class CI_URI { { // Note: Due to a bug in current() that affects some versions // of PHP we can not pass function call directly into it - $keys = array_keys($_GET); - $this->uri_string = current($keys); + $key = array_keys($_GET); + $index = current($key); + $this->uri_string = $_GET[$index]; return; } -- cgit v1.2.3-24-g4f1b From 92a17b18ef42ee310234cdbe57374e6a59169bb9 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 7 Aug 2007 19:22:50 +0000 Subject: fixed DocBlock typo for unset_userdata() --- system/libraries/Session.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 8045017ab..a0fe56274 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -436,7 +436,8 @@ class CI_Session { /** * Delete a session variable from the "userdata" array * - * @access array + * @access public + * @param array * @return void */ function unset_userdata($newdata = array()) -- cgit v1.2.3-24-g4f1b From 428e96442ce4534e337404e5d4a436bd753b7cf6 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 10 Aug 2007 03:16:16 +0000 Subject: Added Flashdata variables, session_id regeneration and configurable session update times to the Session class --- system/libraries/Session.php | 175 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 162 insertions(+), 13 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Session.php b/system/libraries/Session.php index a0fe56274..57106ea2c 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -35,7 +35,8 @@ class CI_Session { var $sess_cookie = 'ci_session'; var $userdata = array(); var $gc_probability = 5; - + var $flashdata_key = 'flash'; + var $time_to_update = 300; // 5 mintues, not accessible from config settings /** * Session Constructor @@ -72,6 +73,12 @@ class CI_Session { * "last_visit" times based on each user's locale. * */ + + if (is_numeric($this->CI->config->item('sess_time_to_update'))) + { + $this->time_to_update = $this->CI->config->item('sess_time_to_update'); + } + if (strtolower($this->CI->config->item('time_reference')) == 'gmt') { $now = time(); @@ -146,7 +153,7 @@ class CI_Session { else { // We only update the session every five minutes - if (($this->userdata['last_activity'] + 300) < $this->now) + if (($this->userdata['last_activity'] + $this->time_to_update) < $this->now) { $this->sess_update(); } @@ -156,7 +163,13 @@ class CI_Session { if ($this->use_database === TRUE) { $this->sess_gc(); - } + } + + // Delete 'old' flashdata (from last request) + $this->_flashdata_sweep(); + + // Mark all new flashdata as old (data will be deleted before next request) + $this->_flashdata_mark(); } // -------------------------------------------------------------------- @@ -313,7 +326,7 @@ class CI_Session { } // Write the cookie - $this->userdata['last_visit'] = 0; + $this->userdata['last_visit'] = 0; $this->sess_write(); } @@ -331,13 +344,25 @@ class CI_Session { { $this->userdata['last_visit'] = $this->userdata['last_activity']; } - + + // Save the old session id so we know which record to + // update in the database if we need it + $old_sessid = $this->userdata['session_id']; + $new_sessid = ''; + while (strlen($new_sessid) < 32) + { + $new_sessid .= mt_rand(0, mt_getrandmax()); + } + $new_sessid = md5(uniqid($new_sessid, TRUE)); + + // Update the session data in the session data array + $this->userdata['session_id'] = $new_sessid; $this->userdata['last_activity'] = $this->now; // Update the session in the DB if needed if ($this->use_database === TRUE) { - $this->CI->db->query($this->CI->db->update_string($this->session_table, array('last_activity' => $this->now), array('session_id' => $this->userdata['session_id']))); + $this->CI->db->query($this->CI->db->update_string($this->session_table, array('last_activity' => $this->now, 'session_id' => $new_sessid), array('session_id' => $old_sessid))); } // Write the cookie @@ -392,7 +417,7 @@ class CI_Session { // -------------------------------------------------------------------- /** - * Fetch a specific item form the session array + * Fetch a specific item from the session array * * @access public * @param string @@ -402,6 +427,19 @@ class CI_Session { { return ( ! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; } + + // -------------------------------------------------------------------- + + /** + * Fetch all session data + * + * @access public + * @return mixed + */ + function all_userdata() + { + return ( ! isset($this->userdata)) ? FALSE : $this->userdata; + } // -------------------------------------------------------------------- @@ -427,7 +465,7 @@ class CI_Session { $this->userdata[$key] = $val; } } - + $this->sess_write(); } @@ -436,8 +474,7 @@ class CI_Session { /** * Delete a session variable from the "userdata" array * - * @access public - * @param array + * @access array * @return void */ function unset_userdata($newdata = array()) @@ -467,9 +504,9 @@ class CI_Session { * @param mixed * @return mixed */ - function strip_slashes($vals) - { - if (is_array($vals)) + function strip_slashes($vals) + { + if (is_array($vals)) { foreach ($vals as $key=>$val) { @@ -484,6 +521,118 @@ class CI_Session { return $vals; } + + // ------------------------------------------------------------------------ + + /** + * Add or change flashdata, only available + * until the next request + * + * @access public + * @param mixed + * @param string + * @return void + */ + function set_flashdata($newdata = array(), $newval = '') + { + if (is_string($newdata)) + { + $newdata = array($newdata => $newval); + } + + if (count($newdata) > 0) + { + foreach ($newdata as $key => $val) + { + $flashdata_key = $this->flashdata_key.':new:'.$key; + $this->set_userdata($flashdata_key, $val); + } + } + } + + // ------------------------------------------------------------------------ + + /** + * Keeps existing flashdata available to next request. + * + * @access public + * @param string + * @return void + */ + function keep_flashdata($key) + { + // 'old' flashdata gets removed. Here we mark all + // flashdata as 'new' to preserve it from _flashdata_sweep() + // Note the function will return FALSE if the $key + // provided cannot be found + $old_flashdata_key = $this->flashdata_key.':old:'.$key; + $value = $this->userdata($old_flashdata_key); + + $new_flashdata_key = $this->flashdata_key.':new:'.$key; + $this->set_userdata($new_flashdata_key, $value); + } + + // ------------------------------------------------------------------------ + + /** + * Fetch a specific flashdata item from the session array + * + * @access public + * @param string + * @return string + */ + function flashdata($key) + { + $flashdata_key = $this->flashdata_key.':old:'.$key; + return $this->userdata($flashdata_key); + } + + // ------------------------------------------------------------------------ + + /** + * Identifies flashdata as 'old' for removal + * when _flashdata_sweep() runs. + * + * @access private + * @return void + */ + function _flashdata_mark() + { + $userdata = $this->all_userdata(); + foreach ($userdata as $name => $value) + { + $parts = explode(':new:', $name); + if (is_array($parts) && count($parts) === 2) + { + $new_name = $this->flashdata_key.':old:'.$parts[1]; + $this->set_userdata($new_name, $value); + $this->unset_userdata($name); + } + } + } + + // ------------------------------------------------------------------------ + + /** + * Removes all flashdata marked as 'old' + * + * @access private + * @return void + */ + + function _flashdata_sweep() + { + $userdata = $this->all_userdata(); + foreach ($userdata as $key => $value) + { + if (strpos($key, ':old:')) + { + $this->unset_userdata($key); + } + } + + } + } // END Session Class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 34bc8f82221d7b2ea331728a1527658c36e39c89 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 10 Aug 2007 03:26:42 +0000 Subject: typo --- system/libraries/Session.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 57106ea2c..819c3f5ef 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -36,7 +36,7 @@ class CI_Session { var $userdata = array(); var $gc_probability = 5; var $flashdata_key = 'flash'; - var $time_to_update = 300; // 5 mintues, not accessible from config settings + var $time_to_update = 300; /** * Session Constructor -- cgit v1.2.3-24-g4f1b From 89bf50f992b97772acb4028bbd7c9faf81899148 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 14 Aug 2007 02:39:04 +0000 Subject: fixed an extraneous ; --- system/libraries/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 6b6ec0c68..10773b213 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -317,7 +317,7 @@ class CI_Validation { } else { - $line = $this->_error_messages[$rule];; + $line = $this->_error_messages[$rule]; } // Build the error message -- cgit v1.2.3-24-g4f1b From 53a9c3f3fdc480a2392f256875d97d41b9ce2625 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 18 Sep 2007 19:18:53 +0000 Subject: Fixed a bug in Validation where valid_ip() wasn't called properly --- system/libraries/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 10773b213..3dfc7be03 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -490,7 +490,7 @@ class CI_Validation { */ function valid_ip($ip) { - return $this->CI->valid_ip($ip); + return $this->CI->input->valid_ip($ip); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 59c26339c0dbf262116c9f1c562bc07034a9ed74 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 1 Oct 2007 12:17:39 +0000 Subject: Fixed a bug in the Session library where user agent matching would fail on user agents ending with a space. --- system/libraries/Session.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 819c3f5ef..9dd277073 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -220,7 +220,7 @@ class CI_Session { } // Does the User Agent Match? - if ($this->CI->config->item('sess_match_useragent') == TRUE AND $session['user_agent'] != substr($this->CI->input->user_agent(), 0, 50)) + if ($this->CI->config->item('sess_match_useragent') == TRUE AND trim($session['user_agent']) != trim(substr($this->CI->input->user_agent(), 0, 50))) { $this->sess_destroy(); return FALSE; -- cgit v1.2.3-24-g4f1b From 6838f00a708f53f834fb8a98af560177db1d1454 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 4 Oct 2007 19:29:59 +0000 Subject: Fixed a typo in the docblock comments that had CodeIgniter spelled CodeIgnitor. --- system/libraries/Benchmark.php | 2 +- system/libraries/Calendar.php | 2 +- system/libraries/Config.php | 2 +- system/libraries/Controller.php | 2 +- system/libraries/Email.php | 2 +- system/libraries/Encrypt.php | 2 +- system/libraries/Exceptions.php | 2 +- system/libraries/Ftp.php | 2 +- system/libraries/Hooks.php | 2 +- system/libraries/Image_lib.php | 2 +- system/libraries/Input.php | 2 +- system/libraries/Language.php | 2 +- system/libraries/Loader.php | 2 +- system/libraries/Log.php | 2 +- system/libraries/Model.php | 2 +- system/libraries/Output.php | 2 +- system/libraries/Pagination.php | 2 +- system/libraries/Parser.php | 2 +- system/libraries/Profiler.php | 2 +- system/libraries/Router.php | 2 +- system/libraries/Session.php | 2 +- system/libraries/Sha1.php | 2 +- system/libraries/Table.php | 2 +- system/libraries/Trackback.php | 2 +- system/libraries/URI.php | 2 +- system/libraries/Unit_test.php | 2 +- system/libraries/Upload.php | 2 +- system/libraries/User_agent.php | 2 +- system/libraries/Validation.php | 2 +- system/libraries/Xmlrpc.php | 2 +- system/libraries/Xmlrpcs.php | 2 +- system/libraries/Zip.php | 2 +- 32 files changed, 32 insertions(+), 32 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index cf980a81e..f677de751 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 5fec40e1c..b6f122353 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Config.php b/system/libraries/Config.php index 831ba925d..6c97cd820 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 81421cf31..0b34465a2 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Email.php b/system/libraries/Email.php index c7aeb33c8..d8ab47281 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index dc952dde3..e5ad78c11 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Exceptions.php b/system/libraries/Exceptions.php index a0630af08..49d64aae3 100644 --- a/system/libraries/Exceptions.php +++ b/system/libraries/Exceptions.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 18f6ff90a..b4bbd23ff 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index bb06fceeb..15e1009aa 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index e79dad445..8922ea695 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Input.php b/system/libraries/Input.php index b41dcfb29..c18ea59fe 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Language.php b/system/libraries/Language.php index 26775ec7e..ffdbcf09d 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 2e762e9f1..051d3d899 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Log.php b/system/libraries/Log.php index b82fe96bd..79fec6c6c 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Model.php b/system/libraries/Model.php index 3b4c2e144..e81d4382b 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 53003f180..7e13316a1 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index c5c718dee..538c42723 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 613668ac8..4e1f9b9a3 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 6b1d5ea71..efd8e07d1 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 501a8ee82..4d04c0072 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 9dd277073..84bb3ee22 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index 451428deb..d282621b4 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 44acce657..d3e88284f 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.3.1 * @filesource diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index 7c13a5034..1d9be60e1 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/URI.php b/system/libraries/URI.php index e3cf9c55b..06a78934c 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 74ed1275f..ccb2e68bc 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.3.1 * @filesource diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index fa1cf1e73..f804dcec8 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index ea5db4d78..67a3c2b88 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 3dfc7be03..33753bc72 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index fc6208e94..9204beac4 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis, Paul Burdick * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 018530216..5ba1dd041 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis, Paul Burdick * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 518c97836..d76d8c97d 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource -- cgit v1.2.3-24-g4f1b From befdc87b1ce6caf47c6f8b1dfa02333dfee8a950 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 9 Oct 2007 13:25:27 +0000 Subject: Added the ability to auto-load Models --- system/libraries/Loader.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 051d3d899..dd639798d 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -107,8 +107,19 @@ class CI_Loader { */ function model($model, $name = '', $db_conn = FALSE) { + if (is_array($model)) + { + foreach($model as $babe) + { + $this->model($babe); + } + return; + } + if ($model == '') + { return; + } // Is the model in a sub-folder? If so, parse out the filename and path. if (strpos($model, '/') === FALSE) @@ -855,6 +866,12 @@ class CI_Loader { } } + // Autoload models + if (isset($autoload['model'])) + { + $this->model($autoload['model']); + } + // A little tweak to remain backward compatible // The $autoload['core'] item was deprecated if ( ! isset($autoload['libraries'])) @@ -875,6 +892,7 @@ class CI_Loader { // Load the model class. if (in_array('model', $autoload['libraries'])) { + die('made it in!'); $this->model(); $autoload['libraries'] = array_diff($autoload['libraries'], array('model')); } -- cgit v1.2.3-24-g4f1b From 6a8f97cd711a8fd545f3fb23edfdbdeb10a61685 Mon Sep 17 00:00:00 2001 From: paulburdick Date: Wed, 10 Oct 2007 15:09:27 +0000 Subject: Put a debug conditional around some debugging code so that it does not use up memory unintentionally. http://codeigniter.com/forums/viewthread/50918/ --- system/libraries/Xmlrpcs.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 5ba1dd041..bdbb85bb8 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -202,7 +202,10 @@ class CI_Xmlrpcs extends CI_Xmlrpc for($i=0; $i < sizeof($parser_object->xh[$parser]['params']); $i++) { - $plist .= "$i - " . print_r(get_object_vars($parser_object->xh[$parser]['params'][$i]), TRUE). ";\n"; + 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]); } -- cgit v1.2.3-24-g4f1b From 3f9e557ed1e5b9d0ea14bba201058b3877a96da8 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 16 Oct 2007 13:10:02 +0000 Subject: Changed the behaviour of custom callbacks so that they no longer trigger the "required" rule. --- system/libraries/Validation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 33753bc72..575c5262e 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -195,7 +195,7 @@ class CI_Validation { $ex = explode('|', $rules); // Is the field required? If not, if the field is blank we'll move on to the next test - if ( ! in_array('required', $ex, TRUE) AND strpos($rules, 'callback_') === FALSE) + if ( ! in_array('required', $ex, TRUE)) { if ( ! isset($_POST[$field]) OR $_POST[$field] == '') { @@ -546,7 +546,7 @@ class CI_Validation { */ function numeric($str) { - return ( ! ereg("^[0-9\.]+$", $str)) ? FALSE : TRUE; + return ! preg_match('/[^0-9]/', $str); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 582e9f8eea096744d530f32854f5ef30759b577e Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 14 Nov 2007 18:41:29 +0000 Subject: Fixed a bug in the Email library where some timezones were calculated incorrectly. --- system/libraries/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index d8ab47281..4cd930892 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -602,7 +602,7 @@ class CI_Email { $timezone = date("Z"); $operator = (substr($timezone, 0, 1) == '-') ? '-' : '+'; $timezone = abs($timezone); - $timezone = ($timezone/3600) * 100 + ($timezone % 3600) /60; + $timezone = floor($timezone/3600) * 100 + ($timezone % 3600 ) / 60; return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone); } -- cgit v1.2.3-24-g4f1b From 9fa308962d8e2141de012feb9c109287611e90b8 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 27 Nov 2007 13:16:46 +0000 Subject: autoloaded models moved to load after libraries are loaded --- system/libraries/Loader.php | 988 +------------------------------------------- 1 file changed, 1 insertion(+), 987 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index dd639798d..87b468ceb 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -1,987 +1 @@ - 'unit', 'user_agent' => 'agent'); - - - /** - * Constructor - * - * Sets the path to the view files and gets the initial output buffering level - * - * @access public - */ - function CI_Loader() - { - $this->_ci_is_php5 = (floor(phpversion()) >= 5) ? TRUE : FALSE; - $this->_ci_view_path = APPPATH.'views/'; - $this->_ci_ob_level = ob_get_level(); - - log_message('debug', "Loader Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Class Loader - * - * This function lets users load and instantiate classes. - * It is designed to be called from a user's app controllers. - * - * @access public - * @param string the name of the class - * @param mixed the optional parameters - * @return void - */ - function library($library = '', $params = NULL) - { - if ($library == '') - { - return FALSE; - } - - if (is_array($library)) - { - foreach ($library as $class) - { - $this->_ci_load_class($class, $params); - } - } - else - { - $this->_ci_load_class($library, $params); - } - - $this->_ci_assign_to_models(); - } - - // -------------------------------------------------------------------- - - /** - * Model Loader - * - * This function lets users load and instantiate models. - * - * @access public - * @param string the name of the class - * @param mixed any initialization parameters - * @return void - */ - function model($model, $name = '', $db_conn = FALSE) - { - if (is_array($model)) - { - foreach($model as $babe) - { - $this->model($babe); - } - return; - } - - if ($model == '') - { - return; - } - - // Is the model in a sub-folder? If so, parse out the filename and path. - if (strpos($model, '/') === FALSE) - { - $path = ''; - } - else - { - $x = explode('/', $model); - $model = end($x); - unset($x[count($x)-1]); - $path = implode('/', $x).'/'; - } - - 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); - - if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT)) - { - show_error('Unable to locate the model you have specified: '.$model); - } - - if ($db_conn !== FALSE AND ! class_exists('CI_DB')) - { - if ($db_conn === TRUE) - $db_conn = ''; - - $CI->load->database($db_conn, FALSE, TRUE); - } - - if ( ! class_exists('Model')) - { - require_once(BASEPATH.'libraries/Model'.EXT); - } - - require_once(APPPATH.'models/'.$path.$model.EXT); - - $model = ucfirst($model); - - $CI->$name = new $model(); - $CI->$name->_assign_libraries(); - - $this->_ci_models[] = $name; - } - - // -------------------------------------------------------------------- - - /** - * Database Loader - * - * @access public - * @param string the DB credentials - * @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 = FALSE) - { - // Do we even need to load the database class? - if (class_exists('CI_DB') AND $return == FALSE AND $active_record == FALSE) - { - return FALSE; - } - - require_once(BASEPATH.'database/DB'.EXT); - - if ($return === TRUE) - { - return DB($params, $active_record); - } - - // Grab the super object - $CI =& get_instance(); - - // Initialize the db variable. Needed to prevent - // reference errors with some configurations - $CI->db = ''; - - // Load the DB class - $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 - */ - function dbutil() - { - if ( ! class_exists('CI_DB')) - { - $this->database(); - } - - $CI =& get_instance(); - - 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'; - - $CI->dbutil = new $class(); - $CI->load->_ci_assign_to_models(); - } - - // -------------------------------------------------------------------- - - /** - * Load View - * - * This function is used to load a "view" file. It has three parameters: - * - * 1. The name of the "view" file to be included. - * 2. An associative array of data to be extracted for use in the view. - * 3. TRUE/FALSE - whether to return the data or load it. In - * some cases it's advantageous to be able to return data so that - * a developer can process it in some way. - * - * @access public - * @param string - * @param array - * @param bool - * @return void - */ - function view($view, $vars = array(), $return = FALSE) - { - return $this->_ci_load(array('view' => $view, 'vars' => $this->_ci_object_to_array($vars), 'return' => $return)); - } - - // -------------------------------------------------------------------- - - /** - * Load File - * - * This is a generic file loader - * - * @access public - * @param string - * @param bool - * @return string - */ - function file($path, $return = FALSE) - { - return $this->_ci_load(array('path' => $path, 'return' => $return)); - } - - // -------------------------------------------------------------------- - - /** - * Set Variables - * - * Once variables are set they become available within - * the controller class and its "view" files. - * - * @access public - * @param array - * @return void - */ - function vars($vars = array()) - { - $vars = $this->_ci_object_to_array($vars); - - if (is_array($vars) AND count($vars) > 0) - { - foreach ($vars as $key => $val) - { - $this->_ci_cached_vars[$key] = $val; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Load Helper - * - * This function loads the specified helper file. - * - * @access public - * @param mixed - * @return void - */ - function helper($helpers = array()) - { - if ( ! is_array($helpers)) - { - $helpers = array($helpers); - } - - foreach ($helpers as $helper) - { - $helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper'); - - if (isset($this->_ci_helpers[$helper])) - { - continue; - } - - if (file_exists(APPPATH.'helpers/'.$helper.EXT)) - { - include_once(APPPATH.'helpers/'.$helper.EXT); - } - else - { - if (file_exists(BASEPATH.'helpers/'.$helper.EXT)) - { - include(BASEPATH.'helpers/'.$helper.EXT); - } - else - { - show_error('Unable to load the requested file: helpers/'.$helper.EXT); - } - } - - $this->_ci_helpers[$helper] = TRUE; - - } - - log_message('debug', 'Helpers loaded: '.implode(', ', $helpers)); - } - - // -------------------------------------------------------------------- - - /** - * Load Helpers - * - * This is simply an alias to the above function in case the - * user has written the plural form of this function. - * - * @access public - * @param array - * @return void - */ - function helpers($helpers = array()) - { - $this->helper($helpers); - } - - // -------------------------------------------------------------------- - - /** - * Load Plugin - * - * This function loads the specified plugin. - * - * @access public - * @param array - * @return void - */ - function plugin($plugins = array()) - { - if ( ! is_array($plugins)) - { - $plugins = array($plugins); - } - - foreach ($plugins as $plugin) - { - $plugin = strtolower(str_replace(EXT, '', str_replace('_plugin.', '', $plugin)).'_pi'); - - if (isset($this->_ci_plugins[$plugin])) - { - continue; - } - - if (file_exists(APPPATH.'plugins/'.$plugin.EXT)) - { - include(APPPATH.'plugins/'.$plugin.EXT); - } - else - { - if (file_exists(BASEPATH.'plugins/'.$plugin.EXT)) - { - include(BASEPATH.'plugins/'.$plugin.EXT); - } - else - { - show_error('Unable to load the requested file: plugins/'.$plugin.EXT); - } - } - - $this->_ci_plugins[$plugin] = TRUE; - } - - log_message('debug', 'Plugins loaded: '.implode(', ', $plugins)); - } - - // -------------------------------------------------------------------- - - /** - * Load Plugins - * - * This is simply an alias to the above function in case the - * user has written the plural form of this function. - * - * @access public - * @param array - * @return void - */ - function plugins($plugins = array()) - { - $this->plugin($plugins); - } - - // -------------------------------------------------------------------- - - /** - * Load Script - * - * This function loads the specified include file from the - * application/scripts/ folder. - * - * NOTE: This feature has been deprecated but it will remain available - * for legacy users. - * - * @access public - * @param array - * @return void - */ - function script($scripts = array()) - { - if ( ! is_array($scripts)) - { - $scripts = array($scripts); - } - - foreach ($scripts as $script) - { - $script = strtolower(str_replace(EXT, '', $script)); - - if (isset($this->_ci_scripts[$script])) - { - continue; - } - - if ( ! file_exists(APPPATH.'scripts/'.$script.EXT)) - { - show_error('Unable to load the requested script: scripts/'.$script.EXT); - } - - include(APPPATH.'scripts/'.$script.EXT); - } - - log_message('debug', 'Scripts loaded: '.implode(', ', $scripts)); - } - - // -------------------------------------------------------------------- - - /** - * Loads a language file - * - * @access public - * @param array - * @param string - * @return void - */ - function language($file = array(), $lang = '') - { - $CI =& get_instance(); - - if ( ! is_array($file)) - { - $file = array($file); - } - - foreach ($file as $langfile) - { - $CI->lang->load($langfile, $lang); - } - } - - /** - * Loads language files for scaffolding - * - * @access public - * @param string - * @return arra - */ - function scaffold_language($file = '', $lang = '', $return = FALSE) - { - $CI =& get_instance(); - return $CI->lang->load($file, $lang, $return); - } - - // -------------------------------------------------------------------- - - /** - * Loads a config file - * - * @access public - * @param string - * @return void - */ - function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) - { - $CI =& get_instance(); - $CI->config->load($file, $use_sections, $fail_gracefully); - } - - // -------------------------------------------------------------------- - - /** - * Scaffolding Loader - * - * This initializing function works a bit different than the - * others. It doesn't load the class. Instead, it simply - * sets a flag indicating that scaffolding is allowed to be - * used. The actual scaffolding function below is - * called by the front controller based on whether the - * second segment of the URL matches the "secret" scaffolding - * word stored in the application/config/routes.php - * - * @access public - * @param string - * @return void - */ - function scaffolding($table = '') - { - if ($table === FALSE) - { - show_error('You must include the name of the table you would like to access when you initialize scaffolding'); - } - - $CI =& get_instance(); - $CI->_ci_scaffolding = TRUE; - $CI->_ci_scaff_table = $table; - } - - // -------------------------------------------------------------------- - - /** - * Loader - * - * This function is used to load views and files. - * - * @access private - * @param array - * @return void - */ - function _ci_load($data) - { - // Set the default data variables - foreach (array('view', 'vars', 'path', 'return') as $val) - { - $$val = ( ! isset($data[$val])) ? FALSE : $data[$val]; - } - - // Set the path to the requested file - if ($path == '') - { - $ext = pathinfo($view, PATHINFO_EXTENSION); - $file = ($ext == '') ? $view.EXT : $view; - $path = $this->_ci_view_path.$file; - } - else - { - $x = explode('/', $path); - $file = end($x); - } - - if ( ! file_exists($path)) - { - show_error('Unable to load the requested file: '.$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 =& get_instance(); - foreach (get_object_vars($CI) as $key => $var) - { - if ( ! isset($this->$key)) - { - $this->$key =& $CI->$key; - } - } - } - - /* - * Extract and cache variables - * - * You can either set variables using the dedicated $this->load_vars() - * 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($vars)) - { - $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $vars); - } - extract($this->_ci_cached_vars); - - /* - * Buffer the output - * - * We buffer the output for two reasons: - * 1. Speed. You get a significant speed boost. - * 2. So that the final rendered template can be - * post-processed by the output class. Why do we - * need post processing? For one thing, in order to - * show the elapsed page load time. Unless we - * can intercept the content right before it's sent to - * 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(' $this->_ci_ob_level + 1) - { - ob_end_flush(); - } - else - { - // PHP 4 requires that we use a global - global $OUT; - $OUT->set_output(ob_get_contents()); - @ob_end_clean(); - } - } - - // -------------------------------------------------------------------- - - /** - * Load class - * - * This function loads the requested class. - * - * @access private - * @param string the item that is being loaded - * @param mixed any additional parameters - * @return void - */ - function _ci_load_class($class, $params = NULL) - { - // Get the class name - $class = str_replace(EXT, '', $class); - - // We'll test for both lowercase and capitalized versions of the file name - foreach (array(ucfirst($class), strtolower($class)) as $class) - { - $subclass = APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT; - - // 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); - show_error("Unable to load the requested class: ".$class); - } - - // Safety: Was the class already loaded by a previous call? - if (in_array($subclass, $this->_ci_classes)) - { - $is_duplicate = TRUE; - log_message('debug', $class." class already loaded. Second attempt ignored."); - return; - } - - include($baseclass); - include($subclass); - $this->_ci_classes[] = $subclass; - - return $this->_ci_init_class($class, config_item('subclass_prefix'), $params); - } - - // Lets search for the requested library file and load it. - $is_duplicate = FALSE; - for ($i = 1; $i < 3; $i++) - { - $path = ($i % 2) ? APPPATH : BASEPATH; - $filepath = $path.'libraries/'.$class.EXT; - - // Does the file exist? No? Bummer... - if ( ! file_exists($filepath)) - { - continue; - } - - // Safety: Was the class already loaded by a previous call? - if (in_array($filepath, $this->_ci_classes)) - { - $is_duplicate = TRUE; - log_message('debug', $class." class already loaded. Second attempt ignored."); - return; - } - - include($filepath); - $this->_ci_classes[] = $filepath; - return $this->_ci_init_class($class, '', $params); - } - } // END FOREACH - - // If we got this far we were unable to find the requested class. - // We do not issue errors if the load call failed due to a duplicate request - if ($is_duplicate == FALSE) - { - log_message('error', "Unable to load the requested class: ".$class); - show_error("Unable to load the requested class: ".$class); - } - } - - // -------------------------------------------------------------------- - - /** - * Instantiates a class - * - * @access private - * @param string - * @param string - * @return null - */ - function _ci_init_class($class, $prefix = '', $config = FALSE) - { - // Is there an associated config file for this class? - if ($config === NULL) - { - $config = NULL; - if (file_exists(APPPATH.'config/'.$class.EXT)) - { - include(APPPATH.'config/'.$class.EXT); - } - } - - if ($prefix == '') - { - $name = (class_exists('CI_'.$class)) ? 'CI_'.$class : $class; - } - else - { - $name = $prefix.$class; - } - - // Set the variable name we will assign the class to - $class = strtolower($class); - $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; - - // Instantiate the class - $CI =& get_instance(); - if ($config !== NULL) - { - $CI->$classvar = new $name($config); - } - else - { - $CI->$classvar = new $name; - } - } - - // -------------------------------------------------------------------- - - /** - * Autoloader - * - * The config/autoload.php file contains an array that permits sub-systems, - * libraries, plugins, and helpers to be loaded automatically. - * - * @access private - * @param array - * @return void - */ - function _ci_autoloader() - { - include(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 plugins, helpers, scripts and languages - foreach (array('helper', 'plugin', 'script', 'language') as $type) - { - if (isset($autoload[$type]) AND count($autoload[$type]) > 0) - { - $this->$type($autoload[$type]); - } - } - - // Autoload models - if (isset($autoload['model'])) - { - $this->model($autoload['model']); - } - - // A little tweak to remain backward compatible - // The $autoload['core'] item was deprecated - if ( ! isset($autoload['libraries'])) - { - $autoload['libraries'] = $autoload['core']; - } - - // Load libraries - if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0) - { - // Load the database driver. - if (in_array('database', $autoload['libraries'])) - { - $this->database(); - $autoload['libraries'] = array_diff($autoload['libraries'], array('database')); - } - - // Load the model class. - if (in_array('model', $autoload['libraries'])) - { - die('made it in!'); - $this->model(); - $autoload['libraries'] = array_diff($autoload['libraries'], array('model')); - } - - // Load scaffolding - if (in_array('scaffolding', $autoload['libraries'])) - { - $this->scaffolding(); - $autoload['libraries'] = array_diff($autoload['libraries'], array('scaffolding')); - } - - // Load all other libraries - foreach ($autoload['libraries'] as $item) - { - $this->library($item); - } - } - } - - // -------------------------------------------------------------------- - - /** - * Assign to Models - * - * Makes sure that anything loaded by the loader class (libraries, plugins, etc.) - * will be available to models, if any exist. - * - * @access private - * @param object - * @return array - */ - function _ci_assign_to_models() - { - if (count($this->_ci_models) == 0) - { - return; - } - - if ($this->_ci_is_instance()) - { - $CI =& get_instance(); - foreach ($this->_ci_models as $model) - { - $CI->$model->_assign_libraries(); - } - } - else - { - foreach ($this->_ci_models as $model) - { - $this->$model->_assign_libraries(); - } - } - } - - // -------------------------------------------------------------------- - - /** - * Object to Array - * - * Takes an object as input and converts the class variables to array key/vals - * - * @access private - * @param object - * @return array - */ - function _ci_object_to_array($object) - { - return (is_object($object)) ? get_object_vars($object) : $object; - } - - // -------------------------------------------------------------------- - - /** - * Determines whether we should use the CI instance or $this - * - * @access private - * @return bool - */ - function _ci_is_instance() - { - if ($this->_ci_is_php5 == TRUE) - { - return TRUE; - } - - global $CI; - return (is_object($CI)) ? TRUE : FALSE; - } - -} -?> \ No newline at end of file + 'unit', 'user_agent' => 'agent'); /** * Constructor * * Sets the path to the view files and gets the initial output buffering level * * @access public */ function CI_Loader() { $this->_ci_is_php5 = (floor(phpversion()) >= 5) ? TRUE : FALSE; $this->_ci_view_path = APPPATH.'views/'; $this->_ci_ob_level = ob_get_level(); log_message('debug', "Loader Class Initialized"); } // -------------------------------------------------------------------- /** * Class Loader * * This function lets users load and instantiate classes. * It is designed to be called from a user's app controllers. * * @access public * @param string the name of the class * @param mixed the optional parameters * @return void */ function library($library = '', $params = NULL) { if ($library == '') { return FALSE; } if (is_array($library)) { foreach ($library as $class) { $this->_ci_load_class($class, $params); } } else { $this->_ci_load_class($library, $params); } $this->_ci_assign_to_models(); } // -------------------------------------------------------------------- /** * Model Loader * * This function lets users load and instantiate models. * * @access public * @param string the name of the class * @param mixed any initialization parameters * @return void */ function model($model, $name = '', $db_conn = FALSE) { if (is_array($model)) { foreach($model as $babe) { $this->model($babe); } return; } if ($model == '') { return; } // Is the model in a sub-folder? If so, parse out the filename and path. if (strpos($model, '/') === FALSE) { $path = ''; } else { $x = explode('/', $model); $model = end($x); unset($x[count($x)-1]); $path = implode('/', $x).'/'; } 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); if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT)) { show_error('Unable to locate the model you have specified: '.$model); } if ($db_conn !== FALSE AND ! class_exists('CI_DB')) { if ($db_conn === TRUE) $db_conn = ''; $CI->load->database($db_conn, FALSE, TRUE); } if ( ! class_exists('Model')) { require_once(BASEPATH.'libraries/Model'.EXT); } require_once(APPPATH.'models/'.$path.$model.EXT); $model = ucfirst($model); $CI->$name = new $model(); $CI->$name->_assign_libraries(); $this->_ci_models[] = $name; } // -------------------------------------------------------------------- /** * Database Loader * * @access public * @param string the DB credentials * @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 = FALSE) { // Do we even need to load the database class? if (class_exists('CI_DB') AND $return == FALSE AND $active_record == FALSE) { return FALSE; } require_once(BASEPATH.'database/DB'.EXT); if ($return === TRUE) { return DB($params, $active_record); } // Grab the super object $CI =& get_instance(); // Initialize the db variable. Needed to prevent // reference errors with some configurations $CI->db = ''; // Load the DB class $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 */ function dbutil() { if ( ! class_exists('CI_DB')) { $this->database(); } $CI =& get_instance(); 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'; $CI->dbutil = new $class(); $CI->load->_ci_assign_to_models(); } // -------------------------------------------------------------------- /** * Load View * * This function is used to load a "view" file. It has three parameters: * * 1. The name of the "view" file to be included. * 2. An associative array of data to be extracted for use in the view. * 3. TRUE/FALSE - whether to return the data or load it. In * some cases it's advantageous to be able to return data so that * a developer can process it in some way. * * @access public * @param string * @param array * @param bool * @return void */ function view($view, $vars = array(), $return = FALSE) { return $this->_ci_load(array('view' => $view, 'vars' => $this->_ci_object_to_array($vars), 'return' => $return)); } // -------------------------------------------------------------------- /** * Load File * * This is a generic file loader * * @access public * @param string * @param bool * @return string */ function file($path, $return = FALSE) { return $this->_ci_load(array('path' => $path, 'return' => $return)); } // -------------------------------------------------------------------- /** * Set Variables * * Once variables are set they become available within * the controller class and its "view" files. * * @access public * @param array * @return void */ function vars($vars = array()) { $vars = $this->_ci_object_to_array($vars); if (is_array($vars) AND count($vars) > 0) { foreach ($vars as $key => $val) { $this->_ci_cached_vars[$key] = $val; } } } // -------------------------------------------------------------------- /** * Load Helper * * This function loads the specified helper file. * * @access public * @param mixed * @return void */ function helper($helpers = array()) { if ( ! is_array($helpers)) { $helpers = array($helpers); } foreach ($helpers as $helper) { $helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper'); if (isset($this->_ci_helpers[$helper])) { continue; } if (file_exists(APPPATH.'helpers/'.$helper.EXT)) { include_once(APPPATH.'helpers/'.$helper.EXT); } else { if (file_exists(BASEPATH.'helpers/'.$helper.EXT)) { include(BASEPATH.'helpers/'.$helper.EXT); } else { show_error('Unable to load the requested file: helpers/'.$helper.EXT); } } $this->_ci_helpers[$helper] = TRUE; } log_message('debug', 'Helpers loaded: '.implode(', ', $helpers)); } // -------------------------------------------------------------------- /** * Load Helpers * * This is simply an alias to the above function in case the * user has written the plural form of this function. * * @access public * @param array * @return void */ function helpers($helpers = array()) { $this->helper($helpers); } // -------------------------------------------------------------------- /** * Load Plugin * * This function loads the specified plugin. * * @access public * @param array * @return void */ function plugin($plugins = array()) { if ( ! is_array($plugins)) { $plugins = array($plugins); } foreach ($plugins as $plugin) { $plugin = strtolower(str_replace(EXT, '', str_replace('_plugin.', '', $plugin)).'_pi'); if (isset($this->_ci_plugins[$plugin])) { continue; } if (file_exists(APPPATH.'plugins/'.$plugin.EXT)) { include(APPPATH.'plugins/'.$plugin.EXT); } else { if (file_exists(BASEPATH.'plugins/'.$plugin.EXT)) { include(BASEPATH.'plugins/'.$plugin.EXT); } else { show_error('Unable to load the requested file: plugins/'.$plugin.EXT); } } $this->_ci_plugins[$plugin] = TRUE; } log_message('debug', 'Plugins loaded: '.implode(', ', $plugins)); } // -------------------------------------------------------------------- /** * Load Plugins * * This is simply an alias to the above function in case the * user has written the plural form of this function. * * @access public * @param array * @return void */ function plugins($plugins = array()) { $this->plugin($plugins); } // -------------------------------------------------------------------- /** * Load Script * * This function loads the specified include file from the * application/scripts/ folder. * * NOTE: This feature has been deprecated but it will remain available * for legacy users. * * @access public * @param array * @return void */ function script($scripts = array()) { if ( ! is_array($scripts)) { $scripts = array($scripts); } foreach ($scripts as $script) { $script = strtolower(str_replace(EXT, '', $script)); if (isset($this->_ci_scripts[$script])) { continue; } if ( ! file_exists(APPPATH.'scripts/'.$script.EXT)) { show_error('Unable to load the requested script: scripts/'.$script.EXT); } include(APPPATH.'scripts/'.$script.EXT); } log_message('debug', 'Scripts loaded: '.implode(', ', $scripts)); } // -------------------------------------------------------------------- /** * Loads a language file * * @access public * @param array * @param string * @return void */ function language($file = array(), $lang = '') { $CI =& get_instance(); if ( ! is_array($file)) { $file = array($file); } foreach ($file as $langfile) { $CI->lang->load($langfile, $lang); } } /** * Loads language files for scaffolding * * @access public * @param string * @return arra */ function scaffold_language($file = '', $lang = '', $return = FALSE) { $CI =& get_instance(); return $CI->lang->load($file, $lang, $return); } // -------------------------------------------------------------------- /** * Loads a config file * * @access public * @param string * @return void */ function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) { $CI =& get_instance(); $CI->config->load($file, $use_sections, $fail_gracefully); } // -------------------------------------------------------------------- /** * Scaffolding Loader * * This initializing function works a bit different than the * others. It doesn't load the class. Instead, it simply * sets a flag indicating that scaffolding is allowed to be * used. The actual scaffolding function below is * called by the front controller based on whether the * second segment of the URL matches the "secret" scaffolding * word stored in the application/config/routes.php * * @access public * @param string * @return void */ function scaffolding($table = '') { if ($table === FALSE) { show_error('You must include the name of the table you would like to access when you initialize scaffolding'); } $CI =& get_instance(); $CI->_ci_scaffolding = TRUE; $CI->_ci_scaff_table = $table; } // -------------------------------------------------------------------- /** * Loader * * This function is used to load views and files. * * @access private * @param array * @return void */ function _ci_load($data) { // Set the default data variables foreach (array('view', 'vars', 'path', 'return') as $val) { $$val = ( ! isset($data[$val])) ? FALSE : $data[$val]; } // Set the path to the requested file if ($path == '') { $ext = pathinfo($view, PATHINFO_EXTENSION); $file = ($ext == '') ? $view.EXT : $view; $path = $this->_ci_view_path.$file; } else { $x = explode('/', $path); $file = end($x); } if ( ! file_exists($path)) { show_error('Unable to load the requested file: '.$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 =& get_instance(); foreach (get_object_vars($CI) as $key => $var) { if ( ! isset($this->$key)) { $this->$key =& $CI->$key; } } } /* * Extract and cache variables * * You can either set variables using the dedicated $this->load_vars() * 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($vars)) { $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $vars); } extract($this->_ci_cached_vars); /* * Buffer the output * * We buffer the output for two reasons: * 1. Speed. You get a significant speed boost. * 2. So that the final rendered template can be * post-processed by the output class. Why do we * need post processing? For one thing, in order to * show the elapsed page load time. Unless we * can intercept the content right before it's sent to * 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(' $this->_ci_ob_level + 1) { ob_end_flush(); } else { // PHP 4 requires that we use a global global $OUT; $OUT->set_output(ob_get_contents()); @ob_end_clean(); } } // -------------------------------------------------------------------- /** * Load class * * This function loads the requested class. * * @access private * @param string the item that is being loaded * @param mixed any additional parameters * @return void */ function _ci_load_class($class, $params = NULL) { // Get the class name $class = str_replace(EXT, '', $class); // We'll test for both lowercase and capitalized versions of the file name foreach (array(ucfirst($class), strtolower($class)) as $class) { $subclass = APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT; // 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); show_error("Unable to load the requested class: ".$class); } // Safety: Was the class already loaded by a previous call? if (in_array($subclass, $this->_ci_classes)) { $is_duplicate = TRUE; log_message('debug', $class." class already loaded. Second attempt ignored."); return; } include($baseclass); include($subclass); $this->_ci_classes[] = $subclass; return $this->_ci_init_class($class, config_item('subclass_prefix'), $params); } // Lets search for the requested library file and load it. $is_duplicate = FALSE; for ($i = 1; $i < 3; $i++) { $path = ($i % 2) ? APPPATH : BASEPATH; $filepath = $path.'libraries/'.$class.EXT; // Does the file exist? No? Bummer... if ( ! file_exists($filepath)) { continue; } // Safety: Was the class already loaded by a previous call? if (in_array($filepath, $this->_ci_classes)) { $is_duplicate = TRUE; log_message('debug', $class." class already loaded. Second attempt ignored."); return; } include($filepath); $this->_ci_classes[] = $filepath; return $this->_ci_init_class($class, '', $params); } } // END FOREACH // If we got this far we were unable to find the requested class. // We do not issue errors if the load call failed due to a duplicate request if ($is_duplicate == FALSE) { log_message('error', "Unable to load the requested class: ".$class); show_error("Unable to load the requested class: ".$class); } } // -------------------------------------------------------------------- /** * Instantiates a class * * @access private * @param string * @param string * @return null */ function _ci_init_class($class, $prefix = '', $config = FALSE) { // Is there an associated config file for this class? if ($config === NULL) { $config = NULL; if (file_exists(APPPATH.'config/'.$class.EXT)) { include(APPPATH.'config/'.$class.EXT); } } if ($prefix == '') { $name = (class_exists('CI_'.$class)) ? 'CI_'.$class : $class; } else { $name = $prefix.$class; } // Set the variable name we will assign the class to $class = strtolower($class); $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; // Instantiate the class $CI =& get_instance(); if ($config !== NULL) { $CI->$classvar = new $name($config); } else { $CI->$classvar = new $name; } } // -------------------------------------------------------------------- /** * Autoloader * * The config/autoload.php file contains an array that permits sub-systems, * libraries, plugins, and helpers to be loaded automatically. * * @access private * @param array * @return void */ function _ci_autoloader() { include(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 plugins, helpers, scripts and languages foreach (array('helper', 'plugin', 'script', 'language') as $type) { if (isset($autoload[$type]) AND count($autoload[$type]) > 0) { $this->$type($autoload[$type]); } } // Autoload models if (isset($autoload['model'])) { $this->model($autoload['model']); } // A little tweak to remain backward compatible // The $autoload['core'] item was deprecated if ( ! isset($autoload['libraries'])) { $autoload['libraries'] = $autoload['core']; } // Load libraries if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0) { // Load the database driver. if (in_array('database', $autoload['libraries'])) { $this->database(); $autoload['libraries'] = array_diff($autoload['libraries'], array('database')); } // Load scaffolding if (in_array('scaffolding', $autoload['libraries'])) { $this->scaffolding(); $autoload['libraries'] = array_diff($autoload['libraries'], array('scaffolding')); } // Load all other libraries foreach ($autoload['libraries'] as $item) { $this->library($item); } // Load the model class. if (in_array('model', $autoload['libraries'])) { die('made it in!'); $this->model(); $autoload['libraries'] = array_diff($autoload['libraries'], array('model')); } } } // -------------------------------------------------------------------- /** * Assign to Models * * Makes sure that anything loaded by the loader class (libraries, plugins, etc.) * will be available to models, if any exist. * * @access private * @param object * @return array */ function _ci_assign_to_models() { if (count($this->_ci_models) == 0) { return; } if ($this->_ci_is_instance()) { $CI =& get_instance(); foreach ($this->_ci_models as $model) { $CI->$model->_assign_libraries(); } } else { foreach ($this->_ci_models as $model) { $this->$model->_assign_libraries(); } } } // -------------------------------------------------------------------- /** * Object to Array * * Takes an object as input and converts the class variables to array key/vals * * @access private * @param object * @return array */ function _ci_object_to_array($object) { return (is_object($object)) ? get_object_vars($object) : $object; } // -------------------------------------------------------------------- /** * Determines whether we should use the CI instance or $this * * @access private * @return bool */ function _ci_is_instance() { if ($this->_ci_is_php5 == TRUE) { return TRUE; } global $CI; return (is_object($CI)) ? TRUE : FALSE; } } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b60b3722b26a484d93d6556cb83b94ddab8b30c9 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 29 Nov 2007 19:40:26 +0000 Subject: Moved the safe mode and auth checks for the Email library into the constructor --- system/libraries/Email.php | 1816 +------------------------------------------- 1 file changed, 1 insertion(+), 1815 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 4cd930892..9c5121179 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1,1815 +1 @@ - 0) - { - $this->initialize($config); - } - - log_message('debug', "Email Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize preferences - * - * @access public - * @param array - * @return void - */ - function initialize($config = array()) - { - $this->clear(); - foreach ($config as $key => $val) - { - if (isset($this->$key)) - { - $method = 'set_'.$key; - - if (method_exists($this, $method)) - { - $this->$method($val); - } - else - { - $this->$key = $val; - } - } - } - $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; - $this->_safe_mode = (@ini_get("safe_mode") == 0) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Initialize the Email Data - * - * @access public - * @return void - */ - function clear($clear_attachments = FALSE) - { - $this->_subject = ""; - $this->_body = ""; - $this->_finalbody = ""; - $this->_header_str = ""; - $this->_replyto_flag = FALSE; - $this->_recipients = array(); - $this->_headers = array(); - $this->_debug_msg = array(); - - $this->_set_header('User-Agent', $this->useragent); - $this->_set_header('Date', $this->_set_date()); - - if ($clear_attachments !== FALSE) - { - $this->_attach_name = array(); - $this->_attach_type = array(); - $this->_attach_disp = array(); - } - } - - // -------------------------------------------------------------------- - - /** - * Set FROM - * - * @access public - * @param string - * @param string - * @return void - */ - function from($from, $name = '') - { - if (preg_match( '/\<(.*)\>/', $from, $match)) - $from = $match['1']; - - if ($this->validate) - $this->validate_email($this->_str_to_array($from)); - - if ($name != '' && substr($name, 0, 1) != '"') - { - $name = '"'.$name.'"'; - } - - $this->_set_header('From', $name.' <'.$from.'>'); - $this->_set_header('Return-Path', '<'.$from.'>'); - } - - // -------------------------------------------------------------------- - - /** - * Set Reply-to - * - * @access public - * @param string - * @param string - * @return void - */ - function reply_to($replyto, $name = '') - { - if (preg_match( '/\<(.*)\>/', $replyto, $match)) - $replyto = $match['1']; - - if ($this->validate) - $this->validate_email($this->_str_to_array($replyto)); - - if ($name == '') - { - $name = $replyto; - } - - if (substr($name, 0, 1) != '"') - { - $name = '"'.$name.'"'; - } - - $this->_set_header('Reply-To', $name.' <'.$replyto.'>'); - $this->_replyto_flag = TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set Recipients - * - * @access public - * @param string - * @return void - */ - function to($to) - { - $to = $this->_str_to_array($to); - $to = $this->clean_email($to); - - if ($this->validate) - $this->validate_email($to); - - if ($this->_get_protocol() != 'mail') - $this->_set_header('To', implode(", ", $to)); - - switch ($this->_get_protocol()) - { - case 'smtp' : $this->_recipients = $to; - break; - case 'sendmail' : $this->_recipients = implode(", ", $to); - break; - case 'mail' : $this->_recipients = implode(", ", $to); - break; - } - } - - // -------------------------------------------------------------------- - - /** - * Set CC - * - * @access public - * @param string - * @return void - */ - function cc($cc) - { - $cc = $this->_str_to_array($cc); - $cc = $this->clean_email($cc); - - if ($this->validate) - $this->validate_email($cc); - - $this->_set_header('Cc', implode(", ", $cc)); - - if ($this->_get_protocol() == "smtp") - $this->_cc_array = $cc; - } - - // -------------------------------------------------------------------- - - /** - * Set BCC - * - * @access public - * @param string - * @param string - * @return void - */ - function bcc($bcc, $limit = '') - { - if ($limit != '' && is_numeric($limit)) - { - $this->bcc_batch_mode = true; - $this->bcc_batch_size = $limit; - } - - $bcc = $this->_str_to_array($bcc); - $bcc = $this->clean_email($bcc); - - if ($this->validate) - $this->validate_email($bcc); - - if (($this->_get_protocol() == "smtp") OR ($this->bcc_batch_mode && count($bcc) > $this->bcc_batch_size)) - $this->_bcc_array = $bcc; - else - $this->_set_header('Bcc', implode(", ", $bcc)); - } - - // -------------------------------------------------------------------- - - /** - * Set Email Subject - * - * @access public - * @param string - * @return void - */ - function subject($subject) - { - $subject = preg_replace("/(\r\n)|(\r)|(\n)/", "", $subject); - $subject = preg_replace("/(\t)/", " ", $subject); - - $this->_set_header('Subject', trim($subject)); - } - - // -------------------------------------------------------------------- - - /** - * Set Body - * - * @access public - * @param string - * @return void - */ - function message($body) - { - $this->_body = stripslashes(rtrim(str_replace("\r", "", $body))); - } - - // -------------------------------------------------------------------- - - /** - * Assign file attachments - * - * @access public - * @param string - * @return string - */ - function attach($filename, $disposition = 'attachment') - { - $this->_attach_name[] = $filename; - $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename)))); - $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters - } - - // -------------------------------------------------------------------- - - /** - * Add a Header Item - * - * @access public - * @param string - * @param string - * @return void - */ - function _set_header($header, $value) - { - $this->_headers[$header] = $value; - } - - // -------------------------------------------------------------------- - - /** - * Convert a String to an Array - * - * @access public - * @param string - * @return array - */ - function _str_to_array($email) - { - if ( ! is_array($email)) - { - if (ereg(',$', $email)) - $email = substr($email, 0, -1); - - if (ereg('^,', $email)) - $email = substr($email, 1); - - if (ereg(',', $email)) - { - $x = explode(',', $email); - $email = array(); - - for ($i = 0; $i < count($x); $i ++) - $email[] = trim($x[$i]); - } - else - { - $email = trim($email); - settype($email, "array"); - } - } - return $email; - } - - // -------------------------------------------------------------------- - - /** - * Set Multipart Value - * - * @access public - * @param string - * @return void - */ - function set_alt_message($str = '') - { - $this->alt_message = ($str == '') ? '' : $str; - } - - // -------------------------------------------------------------------- - - /** - * Set Mailtype - * - * @access public - * @param string - * @return void - */ - function set_mailtype($type = 'text') - { - $this->mailtype = ($type == 'html') ? 'html' : 'text'; - } - - // -------------------------------------------------------------------- - - /** - * Set Wordwrap - * - * @access public - * @param string - * @return void - */ - function set_wordwrap($wordwrap = TRUE) - { - $this->wordwrap = ($wordwrap === FALSE) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set Protocol - * - * @access public - * @param string - * @return void - */ - function set_protocol($protocol = 'mail') - { - $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol); - } - - // -------------------------------------------------------------------- - - /** - * Set Priority - * - * @access public - * @param integer - * @return void - */ - function set_priority($n = 3) - { - if ( ! is_numeric($n)) - { - $this->priority = 3; - return; - } - - if ($n < 1 OR $n > 5) - { - $this->priority = 3; - return; - } - - $this->priority = $n; - } - - // -------------------------------------------------------------------- - - /** - * Set Newline Character - * - * @access public - * @param string - * @return void - */ - function set_newline($newline = "\n") - { - if ($newline != "\n" AND $newline != "\r\n" AND $newline != "\r") - { - $this->newline = "\n"; - return; - } - - $this->newline = $newline; - } - - // -------------------------------------------------------------------- - - /** - * Set Message Boundary - * - * @access private - * @return void - */ - function _set_boundaries() - { - $this->_alt_boundary = "B_ALT_".uniqid(''); // multipart/alternative - $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary - } - - // -------------------------------------------------------------------- - - /** - * Get the Message ID - * - * @access private - * @return string - */ - function _get_message_id() - { - $from = $this->_headers['Return-Path']; - $from = str_replace(">", "", $from); - $from = str_replace("<", "", $from); - - return "<".uniqid('').strstr($from, '@').">"; - } - - // -------------------------------------------------------------------- - - /** - * Get Mail Protocol - * - * @access private - * @param bool - * @return string - */ - function _get_protocol($return = true) - { - $this->protocol = strtolower($this->protocol); - $this->protocol = ( ! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol; - - if ($return == true) - return $this->protocol; - } - - // -------------------------------------------------------------------- - - /** - * Get Mail Encoding - * - * @access private - * @param bool - * @return string - */ - function _get_encoding($return = true) - { - $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '7bit' : $this->_encoding; - - if ( ! in_array($this->charset, $this->_base_charsets, TRUE)) - $this->_encoding = "8bit"; - - if ($return == true) - return $this->_encoding; - } - - // -------------------------------------------------------------------- - - /** - * Get content type (text/html/attachment) - * - * @access private - * @return string - */ - function _get_content_type() - { - if ($this->mailtype == 'html' && count($this->_attach_name) == 0) - return 'html'; - - elseif ($this->mailtype == 'html' && count($this->_attach_name) > 0) - return 'html-attach'; - - elseif ($this->mailtype == 'text' && count($this->_attach_name) > 0) - return 'plain-attach'; - - else return 'plain'; - } - - // -------------------------------------------------------------------- - - /** - * Set RFC 822 Date - * - * @access public - * @return string - */ - function _set_date() - { - $timezone = date("Z"); - $operator = (substr($timezone, 0, 1) == '-') ? '-' : '+'; - $timezone = abs($timezone); - $timezone = floor($timezone/3600) * 100 + ($timezone % 3600 ) / 60; - - return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone); - } - - // -------------------------------------------------------------------- - - /** - * Mime message - * - * @access private - * @return string - */ - function _get_mime_message() - { - return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format."; - } - - // -------------------------------------------------------------------- - - /** - * Validate Email Address - * - * @access public - * @param string - * @return bool - */ - function validate_email($email) - { - if ( ! is_array($email)) - { - $this->_set_error_message('email_must_be_array'); - return FALSE; - } - - foreach ($email as $val) - { - if ( ! $this->valid_email($val)) - { - $this->_set_error_message('email_invalid_address', $val); - return FALSE; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Email Validation - * - * @access public - * @param string - * @return bool - */ - function valid_email($address) - { - if ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) - return FALSE; - else - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Clean Extended Email Address: Joe Smith - * - * @access public - * @param string - * @return string - */ - function clean_email($email) - { - if ( ! is_array($email)) - { - if (preg_match('/\<(.*)\>/', $email, $match)) - return $match['1']; - else - return $email; - } - - $clean_email = array(); - - for ($i=0; $i < count($email); $i++) - { - if (preg_match( '/\<(.*)\>/', $email[$i], $match)) - $clean_email[] = $match['1']; - else - $clean_email[] = $email[$i]; - } - - return $clean_email; - } - - // -------------------------------------------------------------------- - - /** - * Build alternative plain text message - * - * This function provides the raw message for use - * in plain-text headers of HTML-formatted emails. - * If the user hasn't specified his own alternative message - * it creates one by stripping the HTML - * - * @access private - * @return string - */ - function _get_alt_message() - { - if ($this->alt_message != "") - { - return $this->word_wrap($this->alt_message, '76'); - } - - if (eregi( '\', $this->_body, $match)) - { - $body = $match['1']; - $body = substr($body, strpos($body, ">") + 1); - } - else - { - $body = $this->_body; - } - - $body = trim(strip_tags($body)); - $body = preg_replace( '#'.$output); flock($fp, LOCK_UN); fclose($fp); - @chmod($cache_path, 0777); + @chmod($cache_path, DIR_WRITE_MODE); log_message('debug', "Cache file written: ".$cache_path); } -- cgit v1.2.3-24-g4f1b From 27b5005d23ab2d55e459b59890d0108e100cb070 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 14 Apr 2008 14:03:04 +0000 Subject: added check to make sure the URI path is not constructed entirely of slashes in URI::_fetch_uri_string() --- system/libraries/URI.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/URI.php b/system/libraries/URI.php index aecf05138..d10a5daeb 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -65,7 +65,7 @@ class CI_URI { // build the URI string from the zero index of the $_GET array. // This avoids having to deal with $_SERVER variables, which // can be unreliable in some environments - if (is_array($_GET) AND count($_GET) == 1) + if (is_array($_GET) AND count($_GET) == 1 AND trim(key($_GET), '/') != '') { $this->uri_string = key($_GET); return; @@ -74,7 +74,7 @@ class CI_URI { // Is there a PATH_INFO variable? // Note: some servers seem to have trouble with getenv() so we'll test it two ways $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); - if ($path != '' AND $path != '/' AND $path != "/".SELF) + if (trim($path, '/') != '' AND $path != "/".SELF) { $this->uri_string = $path; return; @@ -82,7 +82,7 @@ class CI_URI { // No PATH_INFO?... What about QUERY_STRING? $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); - if ($path != '' AND $path != '/') + if (trim($path, '/') != '') { $this->uri_string = $path; return; @@ -90,7 +90,7 @@ class CI_URI { // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists? $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); - if ($path != '' AND $path != '/' AND $path != "/".SELF) + if (trim($path, '/') != '' AND $path != "/".SELF) { $this->uri_string = $path; return; -- cgit v1.2.3-24-g4f1b From 7c53be42a74b103774729281aef09ad505f3b611 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 22 Apr 2008 12:02:43 +0000 Subject: Added the ability to set CRLF settings via config in the Email class. Added SVN commit number to changelog Fixed more guide typos and examples --- system/libraries/Email.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 189678742..19121c56b 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -490,6 +490,26 @@ class CI_Email { // -------------------------------------------------------------------- + /** + * Set CRLF + * + * @access public + * @param string + * @return void + */ + function set_crlf($crlf = "\n") + { + if ($crlf != "\n" AND $crlf != "\r\n" AND $crlf != "\r") + { + $this->crlf = "\n"; + return; + } + + $this->crlf = $crlf; + } + + // -------------------------------------------------------------------- + /** * Set Message Boundary * -- cgit v1.2.3-24-g4f1b From f9d5348cf2776374bf09bdda8c941198167d9ae9 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 26 Apr 2008 19:19:25 +0000 Subject: Unit Testing results are now colour coded, and a change was made to the default template of results. --- system/libraries/Router.php | 12 +++++----- system/libraries/Unit_test.php | 52 ++++++++++++++++++++++++++---------------- 2 files changed, 38 insertions(+), 26 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index d9dd6dd3f..804e80bd2 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -204,7 +204,7 @@ class CI_Router { // 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 @@ -220,16 +220,16 @@ class CI_Router { } } - + return $segments; } - + // Can't find the requested controller... - show_404($segments[0]); + show_404($segments[0]); } - + // -------------------------------------------------------------------- - + /** * Parse Routes * diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 33a8f3109..ff4d0c7ed 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -100,32 +100,48 @@ class CI_Unit_test { * @return string */ function report($result = array()) - { + { if (count($result) == 0) { $result = $this->result(); } - + + $CI =& get_instance(); + $CI->load->language('unit_test'); + $this->_parse_template(); - + $r = ''; foreach ($result as $res) { $table = ''; - + foreach ($res as $key => $val) { - $temp = $this->_template_rows; + + if ($key == $CI->lang->line('ut_result')) + { + if ($val == $CI->lang->line('ut_passed')) + { + $val = ''.$val.''; + } + elseif ($val == $CI->lang->line('ut_failed')) + { + $val = ''.$val.''; + } + } + + $temp = $this->_template_rows; $temp = str_replace('{item}', $key, $temp); $temp = str_replace('{result}', $val, $temp); $table .= $temp; } - + $r .= str_replace('{rows}', $table, $this->_template); } - - return $r; - } + + return $r; + } // -------------------------------------------------------------------- @@ -262,18 +278,14 @@ class CI_Unit_test { */ function _default_template() { - $this->_template = ' -
- - {rows} -
'; + $this->_template = "\n".''; + $this->_template .= '{rows}'; + $this->_template .= "\n".'
'; - $this->_template_rows = ' - - {item} - {result} - - '; + $this->_template_rows = "\n\t".''; + $this->_template_rows .= "\n\t\t".'{item}'; + $this->_template_rows .= "\n\t\t".'{result}'; + $this->_template_rows .= "\n\t".''; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From b94b89c69195a0708add8dedb1721f12bcafbf8c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 28 Apr 2008 23:18:00 +0000 Subject: Added a valid_emails rule to the Validation class. --- system/libraries/Validation.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'system/libraries') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index d0714d040..18fdba2d3 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -487,6 +487,33 @@ class CI_Validation { // -------------------------------------------------------------------- + /** + * 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) + { + return FALSE; + } + } + + return TRUE; + } + + // -------------------------------------------------------------------- + /** * Validate IP Address * -- cgit v1.2.3-24-g4f1b From c39d202d35f76f8a85f357d6e86a2223258d6c07 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 1 May 2008 03:26:24 +0000 Subject: The Zip class now exits within download(). --- system/libraries/Zip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index a3d42f34c..fab8e7f6b 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -351,7 +351,7 @@ class CI_Zip { header("Content-Length: ".strlen($this->get_zip())); } - echo $this->get_zip(); + exit($this->get_zip()); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 7327499064ae165468c7440f8571c3e570b58a0b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 5 May 2008 16:39:18 +0000 Subject: Added get_dir_file_info(), get_file_info(), and get_mime_by_extension() to the File Helper. Changed ( ! condition) into (! condition) within the code --- system/libraries/Benchmark.php | 4 +-- system/libraries/Calendar.php | 4 +-- system/libraries/Config.php | 12 ++++----- system/libraries/Controller.php | 2 +- system/libraries/Email.php | 52 ++++++++++++++++++------------------ system/libraries/Encrypt.php | 6 ++--- system/libraries/Exceptions.php | 6 ++--- system/libraries/Ftp.php | 34 ++++++++++++------------ system/libraries/Hooks.php | 14 +++++----- system/libraries/Image_lib.php | 58 ++++++++++++++++++++--------------------- system/libraries/Input.php | 22 ++++++++-------- system/libraries/Language.php | 2 +- system/libraries/Loader.php | 36 ++++++++++++------------- system/libraries/Log.php | 8 +++--- system/libraries/Model.php | 2 +- system/libraries/Output.php | 18 ++++++------- system/libraries/Pagination.php | 2 +- system/libraries/Parser.php | 4 +-- system/libraries/Profiler.php | 6 ++--- system/libraries/Router.php | 8 +++--- system/libraries/Session.php | 8 +++--- system/libraries/Table.php | 18 ++++++------- system/libraries/Trackback.php | 24 ++++++++--------- system/libraries/URI.php | 12 ++++----- system/libraries/Unit_test.php | 8 +++--- system/libraries/Upload.php | 42 ++++++++++++++--------------- system/libraries/User_agent.php | 8 +++--- system/libraries/Validation.php | 48 +++++++++++++++++----------------- system/libraries/Xmlrpc.php | 18 ++++++------- system/libraries/Xmlrpcs.php | 8 +++--- system/libraries/Zip.php | 8 +++--- 31 files changed, 251 insertions(+), 251 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index bca37822b..323d9668d 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -71,12 +71,12 @@ class CI_Benchmark { return '{elapsed_time}'; } - if ( ! isset($this->marker[$point1])) + if (! isset($this->marker[$point1])) { return ''; } - if ( ! isset($this->marker[$point2])) + if (! isset($this->marker[$point2])) { $this->marker[$point2] = microtime(); } diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index a85c18303..e9621fec1 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -49,7 +49,7 @@ class CI_Calendar { { $this->CI =& get_instance(); - if ( ! in_array('calendar_lang'.EXT, $this->CI->lang->is_loaded, TRUE)) + if (! in_array('calendar_lang'.EXT, $this->CI->lang->is_loaded, TRUE)) { $this->CI->lang->load('calendar'); } @@ -125,7 +125,7 @@ class CI_Calendar { // 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]; + $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); diff --git a/system/libraries/Config.php b/system/libraries/Config.php index 9b8b07c5a..73f1986a0 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -66,7 +66,7 @@ class CI_Config { return TRUE; } - if ( ! file_exists(APPPATH.'config/'.$file.EXT)) + if (! file_exists(APPPATH.'config/'.$file.EXT)) { if ($fail_gracefully === TRUE) { @@ -77,7 +77,7 @@ class CI_Config { include(APPPATH.'config/'.$file.EXT); - if ( ! isset($config) OR ! is_array($config)) + if (! isset($config) OR ! is_array($config)) { if ($fail_gracefully === TRUE) { @@ -125,7 +125,7 @@ class CI_Config { { if ($index == '') { - if ( ! isset($this->config[$item])) + if (! isset($this->config[$item])) { return FALSE; } @@ -134,12 +134,12 @@ class CI_Config { } else { - if ( ! isset($this->config[$index])) + if (! isset($this->config[$index])) { return FALSE; } - if ( ! isset($this->config[$index][$item])) + if (! isset($this->config[$index][$item])) { return FALSE; } @@ -165,7 +165,7 @@ class CI_Config { */ function slash_item($item) { - if ( ! isset($this->config[$item])) + if (! isset($this->config[$item])) { return FALSE; } diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index ad9c66805..4957fc35e 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -111,7 +111,7 @@ class Controller extends CI_Base { show_404('Scaffolding unavailable'); } - $method = ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) ? 'view' : $this->uri->segment(3); + $method = (! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) ? 'view' : $this->uri->segment(3); require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); $scaff = new Scaffolding($this->_ci_scaff_table); diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 19121c56b..3b4dddd00 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -371,7 +371,7 @@ class CI_Email { */ function _str_to_array($email) { - if ( ! is_array($email)) + if (! is_array($email)) { if (strpos($email, ',') !== FALSE) { @@ -439,7 +439,7 @@ class CI_Email { */ function set_protocol($protocol = 'mail') { - $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol); + $this->protocol = (! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol); } // -------------------------------------------------------------------- @@ -453,7 +453,7 @@ class CI_Email { */ function set_priority($n = 3) { - if ( ! is_numeric($n)) + if (! is_numeric($n)) { $this->priority = 3; return; @@ -551,7 +551,7 @@ class CI_Email { function _get_protocol($return = TRUE) { $this->protocol = strtolower($this->protocol); - $this->protocol = ( ! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol; + $this->protocol = (! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol; if ($return == TRUE) return $this->protocol; @@ -568,7 +568,7 @@ class CI_Email { */ function _get_encoding($return = TRUE) { - $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '8bit' : $this->_encoding; + $this->_encoding = (! in_array($this->_encoding, $this->_bit_depths)) ? '8bit' : $this->_encoding; foreach ($this->_base_charsets as $charset) { @@ -648,7 +648,7 @@ class CI_Email { */ function validate_email($email) { - if ( ! is_array($email)) + if (! is_array($email)) { $this->_set_error_message('email_must_be_array'); return FALSE; @@ -656,7 +656,7 @@ class CI_Email { foreach ($email as $val) { - if ( ! $this->valid_email($val)) + if (! $this->valid_email($val)) { $this->_set_error_message('email_invalid_address', $val); return FALSE; @@ -675,7 +675,7 @@ class CI_Email { */ function valid_email($address) { - return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE; + return (! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -689,7 +689,7 @@ class CI_Email { */ function clean_email($email) { - if ( ! is_array($email)) + if (! is_array($email)) { if (preg_match('/\<(.*)\>/', $email, $match)) return $match['1']; @@ -1055,7 +1055,7 @@ class CI_Email { $basename = basename($filename); $ctype = $this->_attach_type[$i]; - if ( ! file_exists($filename)) + if (! file_exists($filename)) { $this->_set_error_message('email_attachment_missing', $filename); return FALSE; @@ -1070,7 +1070,7 @@ class CI_Email { $attachment[$z++] = $h; $file = filesize($filename) +1; - if ( ! $fp = fopen($filename, 'r')) + if (! $fp = fopen($filename, 'r')) { $this->_set_error_message('email_attachment_unreadable', $filename); return FALSE; @@ -1194,9 +1194,9 @@ class CI_Email { $this->reply_to($this->_headers['From']); } - if (( ! isset($this->_recipients) AND ! isset($this->_headers['To'])) AND - ( ! isset($this->_bcc_array) AND ! isset($this->_headers['Bcc'])) AND - ( ! isset($this->_headers['Cc']))) + if ((! isset($this->_recipients) AND ! isset($this->_headers['To'])) AND + (! isset($this->_bcc_array) AND ! isset($this->_headers['Bcc'])) AND + (! isset($this->_headers['Cc']))) { $this->_set_error_message('email_no_recipients'); return FALSE; @@ -1212,7 +1212,7 @@ class CI_Email { $this->_build_message(); - if ( ! $this->_spool_email()) + if (! $this->_spool_email()) return FALSE; else return TRUE; @@ -1311,7 +1311,7 @@ class CI_Email { { case 'mail' : - if ( ! $this->_send_with_mail()) + if (! $this->_send_with_mail()) { $this->_set_error_message('email_send_failure_phpmail'); return FALSE; @@ -1319,7 +1319,7 @@ class CI_Email { break; case 'sendmail' : - if ( ! $this->_send_with_sendmail()) + if (! $this->_send_with_sendmail()) { $this->_set_error_message('email_send_failure_sendmail'); return FALSE; @@ -1327,7 +1327,7 @@ class CI_Email { break; case 'smtp' : - if ( ! $this->_send_with_smtp()) + if (! $this->_send_with_smtp()) { $this->_set_error_message('email_send_failure_smtp'); return FALSE; @@ -1352,7 +1352,7 @@ class CI_Email { { if ($this->_safe_mode == TRUE) { - if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str)) + if (! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str)) return FALSE; else return TRUE; @@ -1361,7 +1361,7 @@ class CI_Email { { // most documentation of sendmail using the "-f" flag lacks a space after it, however // we've encountered servers that seem to require it to be in place. - if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From']))) + if (! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From']))) return FALSE; else return TRUE; @@ -1380,7 +1380,7 @@ class CI_Email { { $fp = @popen($this->mailpath . " -oi -f ".$this->clean_email($this->_headers['From'])." -t", 'w'); - if ( ! is_resource($fp)) + if (! is_resource($fp)) { $this->_set_error_message('email_no_socket'); return FALSE; @@ -1472,7 +1472,7 @@ class CI_Email { $errstr, $this->smtp_timeout); - if( ! is_resource($this->_smtp_connect)) + if(! is_resource($this->_smtp_connect)) { $this->_set_error_message('email_smtp_error', $errno." ".$errstr); return FALSE; @@ -1557,7 +1557,7 @@ class CI_Email { */ function _smtp_authenticate() { - if ( ! $this->_smtp_auth) + if (! $this->_smtp_auth) return TRUE; if ($this->smtp_user == "" AND $this->smtp_pass == "") @@ -1609,7 +1609,7 @@ class CI_Email { */ function _send_data($data) { - if ( ! fwrite($this->_smtp_connect, $data . $this->newline)) + if (! fwrite($this->_smtp_connect, $data . $this->newline)) { $this->_set_error_message('email_smtp_data_failure', $data); return FALSE; @@ -1684,7 +1684,7 @@ class CI_Email { $this->_IP = end($x); } - if ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $this->_IP)) + if (! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $this->_IP)) $this->_IP = '0.0.0.0'; unset($cip); @@ -1842,7 +1842,7 @@ class CI_Email { 'eml' => 'message/rfc822' ); - return ( ! isset($mimes[strtolower($ext)])) ? "application/x-unknown-content-type" : $mimes[strtolower($ext)]; + return (! isset($mimes[strtolower($ext)])) ? "application/x-unknown-content-type" : $mimes[strtolower($ext)]; } } diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 48f9d3e51..9a784d254 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -44,7 +44,7 @@ class CI_Encrypt { function CI_Encrypt() { $this->CI =& get_instance(); - $this->_mcrypt_exists = ( ! function_exists('mcrypt_encrypt')) ? FALSE : TRUE; + $this->_mcrypt_exists = (! function_exists('mcrypt_encrypt')) ? FALSE : TRUE; log_message('debug', "Encrypt Class Initialized"); } @@ -459,9 +459,9 @@ class CI_Encrypt { */ function sha1($str) { - if ( ! function_exists('sha1')) + if (! function_exists('sha1')) { - if ( ! function_exists('mhash')) + if (! function_exists('mhash')) { require_once(BASEPATH.'libraries/Sha1'.EXT); $SH = new CI_SHA; diff --git a/system/libraries/Exceptions.php b/system/libraries/Exceptions.php index b22ef9f7a..7c9640554 100644 --- a/system/libraries/Exceptions.php +++ b/system/libraries/Exceptions.php @@ -74,7 +74,7 @@ class CI_Exceptions { */ function log_exception($severity, $message, $filepath, $line) { - $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; + $severity = (! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; log_message('error', 'Severity: '.$severity.' --> '.$message. ' '.$filepath.' '.$line, TRUE); } @@ -115,7 +115,7 @@ class CI_Exceptions { */ function show_error($heading, $message, $template = 'error_general') { - $message = '

'.implode('

', ( ! is_array($message)) ? array($message) : $message).'

'; + $message = '

'.implode('

', (! is_array($message)) ? array($message) : $message).'

'; if (ob_get_level() > $this->ob_level + 1) { @@ -142,7 +142,7 @@ class CI_Exceptions { */ function show_php_error($severity, $message, $filepath, $line) { - $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; + $severity = (! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; $filepath = str_replace("\\", "/", $filepath); diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index ed934b548..1b5ec2fd2 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -98,7 +98,7 @@ class CI_FTP { return FALSE; } - if ( ! $this->_login()) + if (! $this->_login()) { if ($this->debug == TRUE) { @@ -139,7 +139,7 @@ class CI_FTP { */ function _is_conn() { - if ( ! is_resource($this->conn_id)) + if (! is_resource($this->conn_id)) { if ($this->debug == TRUE) { @@ -216,7 +216,7 @@ class CI_FTP { } // Set file permissions if needed - if ( ! is_null($permissions)) + if (! is_null($permissions)) { $this->chmod($path, (int)$permissions); } @@ -237,12 +237,12 @@ class CI_FTP { */ function upload($locpath, $rempath, $mode = 'auto', $permissions = NULL) { - if ( ! $this->_is_conn()) + if (! $this->_is_conn()) { return FALSE; } - if ( ! file_exists($locpath)) + if (! file_exists($locpath)) { $this->_error('ftp_no_source_file'); return FALSE; @@ -270,7 +270,7 @@ class CI_FTP { } // Set file permissions if needed - if ( ! is_null($permissions)) + if (! is_null($permissions)) { $this->chmod($rempath, (int)$permissions); } @@ -291,7 +291,7 @@ class CI_FTP { */ function rename($old_file, $new_file, $move = FALSE) { - if ( ! $this->_is_conn()) + if (! $this->_is_conn()) { return FALSE; } @@ -338,7 +338,7 @@ class CI_FTP { */ function delete_file($filepath) { - if ( ! $this->_is_conn()) + if (! $this->_is_conn()) { return FALSE; } @@ -369,7 +369,7 @@ class CI_FTP { */ function delete_dir($filepath) { - if ( ! $this->_is_conn()) + if (! $this->_is_conn()) { return FALSE; } @@ -385,7 +385,7 @@ class CI_FTP { { // If we can't delete the item it's probaly a folder so // we'll recursively call delete_dir() - if ( ! @ftp_delete($this->conn_id, $filepath.$item)) + if (! @ftp_delete($this->conn_id, $filepath.$item)) { $this->delete_dir($filepath.$item); } @@ -418,13 +418,13 @@ class CI_FTP { */ function chmod($path, $perm) { - if ( ! $this->_is_conn()) + if (! $this->_is_conn()) { return FALSE; } // Permissions can only be set when running PHP 5 - if ( ! function_exists('ftp_chmod')) + if (! function_exists('ftp_chmod')) { if ($this->debug == TRUE) { @@ -457,7 +457,7 @@ class CI_FTP { */ function list_files($path = '.') { - if ( ! $this->_is_conn()) + if (! $this->_is_conn()) { return FALSE; } @@ -481,7 +481,7 @@ class CI_FTP { */ function mirror($locpath, $rempath) { - if ( ! $this->_is_conn()) + if (! $this->_is_conn()) { return FALSE; } @@ -490,10 +490,10 @@ class CI_FTP { if ($fp = @opendir($locpath)) { // Attempt to open the remote file path. - if ( ! $this->changedir($rempath, TRUE)) + if (! $this->changedir($rempath, TRUE)) { // If it doesn't exist we'll attempt to create the direcotory - if ( ! $this->mkdir($rempath) OR ! $this->changedir($rempath)) + if (! $this->mkdir($rempath) OR ! $this->changedir($rempath)) { return FALSE; } @@ -586,7 +586,7 @@ class CI_FTP { */ function close() { - if ( ! $this->_is_conn()) + if (! $this->_is_conn()) { return FALSE; } diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index 49cb230c0..a41320c5e 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -68,7 +68,7 @@ class CI_Hooks { @include(APPPATH.'config/hooks'.EXT); - if ( ! isset($hook) OR ! is_array($hook)) + if (! isset($hook) OR ! is_array($hook)) { return; } @@ -90,7 +90,7 @@ class CI_Hooks { */ function _call_hook($which = '') { - if ( ! $this->enabled OR ! isset($this->hooks[$which])) + if (! $this->enabled OR ! isset($this->hooks[$which])) { return FALSE; } @@ -123,7 +123,7 @@ class CI_Hooks { */ function _run_hook($data) { - if ( ! is_array($data)) + if (! is_array($data)) { return FALSE; } @@ -144,14 +144,14 @@ class CI_Hooks { // Set file path // ----------------------------------- - if ( ! isset($data['filepath']) OR ! isset($data['filename'])) + if (! isset($data['filepath']) OR ! isset($data['filename'])) { return FALSE; } $filepath = APPPATH.$data['filepath'].'/'.$data['filename']; - if ( ! file_exists($filepath)) + if (! file_exists($filepath)) { return FALSE; } @@ -196,7 +196,7 @@ class CI_Hooks { if ($class !== FALSE) { - if ( ! class_exists($class)) + if (! class_exists($class)) { require($filepath); } @@ -206,7 +206,7 @@ class CI_Hooks { } else { - if ( ! function_exists($function)) + if (! function_exists($function)) { require($filepath); } diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 85435f6c9..c236e391e 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -158,7 +158,7 @@ class CI_Image_lib { * properties using ImageMagick and NetPBM * */ - if ( ! function_exists('getimagesize')) + if (! function_exists('getimagesize')) { $this->set_error('imglib_gd_required_for_props'); return FALSE; @@ -188,7 +188,7 @@ class CI_Image_lib { $this->source_folder = str_replace($this->source_image, '', $full_source_path); // Set the Image Properties - if ( ! $this->get_image_properties($this->source_folder.$this->source_image)) + if (! $this->get_image_properties($this->source_folder.$this->source_image)) { return FALSE; } @@ -226,7 +226,7 @@ class CI_Image_lib { } // Is there a file name? - if ( ! preg_match("#[\.jpg|\.jpeg|\.gif|\.png]$#i", $full_dest_path)) + if (! preg_match("#[\.jpg|\.jpeg|\.gif|\.png]$#i", $full_dest_path)) { $this->dest_folder = $full_dest_path.'/'; $this->dest_image = $this->source_image; @@ -478,7 +478,7 @@ class CI_Image_lib { // we'll simply make a copy of the original with the new name if (($this->orig_width == $this->width AND $this->orig_height == $this->height) AND ($this->source_image != $this->new_image)) { - if ( ! @copy($this->full_src_path, $this->full_dst_path)) + if (! @copy($this->full_src_path, $this->full_dst_path)) { $this->set_error('imglib_copy_failed'); return FALSE; @@ -494,7 +494,7 @@ class CI_Image_lib { } // Create the image handle - if ( ! ($src_img = $this->image_create_gd())) + if (! ($src_img = $this->image_create_gd())) { return FALSE; } @@ -528,7 +528,7 @@ class CI_Image_lib { else { // Or save it - if ( ! $this->image_save_gd($dst_img)) + if (! $this->image_save_gd($dst_img)) { return FALSE; } @@ -564,9 +564,9 @@ class CI_Image_lib { return FALSE; } - if ( ! eregi("convert$", $this->library_path)) + if (! eregi("convert$", $this->library_path)) { - if ( ! eregi("/$", $this->library_path)) $this->library_path .= "/"; + if (! eregi("/$", $this->library_path)) $this->library_path .= "/"; $this->library_path .= 'convert'; } @@ -712,14 +712,14 @@ class CI_Image_lib { { // Is Image Rotation Supported? // this function is only supported as of PHP 4.3 - if ( ! function_exists('imagerotate')) + if (! function_exists('imagerotate')) { $this->set_error('imglib_rotate_unsupported'); return FALSE; } // Create the image handle - if ( ! ($src_img = $this->image_create_gd())) + if (! ($src_img = $this->image_create_gd())) { return FALSE; } @@ -742,7 +742,7 @@ class CI_Image_lib { else { // Or save it - if ( ! $this->image_save_gd($dst_img)) + if (! $this->image_save_gd($dst_img)) { return FALSE; } @@ -771,7 +771,7 @@ class CI_Image_lib { */ function image_mirror_gd() { - if ( ! $src_img = $this->image_create_gd()) + if (! $src_img = $this->image_create_gd()) { return FALSE; } @@ -828,7 +828,7 @@ class CI_Image_lib { else { // Or save it - if ( ! $this->image_save_gd($src_img)) + if (! $this->image_save_gd($src_img)) { return FALSE; } @@ -877,7 +877,7 @@ class CI_Image_lib { */ function overlay_watermark() { - if ( ! function_exists('imagecolortransparent')) + if (! function_exists('imagecolortransparent')) { $this->set_error('imglib_gd_required'); return FALSE; @@ -955,7 +955,7 @@ class CI_Image_lib { } else { - if ( ! $this->image_save_gd($src_img)) + if (! $this->image_save_gd($src_img)) { return FALSE; } @@ -977,7 +977,7 @@ class CI_Image_lib { */ function text_watermark() { - if ( ! ($src_img = $this->image_create_gd())) + if (! ($src_img = $this->image_create_gd())) { return FALSE; } @@ -1131,7 +1131,7 @@ class CI_Image_lib { switch ($image_type) { case 1 : - if ( ! function_exists('imagecreatefromgif')) + if (! function_exists('imagecreatefromgif')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); return FALSE; @@ -1140,7 +1140,7 @@ class CI_Image_lib { return imagecreatefromgif($path); break; case 2 : - if ( ! function_exists('imagecreatefromjpeg')) + if (! function_exists('imagecreatefromjpeg')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); return FALSE; @@ -1149,7 +1149,7 @@ class CI_Image_lib { return imagecreatefromjpeg($path); break; case 3 : - if ( ! function_exists('imagecreatefrompng')) + if (! function_exists('imagecreatefrompng')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); return FALSE; @@ -1181,7 +1181,7 @@ class CI_Image_lib { switch ($this->image_type) { case 1 : - if ( ! function_exists('imagegif')) + if (! function_exists('imagegif')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); return FALSE; @@ -1190,7 +1190,7 @@ class CI_Image_lib { @imagegif($resource, $this->full_dst_path); break; case 2 : - if ( ! function_exists('imagejpeg')) + if (! function_exists('imagejpeg')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); return FALSE; @@ -1204,7 +1204,7 @@ class CI_Image_lib { @imagejpeg($resource, $this->full_dst_path, $this->quality); break; case 3 : - if ( ! function_exists('imagepng')) + if (! function_exists('imagepng')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); return FALSE; @@ -1267,10 +1267,10 @@ class CI_Image_lib { */ function image_reproportion() { - if ( ! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0) + if (! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0) return; - if ( ! is_numeric($this->orig_width) OR ! is_numeric($this->orig_height) OR $this->orig_width == 0 OR $this->orig_height == 0) + if (! is_numeric($this->orig_width) OR ! is_numeric($this->orig_height) OR $this->orig_width == 0 OR $this->orig_height == 0) return; $new_width = ceil($this->orig_width*$this->height/$this->orig_height); @@ -1315,7 +1315,7 @@ class CI_Image_lib { if ($path == '') $path = $this->full_src_path; - if ( ! file_exists($path)) + if (! file_exists($path)) { $this->set_error('imglib_invalid_path'); return FALSE; @@ -1369,14 +1369,14 @@ class CI_Image_lib { */ function size_calculator($vals) { - if ( ! is_array($vals)) + if (! is_array($vals)) return; $allowed = array('new_width', 'new_height', 'width', 'height'); foreach ($allowed as $item) { - if ( ! isset($vals[$item]) OR $vals[$item] == '') + if (! isset($vals[$item]) OR $vals[$item] == '') $vals[$item] = 0; } @@ -1447,9 +1447,9 @@ class CI_Image_lib { */ function gd_loaded() { - if ( ! extension_loaded('gd')) + if (! extension_loaded('gd')) { - if ( ! dl('gd.so')) + if (! dl('gd.so')) { return FALSE; } diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 1c5682eb7..8a0478be2 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -76,9 +76,9 @@ class CI_Input { // This is effectively the same as register_globals = off foreach (array($_GET, $_POST, $_COOKIE, $_SERVER, $_FILES, $_ENV, (isset($_SESSION) && is_array($_SESSION)) ? $_SESSION : array()) as $global) { - if ( ! is_array($global)) + if (! is_array($global)) { - if ( ! in_array($global, $protected)) + if (! in_array($global, $protected)) { unset($GLOBALS[$global]); } @@ -87,7 +87,7 @@ class CI_Input { { foreach ($global as $key => $val) { - if ( ! in_array($key, $protected)) + if (! in_array($key, $protected)) { unset($GLOBALS[$key]); } @@ -96,7 +96,7 @@ class CI_Input { { foreach($val as $k => $v) { - if ( ! in_array($k, $protected)) + if (! in_array($k, $protected)) { unset($GLOBALS[$k]); } @@ -198,7 +198,7 @@ class CI_Input { */ function _clean_input_keys($str) { - if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str)) + if (! preg_match("/^[a-z0-9:_\/-]+$/i", $str)) { exit('Disallowed Key Characters.'); } @@ -218,7 +218,7 @@ class CI_Input { */ function get($index = '', $xss_clean = FALSE) { - if ( ! isset($_GET[$index])) + if (! isset($_GET[$index])) { return FALSE; } @@ -253,7 +253,7 @@ class CI_Input { */ function post($index = '', $xss_clean = FALSE) { - if ( ! isset($_POST[$index])) + if (! isset($_POST[$index])) { return FALSE; } @@ -288,7 +288,7 @@ class CI_Input { */ function cookie($index = '', $xss_clean = FALSE) { - if ( ! isset($_COOKIE[$index])) + if (! isset($_COOKIE[$index])) { return FALSE; } @@ -328,7 +328,7 @@ class CI_Input { */ function server($index = '', $xss_clean = FALSE) { - if ( ! isset($_SERVER[$index])) + if (! isset($_SERVER[$index])) { return FALSE; } @@ -385,7 +385,7 @@ class CI_Input { $this->ip_address = end($x); } - if ( ! $this->valid_ip($this->ip_address)) + if (! $this->valid_ip($this->ip_address)) { $this->ip_address = '0.0.0.0'; } @@ -447,7 +447,7 @@ class CI_Input { return $this->user_agent; } - $this->user_agent = ( ! isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT']; + $this->user_agent = (! isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT']; return $this->user_agent; } diff --git a/system/libraries/Language.php b/system/libraries/Language.php index 3dac1a61f..a8e6366bb 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -83,7 +83,7 @@ class CI_Language { } - if ( ! isset($lang)) + if (! isset($lang)) { log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile); return; diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 31e7d660f..5cf1f2ae6 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -152,7 +152,7 @@ class CI_Loader { $model = strtolower($model); - if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT)) + if (! file_exists(APPPATH.'models/'.$path.$model.EXT)) { show_error('Unable to locate the model you have specified: '.$model); } @@ -165,7 +165,7 @@ class CI_Loader { $CI->load->database($db_conn, FALSE, TRUE); } - if ( ! class_exists('Model')) + if (! class_exists('Model')) { load_class('Model', FALSE); } @@ -230,7 +230,7 @@ class CI_Loader { */ function dbutil() { - if ( ! class_exists('CI_DB')) + if (! class_exists('CI_DB')) { $this->database(); } @@ -260,7 +260,7 @@ class CI_Loader { */ function dbforge() { - if ( ! class_exists('CI_DB')) + if (! class_exists('CI_DB')) { $this->database(); } @@ -353,7 +353,7 @@ class CI_Loader { */ function helper($helpers = array()) { - if ( ! is_array($helpers)) + if (! is_array($helpers)) { $helpers = array($helpers); } @@ -374,7 +374,7 @@ class CI_Loader { { $base_helper = BASEPATH.'helpers/'.$helper.EXT; - if ( ! file_exists($base_helper)) + if (! file_exists($base_helper)) { show_error('Unable to load the requested file: helpers/'.$helper.EXT); } @@ -435,7 +435,7 @@ class CI_Loader { */ function plugin($plugins = array()) { - if ( ! is_array($plugins)) + if (! is_array($plugins)) { $plugins = array($plugins); } @@ -505,7 +505,7 @@ class CI_Loader { */ function script($scripts = array()) { - if ( ! is_array($scripts)) + if (! is_array($scripts)) { $scripts = array($scripts); } @@ -519,7 +519,7 @@ class CI_Loader { continue; } - if ( ! file_exists(APPPATH.'scripts/'.$script.EXT)) + if (! file_exists(APPPATH.'scripts/'.$script.EXT)) { show_error('Unable to load the requested script: scripts/'.$script.EXT); } @@ -544,7 +544,7 @@ class CI_Loader { { $CI =& get_instance(); - if ( ! is_array($file)) + if (! is_array($file)) { $file = array($file); } @@ -630,7 +630,7 @@ class CI_Loader { // Set the default data variables foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val) { - $$_ci_val = ( ! isset($_ci_data[$_ci_val])) ? FALSE : $_ci_data[$_ci_val]; + $$_ci_val = (! isset($_ci_data[$_ci_val])) ? FALSE : $_ci_data[$_ci_val]; } // Set the path to the requested file @@ -646,7 +646,7 @@ class CI_Loader { $_ci_file = end($_ci_x); } - if ( ! file_exists($_ci_path)) + if (! file_exists($_ci_path)) { show_error('Unable to load the requested file: '.$_ci_file); } @@ -660,7 +660,7 @@ class CI_Loader { $_ci_CI =& get_instance(); foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var) { - if ( ! isset($this->$_ci_key)) + if (! isset($this->$_ci_key)) { $this->$_ci_key =& $_ci_CI->$_ci_key; } @@ -768,7 +768,7 @@ class CI_Loader { { $baseclass = BASEPATH.'libraries/'.ucfirst($class).EXT; - if ( ! file_exists($baseclass)) + if (! file_exists($baseclass)) { log_message('error', "Unable to load the requested class: ".$class); show_error("Unable to load the requested class: ".$class); @@ -797,7 +797,7 @@ class CI_Loader { $filepath = $path.'libraries/'.$class.EXT; // Does the file exist? No? Bummer... - if ( ! file_exists($filepath)) + if (! file_exists($filepath)) { continue; } @@ -858,7 +858,7 @@ class CI_Loader { } // Set the variable name we will assign the class to - $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; + $classvar = (! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; // Instantiate the class $CI =& get_instance(); @@ -888,7 +888,7 @@ class CI_Loader { { include_once(APPPATH.'config/autoload'.EXT); - if ( ! isset($autoload)) + if (! isset($autoload)) { return FALSE; } @@ -916,7 +916,7 @@ class CI_Loader { // A little tweak to remain backward compatible // The $autoload['core'] item was deprecated - if ( ! isset($autoload['libraries'])) + if (! isset($autoload['libraries'])) { $autoload['libraries'] = $autoload['core']; } diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 1aa8bd0f4..247aee13c 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -46,7 +46,7 @@ class CI_Log { $this->log_path = ($config['log_path'] != '') ? $config['log_path'] : BASEPATH.'logs/'; - if ( ! is_dir($this->log_path) OR ! is_really_writable($this->log_path)) + if (! is_dir($this->log_path) OR ! is_really_writable($this->log_path)) { $this->_enabled = FALSE; } @@ -84,7 +84,7 @@ class CI_Log { $level = strtoupper($level); - if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) + if (! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) { return FALSE; } @@ -92,12 +92,12 @@ class CI_Log { $filepath = $this->log_path.'log-'.date('Y-m-d').EXT; $message = ''; - if ( ! file_exists($filepath)) + if (! file_exists($filepath)) { $message .= "<"."?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; } - if ( ! $fp = @fopen($filepath, "a")) + if (! $fp = @fopen($filepath, "a")) { return FALSE; } diff --git a/system/libraries/Model.php b/system/libraries/Model.php index 8181ead32..e87d6045c 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -59,7 +59,7 @@ class Model { $CI =& get_instance(); foreach (array_keys(get_object_vars($CI)) as $key) { - if ( ! isset($this->$key) AND $key != $this->_parent_name) + if (! isset($this->$key) AND $key != $this->_parent_name) { // In some cases using references can cause // problems so we'll conditionally use them diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 07990eb16..d513a1279 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -137,7 +137,7 @@ class CI_Output { */ function cache($time) { - $this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time; + $this->cache_expiration = (! is_numeric($time)) ? 0 : $time; } // -------------------------------------------------------------------- @@ -187,7 +187,7 @@ class CI_Output { $elapsed = $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end'); $output = str_replace('{elapsed_time}', $elapsed, $output); - $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; + $memory = (! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; $output = str_replace('{memory_usage}', $memory, $output); // -------------------------------------------------------------------- @@ -220,7 +220,7 @@ class CI_Output { // Does the get_instance() function exist? // If not we know we are dealing with a cache file so we'll // simply echo out the data and exit. - if ( ! function_exists('get_instance')) + if (! function_exists('get_instance')) { echo $output; log_message('debug', "Final output sent to browser"); @@ -285,7 +285,7 @@ class CI_Output { $cache_path = ($path == '') ? BASEPATH.'cache/' : $path; - if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path)) + if (! is_dir($cache_path) OR ! is_really_writable($cache_path)) { return; } @@ -296,7 +296,7 @@ class CI_Output { $cache_path .= md5($uri); - if ( ! $fp = @fopen($cache_path, 'wb')) + if (! $fp = @fopen($cache_path, 'wb')) { log_message('error', "Unable to write cache file: ".$cache_path); return; @@ -327,7 +327,7 @@ class CI_Output { $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); - if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path)) + if (! is_dir($cache_path) OR ! is_really_writable($cache_path)) { return FALSE; } @@ -339,12 +339,12 @@ class CI_Output { $filepath = $cache_path.md5($uri); - if ( ! @file_exists($filepath)) + if (! @file_exists($filepath)) { return FALSE; } - if ( ! $fp = @fopen($filepath, 'rb')) + if (! $fp = @fopen($filepath, 'rb')) { return FALSE; } @@ -361,7 +361,7 @@ class CI_Output { fclose($fp); // Strip out the embedded timestamp - if ( ! preg_match("/(\d+TS--->)/", $cache, $match)) + if (! preg_match("/(\d+TS--->)/", $cache, $match)) { return FALSE; } diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 28b74f1f0..e1212035a 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -132,7 +132,7 @@ class CI_Pagination { show_error('Your number of links must be a positive number.'); } - if ( ! is_numeric($this->cur_page)) + if (! is_numeric($this->cur_page)) { $this->cur_page = 0; } diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index a0b310f00..417e04f29 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -130,7 +130,7 @@ class CI_Parser { $temp = $match['1']; foreach ($row as $key => $val) { - if ( ! is_array($val)) + if (! is_array($val)) { $temp = $this->_parse_single($key, $val, $temp); } @@ -158,7 +158,7 @@ class CI_Parser { */ function _match_pair($string, $variable) { - if ( ! preg_match("|".$this->l_delim . $variable . $this->r_delim."(.+)".$this->l_delim . '/' . $variable . $this->r_delim."|s", $string, $match)) + if (! preg_match("|".$this->l_delim . $variable . $this->r_delim."(.+)".$this->l_delim . '/' . $variable . $this->r_delim."|s", $string, $match)) { return FALSE; } diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 8a45933e1..807c1aff6 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -106,7 +106,7 @@ class CI_Profiler { $output .= '
'; $output .= "\n"; - if ( ! class_exists('CI_DB_driver')) + if (! class_exists('CI_DB_driver')) { $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; $output .= "\n"; @@ -175,7 +175,7 @@ class CI_Profiler { foreach ($_GET as $key => $val) { - if ( ! is_numeric($key)) + if (! is_numeric($key)) { $key = "'".$key."'"; } @@ -225,7 +225,7 @@ class CI_Profiler { foreach ($_POST as $key => $val) { - if ( ! is_numeric($key)) + if (! is_numeric($key)) { $key = "'".$key."'"; } diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 804e80bd2..6bb85518f 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -80,12 +80,12 @@ class CI_Router { // Load the routes.php file. @include(APPPATH.'config/routes'.EXT); - $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route; + $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']); // Fetch the complete URI string $this->uri->_fetch_uri_string(); @@ -202,7 +202,7 @@ class CI_Router { if (count($segments) > 0) { // Does the requested controller exist in the sub-folder? - if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT)) + if (! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT)) { show_404($this->fetch_directory().$segments[0]); } @@ -213,7 +213,7 @@ class CI_Router { $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)) + if (! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT)) { $this->directory = ''; return array(); diff --git a/system/libraries/Session.php b/system/libraries/Session.php index afa43348e..d4fdd3ac7 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -146,7 +146,7 @@ class CI_Session { * a new one. If it does, we'll update it. * */ - if ( ! $this->sess_read()) + if (! $this->sess_read()) { $this->sess_create(); } @@ -214,7 +214,7 @@ class CI_Session { $session = @unserialize($this->strip_slashes($session)); - if ( ! is_array($session) OR ! isset($session['last_activity'])) + if (! is_array($session) OR ! isset($session['last_activity'])) { log_message('error', 'The session cookie data did not contain a valid array. This could be a possible hacking attempt.'); return FALSE; @@ -439,7 +439,7 @@ class CI_Session { */ function userdata($item) { - return ( ! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; + return (! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; } // -------------------------------------------------------------------- @@ -452,7 +452,7 @@ class CI_Session { */ function all_userdata() { - return ( ! isset($this->userdata)) ? FALSE : $this->userdata; + return (! isset($this->userdata)) ? FALSE : $this->userdata; } // -------------------------------------------------------------------- diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 439fe2ef9..38affa579 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -53,7 +53,7 @@ class CI_Table { */ function set_template($template) { - if ( ! is_array($template)) + if (! is_array($template)) { return FALSE; } @@ -93,7 +93,7 @@ class CI_Table { */ function make_columns($array = array(), $col_limit = 0) { - if ( ! is_array($array) OR count($array) == 0) + if (! is_array($array) OR count($array) == 0) { return FALSE; } @@ -187,7 +187,7 @@ class CI_Table { { // The table data can optionally be passed to this function // either as a database result object or an array - if ( ! is_null($table_data)) + if (! is_null($table_data)) { if (is_object($table_data)) { @@ -246,7 +246,7 @@ class CI_Table { $i = 1; foreach($this->rows as $row) { - if ( ! is_array($row)) + if (! is_array($row)) { break; } @@ -309,7 +309,7 @@ class CI_Table { */ function _set_from_object($query) { - if ( ! is_object($query)) + if (! is_object($query)) { return FALSE; } @@ -317,7 +317,7 @@ class CI_Table { // First generate the headings from the table column names if (count($this->heading) == 0) { - if ( ! method_exists($query, 'list_fields')) + if (! method_exists($query, 'list_fields')) { return FALSE; } @@ -347,7 +347,7 @@ class CI_Table { */ function _set_from_array($data, $set_heading = TRUE) { - if ( ! is_array($data) OR count($data) == 0) + if (! is_array($data) OR count($data) == 0) { return FALSE; } @@ -355,7 +355,7 @@ class CI_Table { $i = 0; foreach ($data as $row) { - if ( ! is_array($row)) + if (! is_array($row)) { $this->rows[] = $data; break; @@ -394,7 +394,7 @@ class CI_Table { $this->temp = $this->_default_template(); foreach (array('table_open','heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end', 'row_start', 'row_end', 'cell_start', 'cell_end', 'row_alt_start', 'row_alt_end', 'cell_alt_start', 'cell_alt_end', 'table_close') as $val) { - if ( ! isset($this->template[$val])) + if (! isset($this->template[$val])) { $this->template[$val] = $this->temp[$val]; } diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index 5371e9050..3e1c20210 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -56,7 +56,7 @@ class CI_Trackback { */ function send($tb_data) { - if ( ! is_array($tb_data)) + if (! is_array($tb_data)) { $this->set_error('The send() method must be passed an array'); return FALSE; @@ -65,7 +65,7 @@ class CI_Trackback { // Pre-process the Trackback Data foreach (array('url', 'title', 'excerpt', 'blog_name', 'ping_url') as $item) { - if ( ! isset($tb_data[$item])) + if (! isset($tb_data[$item])) { $this->set_error('Required item missing: '.$item); return FALSE; @@ -102,7 +102,7 @@ class CI_Trackback { } // Build the Trackback data string - $charset = ( ! isset($tb_data['charset'])) ? $this->charset : $tb_data['charset']; + $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); @@ -139,13 +139,13 @@ class CI_Trackback { { foreach (array('url', 'title', 'blog_name', 'excerpt') as $val) { - if ( ! isset($_POST[$val]) OR $_POST[$val] == '') + if (! isset($_POST[$val]) OR $_POST[$val] == '') { $this->set_error('The following required POST variable is missing: '.$val); return FALSE; } - $this->data['charset'] = ( ! isset($_POST['charset'])) ? 'auto' : strtoupper(trim($_POST['charset'])); + $this->data['charset'] = (! isset($_POST['charset'])) ? 'auto' : strtoupper(trim($_POST['charset'])); if ($val != 'url' && function_exists('mb_convert_encoding')) { @@ -212,7 +212,7 @@ class CI_Trackback { */ function data($item) { - return ( ! isset($this->data[$item])) ? '' : $this->data[$item]; + return (! isset($this->data[$item])) ? '' : $this->data[$item]; } // -------------------------------------------------------------------- @@ -233,14 +233,14 @@ class CI_Trackback { $target = parse_url($url); // Open the socket - if ( ! $fp = @fsockopen($target['host'], 80)) + if (! $fp = @fsockopen($target['host'], 80)) { $this->set_error('Invalid Connection: '.$url); return FALSE; } // Build the path - $ppath = ( ! isset($target['path'])) ? $url : $target['path']; + $ppath = (! isset($target['path'])) ? $url : $target['path']; $path = (isset($target['query']) && $target['query'] != "") ? $ppath.'?'.$target['query'] : $ppath; @@ -267,7 +267,7 @@ class CI_Trackback { } @fclose($fp); - if ( ! eregi("0", $this->response)) + if (! eregi("0", $this->response)) { $message = 'An unknown error was encountered'; @@ -360,7 +360,7 @@ class CI_Trackback { $tb_array = explode('/', $url); $tb_end = $tb_array[count($tb_array)-1]; - if ( ! is_numeric($tb_end)) + if (! is_numeric($tb_end)) { $tb_end = $tb_array[count($tb_array)-2]; } @@ -378,13 +378,13 @@ class CI_Trackback { $tb_array = explode('/', $url); $tb_id = $tb_array[count($tb_array)-1]; - if ( ! is_numeric($tb_id)) + if (! is_numeric($tb_id)) { $tb_id = $tb_array[count($tb_array)-2]; } } - if ( ! preg_match ("/^([0-9]+)$/", $tb_id)) + if (! preg_match ("/^([0-9]+)$/", $tb_id)) { return false; } diff --git a/system/libraries/URI.php b/system/libraries/URI.php index d10a5daeb..f0d02101a 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -133,7 +133,7 @@ class CI_URI { */ function _parse_request_uri() { - if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '') + if (! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '') { return ''; } @@ -185,7 +185,7 @@ class CI_URI { { if ($str != '' AND $this->config->item('permitted_uri_chars') != '') { - if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) + if (! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) { exit('The URI you submitted has disallowed characters.'); } @@ -278,7 +278,7 @@ class CI_URI { */ function segment($n, $no_result = FALSE) { - return ( ! isset($this->segments[$n])) ? $no_result : $this->segments[$n]; + return (! isset($this->segments[$n])) ? $no_result : $this->segments[$n]; } // -------------------------------------------------------------------- @@ -297,7 +297,7 @@ class CI_URI { */ function rsegment($n, $no_result = FALSE) { - return ( ! isset($this->rsegments[$n])) ? $no_result : $this->rsegments[$n]; + return (! isset($this->rsegments[$n])) ? $no_result : $this->rsegments[$n]; } // -------------------------------------------------------------------- @@ -360,7 +360,7 @@ class CI_URI { $segment_array = 'rsegment_array'; } - if ( ! is_numeric($n)) + if (! is_numeric($n)) { return $default; } @@ -409,7 +409,7 @@ class CI_URI { { foreach ($default as $val) { - if ( ! array_key_exists($val, $retval)) + if (! array_key_exists($val, $retval)) { $retval[$val] = FALSE; } diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index ff4d0c7ed..3cdf45f12 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -260,8 +260,8 @@ class CI_Unit_test { { $back = debug_backtrace(); - $file = ( ! isset($back['1']['file'])) ? '' : $back['1']['file']; - $line = ( ! isset($back['1']['line'])) ? '' : $back['1']['line']; + $file = (! isset($back['1']['file'])) ? '' : $back['1']['file']; + $line = (! isset($back['1']['line'])) ? '' : $back['1']['line']; return array('file' => $file, 'line' => $line); } @@ -300,7 +300,7 @@ class CI_Unit_test { */ function _parse_template() { - if ( ! is_null($this->_template_rows)) + if (! is_null($this->_template_rows)) { return; } @@ -311,7 +311,7 @@ class CI_Unit_test { return; } - if ( ! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match)) + if (! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match)) { $this->_default_template(); return; diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 760d93999..f13907000 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -135,23 +135,23 @@ class CI_Upload { function do_upload($field = 'userfile') { // Is $_FILES[$field] set? If not, no reason to continue. - if ( ! isset($_FILES[$field])) + if (! isset($_FILES[$field])) { $this->set_error('upload_no_file_selected'); return FALSE; } // Is the upload path valid? - if ( ! $this->validate_upload_path()) + if (! $this->validate_upload_path()) { $this->set_error('upload_no_filepath'); return FALSE; } // Was the file able to be uploaded? If not, determine the reason why. - if ( ! is_uploaded_file($_FILES[$field]['tmp_name'])) + if (! is_uploaded_file($_FILES[$field]['tmp_name'])) { - $error = ( ! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error']; + $error = (! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error']; switch($error) { @@ -198,14 +198,14 @@ class CI_Upload { } // Is the file type allowed to be uploaded? - if ( ! $this->is_allowed_filetype()) + if (! $this->is_allowed_filetype()) { $this->set_error('upload_invalid_filetype'); return FALSE; } // Is the file size within the allowed maximum? - if ( ! $this->is_allowed_filesize()) + if (! $this->is_allowed_filesize()) { $this->set_error('upload_invalid_filesize'); return FALSE; @@ -213,7 +213,7 @@ class CI_Upload { // Are the image dimensions within the allowed size? // Note: This can fail if the server has an open_basdir restriction. - if ( ! $this->is_allowed_dimensions()) + if (! $this->is_allowed_dimensions()) { $this->set_error('upload_invalid_dimensions'); return FALSE; @@ -253,9 +253,9 @@ class CI_Upload { * we'll use move_uploaded_file(). One of the two should * reliably work in most environments */ - if ( ! @copy($this->file_temp, $this->upload_path.$this->file_name)) + if (! @copy($this->file_temp, $this->upload_path.$this->file_name)) { - if ( ! @move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name)) + if (! @move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name)) { $this->set_error('upload_destination_error'); return FALSE; @@ -350,7 +350,7 @@ class CI_Upload { $filename = md5(uniqid(mt_rand())).$this->file_ext; } - if ( ! file_exists($path.$filename)) + if (! file_exists($path.$filename)) { return $filename; } @@ -360,7 +360,7 @@ class CI_Upload { $new_filename = ''; for ($i = 1; $i < 100; $i++) { - if ( ! file_exists($path.$filename.$i.$this->file_ext)) + if (! file_exists($path.$filename.$i.$this->file_ext)) { $new_filename = $filename.$i.$this->file_ext; break; @@ -389,7 +389,7 @@ class CI_Upload { */ function set_max_filesize($n) { - $this->max_size = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + $this->max_size = (! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; } // -------------------------------------------------------------------- @@ -403,7 +403,7 @@ class CI_Upload { */ function set_max_width($n) { - $this->max_width = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + $this->max_width = (! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; } // -------------------------------------------------------------------- @@ -417,7 +417,7 @@ class CI_Upload { */ function set_max_height($n) { - $this->max_height = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + $this->max_height = (! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; } // -------------------------------------------------------------------- @@ -447,7 +447,7 @@ class CI_Upload { */ function set_image_properties($path = '') { - if ( ! $this->is_image()) + if (! $this->is_image()) { return; } @@ -460,7 +460,7 @@ class CI_Upload { $this->image_width = $D['0']; $this->image_height = $D['1']; - $this->image_type = ( ! isset($types[$D['2']])) ? 'unknown' : $types[$D['2']]; + $this->image_type = (! isset($types[$D['2']])) ? 'unknown' : $types[$D['2']]; $this->image_size_str = $D['3']; // string containing height and width } } @@ -587,7 +587,7 @@ class CI_Upload { */ function is_allowed_dimensions() { - if ( ! $this->is_image()) + if (! $this->is_image()) { return TRUE; } @@ -636,13 +636,13 @@ class CI_Upload { $this->upload_path = str_replace("\\", "/", realpath($this->upload_path)); } - if ( ! @is_dir($this->upload_path)) + if (! @is_dir($this->upload_path)) { $this->set_error('upload_no_filepath'); return FALSE; } - if ( ! is_really_writable($this->upload_path)) + if (! is_really_writable($this->upload_path)) { $this->set_error('upload_not_writable'); return FALSE; @@ -741,7 +741,7 @@ class CI_Upload { return FALSE; } - if ( ! $fp = @fopen($file, 'r+b')) + if (! $fp = @fopen($file, 'r+b')) { return FALSE; } @@ -830,7 +830,7 @@ class CI_Upload { } } - return ( ! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime]; + return (! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime]; } /** diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index ff6d4a933..dd60a56a1 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -63,7 +63,7 @@ class CI_User_agent { $this->agent = trim($_SERVER['HTTP_USER_AGENT']); } - if ( ! is_null($this->agent)) + if (! is_null($this->agent)) { if ($this->_load_agent_file()) { @@ -84,7 +84,7 @@ class CI_User_agent { */ function _load_agent_file() { - if ( ! @include(APPPATH.'config/user_agents'.EXT)) + if (! @include(APPPATH.'config/user_agents'.EXT)) { return FALSE; } @@ -339,7 +339,7 @@ class CI_User_agent { */ function is_referral() { - return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE; + return (! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -429,7 +429,7 @@ class CI_User_agent { */ function referrer() { - return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']); + return (! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']); } // -------------------------------------------------------------------- diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 18fdba2d3..16e8cd74f 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -74,7 +74,7 @@ class CI_Validation { } else { - if ( ! is_array($data)) + if (! is_array($data)) { $data = array($data => $field); } @@ -87,10 +87,10 @@ class CI_Validation { foreach($this->_fields as $key => $val) { - $this->$key = ( ! isset($_POST[$key])) ? '' : $this->prep_for_form($_POST[$key]); + $this->$key = (! isset($_POST[$key])) ? '' : $this->prep_for_form($_POST[$key]); $error = $key.'_error'; - if ( ! isset($this->$error)) + if (! isset($this->$error)) { $this->$error = ''; } @@ -112,7 +112,7 @@ class CI_Validation { */ function set_rules($data, $rules = '') { - if ( ! is_array($data)) + if (! is_array($data)) { if ($rules == '') return; @@ -141,7 +141,7 @@ class CI_Validation { */ function set_message($lang, $val = '') { - if ( ! is_array($lang)) + if (! is_array($lang)) { $lang = array($lang => $val); } @@ -195,9 +195,9 @@ class CI_Validation { $ex = explode('|', $rules); // Is the field required? If not, if the field is blank we'll move on to the next test - if ( ! in_array('required', $ex, TRUE)) + if (! in_array('required', $ex, TRUE)) { - if ( ! isset($_POST[$field]) OR $_POST[$field] == '') + if (! isset($_POST[$field]) OR $_POST[$field] == '') { continue; } @@ -212,11 +212,11 @@ class CI_Validation { * test for it here since there's not reason to go * further */ - if ( ! isset($_POST[$field])) + if (! isset($_POST[$field])) { if (in_array('isset', $ex, TRUE) OR in_array('required', $ex)) { - if ( ! isset($this->_error_messages['isset'])) + if (! isset($this->_error_messages['isset'])) { if (FALSE === ($line = $this->CI->lang->line('isset'))) { @@ -229,7 +229,7 @@ class CI_Validation { } // Build the error message - $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; + $mfield = (! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; $message = sprintf($line, $mfield); // Set the error variable. Example: $this->username_error @@ -274,7 +274,7 @@ class CI_Validation { // Call the function that corresponds to the rule if ($callback === TRUE) { - if ( ! method_exists($this->CI, $rule)) + if (! method_exists($this->CI, $rule)) { continue; } @@ -282,7 +282,7 @@ class CI_Validation { $result = $this->CI->$rule($_POST[$field], $param); // If the field isn't required and we just processed a callback we'll move on... - if ( ! in_array('required', $ex, TRUE) AND $result !== FALSE) + if (! in_array('required', $ex, TRUE) AND $result !== FALSE) { continue 2; } @@ -290,7 +290,7 @@ class CI_Validation { } else { - if ( ! method_exists($this, $rule)) + if (! method_exists($this, $rule)) { /* * Run the native PHP function if called for @@ -314,7 +314,7 @@ class CI_Validation { // Did the rule test negatively? If so, grab the error. if ($result === FALSE) { - if ( ! isset($this->_error_messages[$rule])) + if (! isset($this->_error_messages[$rule])) { if (FALSE === ($line = $this->CI->lang->line($rule))) { @@ -327,8 +327,8 @@ class CI_Validation { } // Build the error message - $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; - $mparam = ( ! isset($this->_fields[$param])) ? $param : $this->_fields[$param]; + $mfield = (! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; + $mparam = (! isset($this->_fields[$param])) ? $param : $this->_fields[$param]; $message = sprintf($line, $mfield, $mparam); // Set the error variable. Example: $this->username_error @@ -385,13 +385,13 @@ class CI_Validation { */ function required($str) { - if ( ! is_array($str)) + if (! is_array($str)) { return (trim($str) == '') ? FALSE : TRUE; } else { - return ( ! empty($str)); + return (! empty($str)); } } @@ -406,7 +406,7 @@ class CI_Validation { */ function matches($str, $field) { - if ( ! isset($_POST[$field])) + if (! isset($_POST[$field])) { return FALSE; } @@ -482,7 +482,7 @@ class CI_Validation { */ function valid_email($str) { - return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; + return (! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -537,7 +537,7 @@ class CI_Validation { */ function alpha($str) { - return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE; + return (! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -551,7 +551,7 @@ class CI_Validation { */ function alpha_numeric($str) { - return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE; + return (! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -565,7 +565,7 @@ class CI_Validation { */ function alpha_dash($str) { - return ( ! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE; + return (! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -594,7 +594,7 @@ class CI_Validation { */ function is_numeric($str) { - return ( ! is_numeric($str)) ? FALSE : TRUE; + return (! is_numeric($str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index f90ee56b1..f8ad01714 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -13,7 +13,7 @@ * @filesource */ -if ( ! function_exists('xml_parser_create')) +if (! function_exists('xml_parser_create')) { show_error('Your PHP installation does not support XML'); } @@ -176,7 +176,7 @@ class CI_Xmlrpc { function timeout($seconds=5) { - if ( ! is_null($this->client) && is_int($seconds)) + if (! is_null($this->client) && is_int($seconds)) { $this->client->timeout = $seconds; } @@ -199,7 +199,7 @@ class CI_Xmlrpc { function request($incoming) { - if ( ! is_array($incoming)) + if (! is_array($incoming)) { // Send Error } @@ -231,7 +231,7 @@ class CI_Xmlrpc { { if (is_array($value) && isset($value['0'])) { - if ( ! isset($value['1']) OR ! isset($this->xmlrpcTypes[strtolower($value['1'])])) + if (! isset($value['1']) OR ! isset($this->xmlrpcTypes[strtolower($value['1'])])) { if (is_array($value[0])) { @@ -275,12 +275,12 @@ 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)) + if (! $this->result = $this->client->send($this->message)) { $this->error = $this->result->errstr; return FALSE; } - elseif( ! is_object($this->result->val)) + elseif(! is_object($this->result->val)) { $this->error = $this->result->errstr; return FALSE; @@ -765,7 +765,7 @@ 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; } - elseif ( ! is_object($this->xh[$parser]['value'])) + elseif (! is_object($this->xh[$parser]['value'])) { $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); return $r; @@ -961,7 +961,7 @@ class XML_RPC_Message extends CI_Xmlrpc case 'STRUCT': case 'ARRAY': $cur_val = array_shift($this->xh[$the_parser]['valuestack']); - $this->xh[$the_parser]['value'] = ( ! isset($cur_val['values'])) ? array() : $cur_val['values']; + $this->xh[$the_parser]['value'] = (! isset($cur_val['values'])) ? array() : $cur_val['values']; $this->xh[$the_parser]['vt'] = strtolower($name); break; case 'NAME': @@ -1101,7 +1101,7 @@ class XML_RPC_Message extends CI_Xmlrpc $this->xh[$the_parser]['lv'] = 2; // Found a value } - if( ! @isset($this->xh[$the_parser]['ac'])) + if(! @isset($this->xh[$the_parser]['ac'])) { $this->xh[$the_parser]['ac'] = ''; } diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index ac644d894..1b2ffca05 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -13,12 +13,12 @@ * @filesource */ -if ( ! function_exists('xml_parser_create')) +if (! function_exists('xml_parser_create')) { show_error('Your PHP installation does not support XML'); } -if ( ! class_exists('CI_Xmlrpc')) +if (! class_exists('CI_Xmlrpc')) { show_error('You must load the Xmlrpc class before loading the Xmlrpcs class in order to create a server.'); } @@ -176,7 +176,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc // PARSE + PROCESS XML DATA //------------------------------------- - if ( ! xml_parse($parser, $data, 1)) + if (! xml_parse($parser, $data, 1)) { // return XML error as a faultCode $r = new XML_RPC_Response(0, @@ -244,7 +244,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc // Valid Method //------------------------------------- - if ( ! isset($this->methods[$methName]['function'])) + if (! isset($this->methods[$methName]['function'])) { return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); } diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index fab8e7f6b..4bdc92547 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -57,7 +57,7 @@ class CI_Zip { { foreach ((array)$directory as $dir) { - if ( ! preg_match("|.+/$|", $dir)) + if (! preg_match("|.+/$|", $dir)) { $dir .= '/'; } @@ -196,7 +196,7 @@ class CI_Zip { */ function read_file($path, $preserve_filepath = FALSE) { - if ( ! file_exists($path)) + if (! file_exists($path)) { return FALSE; } @@ -301,7 +301,7 @@ class CI_Zip { */ function archive($filepath) { - if ( ! ($fp = @fopen($filepath, "wb"))) + if (! ($fp = @fopen($filepath, "wb"))) { return FALSE; } @@ -326,7 +326,7 @@ class CI_Zip { */ function download($filename = 'backup.zip') { - if ( ! preg_match("|.+?\.zip$|", $filename)) + if (! preg_match("|.+?\.zip$|", $filename)) { $filename .= '.zip'; } -- cgit v1.2.3-24-g4f1b From 14031d152b76e7744d6f8a70964ecae77ca55179 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 5 May 2008 18:29:43 +0000 Subject: implemented fopen mode constants --- system/libraries/Email.php | 2 +- system/libraries/Log.php | 2 +- system/libraries/Upload.php | 2 +- system/libraries/Zip.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 3b4dddd00..d71f593e9 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1070,7 +1070,7 @@ class CI_Email { $attachment[$z++] = $h; $file = filesize($filename) +1; - if (! $fp = fopen($filename, 'r')) + if (! $fp = fopen($filename, FOPEN_READ_BOF)) { $this->_set_error_message('email_attachment_unreadable', $filename); return FALSE; diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 247aee13c..370ab7922 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -97,7 +97,7 @@ class CI_Log { $message .= "<"."?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; } - if (! $fp = @fopen($filepath, "a")) + if (! $fp = @fopen($filepath, FOPEN_WRITE_CREATE_EOF)) { return FALSE; } diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index f13907000..853c162bd 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -741,7 +741,7 @@ class CI_Upload { return FALSE; } - if (! $fp = @fopen($file, 'r+b')) + if (! $fp = @fopen($file, FOPEN_READ_WRITE_BOF)) { return FALSE; } diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 4bdc92547..6b5988017 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -301,7 +301,7 @@ class CI_Zip { */ function archive($filepath) { - if (! ($fp = @fopen($filepath, "wb"))) + if (! ($fp = @fopen($filepath, FOPEN_WRITE_CREATE_BOF))) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 3be20e26b7d3c0f60bc60b314a85138100edab52 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 5 May 2008 20:07:09 +0000 Subject: tweak to the new fopen mode constant names --- system/libraries/Email.php | 2 +- system/libraries/Log.php | 2 +- system/libraries/Upload.php | 2 +- system/libraries/Zip.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index d71f593e9..e0fa689b3 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1070,7 +1070,7 @@ class CI_Email { $attachment[$z++] = $h; $file = filesize($filename) +1; - if (! $fp = fopen($filename, FOPEN_READ_BOF)) + if (! $fp = fopen($filename, FOPEN_READ)) { $this->_set_error_message('email_attachment_unreadable', $filename); return FALSE; diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 370ab7922..26757ba50 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -97,7 +97,7 @@ class CI_Log { $message .= "<"."?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; } - if (! $fp = @fopen($filepath, FOPEN_WRITE_CREATE_EOF)) + if (! $fp = @fopen($filepath, FOPEN_WRITE_CREATE)) { return FALSE; } diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 853c162bd..0fc38dc4f 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -741,7 +741,7 @@ class CI_Upload { return FALSE; } - if (! $fp = @fopen($file, FOPEN_READ_WRITE_BOF)) + if (! $fp = @fopen($file, FOPEN_READ_WRITE)) { return FALSE; } diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 6b5988017..f7f47ab42 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -301,7 +301,7 @@ class CI_Zip { */ function archive($filepath) { - if (! ($fp = @fopen($filepath, FOPEN_WRITE_CREATE_BOF))) + if (! ($fp = @fopen($filepath, FOPEN_WRITE_CREATE_DESTRUCTIVE))) { return FALSE; } -- cgit v1.2.3-24-g4f1b From ff390bdb457dbcfb5ba3e95323bce5f4a2c17497 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 6 May 2008 00:37:12 +0000 Subject: DB Forge is now assigned to any models that exist after loading (#3457). --- system/libraries/Loader.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 5cf1f2ae6..5966aebf6 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -272,6 +272,8 @@ class CI_Loader { $class = 'CI_DB_'.$CI->db->dbdriver.'_forge'; $CI->dbforge = new $class(); + + $CI->load->_ci_assign_to_models(); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From be8ec803cf8542acca9d2dd24c46b219fecabd9c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 6 May 2008 01:02:41 +0000 Subject: Fixed a bug in the table library that could cause identically constructed rows to be dropped (#3459). --- system/libraries/Table.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 38affa579..01b490a5d 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -110,8 +110,7 @@ class CI_Table { $new = array(); while(count($array) > 0) { - $temp = array_slice($array, 0, $col_limit); - $array = array_diff($array, $temp); + $temp = array_splice($array, 0, $col_limit); if (count($temp) < $col_limit) { -- cgit v1.2.3-24-g4f1b From 62a90205c4ace42df775dbe1354c41340e89c92c Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 7 May 2008 16:40:28 +0000 Subject: removed SCRIPT_NAME from path provided by ORIG_PATH_INFO to remove the path and script name from the URI data (bug #3191) --- system/libraries/URI.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/URI.php b/system/libraries/URI.php index f0d02101a..8ee888a2e 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -92,7 +92,8 @@ class CI_URI { $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); if (trim($path, '/') != '' AND $path != "/".SELF) { - $this->uri_string = $path; + // remove path and script information so we have good URI data + $this->uri_string = str_replace($_SERVER['SCRIPT_NAME'], '', $path); return; } -- cgit v1.2.3-24-g4f1b From 4dc06183aa67ba1911562719c97f41c6a9529075 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 7 May 2008 22:45:21 +0000 Subject: Fixed bug with recursive deletes in delete_dir() http://codeigniter.com/bug_tracker/bug/4215/ --- system/libraries/Ftp.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 1b5ec2fd2..74b7728fa 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -379,15 +379,15 @@ class CI_FTP { $list = $this->list_files($filepath); - if ($list !== FALSE AND count($list) > 0) + if ($list !== FALSE) { foreach ($list as $item) { // If we can't delete the item it's probaly a folder so // we'll recursively call delete_dir() - if (! @ftp_delete($this->conn_id, $filepath.$item)) + if (! @ftp_delete($this->conn_id, $item)) { - $this->delete_dir($filepath.$item); + $this->delete_dir($item); } } } -- cgit v1.2.3-24-g4f1b From 40306b5283b2929e344c7e11da7b736b9e51ef43 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 7 May 2008 22:52:45 +0000 Subject: Fixed a bug where $data was not being converted to an array properly in set_rules() http://codeigniter.com/bug_tracker/bug/4220/ --- system/libraries/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 16e8cd74f..f628d8612 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -117,7 +117,7 @@ class CI_Validation { if ($rules == '') return; - $data[$data] = $rules; + $data = array($data => $rules); } foreach ($data as $key => $val) -- cgit v1.2.3-24-g4f1b From 044379d18fbfb7673e5a5992e9c5af7830e358a8 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 8 May 2008 18:57:58 +0000 Subject: added 'object' key to the XML-RPCS config allowing the passing of a class object for method calls that aren't part of the CI super object --- system/libraries/Xmlrpcs.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 1b2ffca05..7a4bc825e 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -41,7 +41,9 @@ class CI_Xmlrpcs extends CI_Xmlrpc var $system_methods = array(); // XML RPC Server methods var $controller_obj; - + var $object = FALSE; + + //------------------------------------- // Constructor, more or less //------------------------------------- @@ -74,6 +76,11 @@ class CI_Xmlrpcs extends CI_Xmlrpc { $this->debug = $config['debug']; } + + if (isset($config['object']) && is_object($config['object'])) + { + $this->object = $config['object']; + } } //------------------------------------- @@ -320,11 +327,16 @@ class CI_Xmlrpcs extends CI_Xmlrpc } else { - $CI =& get_instance(); - return $CI->$method_parts['1']($m); - //$class = new $method_parts['0']; - //return $class->$method_parts['1']($m); - //return call_user_func(array(&$method_parts['0'],$method_parts['1']), $m); + if ($this->object === FALSE) + { + $CI =& get_instance(); + return $CI->$method_parts['1']($m); + } + else + { + return $this->object->$method_parts['1']($m); + //return call_user_func(array(&$method_parts['0'],$method_parts['1']), $m); + } } } else -- cgit v1.2.3-24-g4f1b From 8e94646b3147d5f9f70ad09b4cc0aff284b93a98 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 8 May 2008 19:55:35 +0000 Subject: removed extraneous error message from Upload lib on failure of validate_upload_path() http://codeigniter.com/bug_tracker/bug/4390/ --- system/libraries/Upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 0fc38dc4f..317cf9560 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -144,7 +144,7 @@ class CI_Upload { // Is the upload path valid? if (! $this->validate_upload_path()) { - $this->set_error('upload_no_filepath'); + // errors will already be set by validate_upload_path() so just return FALSE return FALSE; } -- cgit v1.2.3-24-g4f1b From af4a8a057f7b69da2973847717d0ff9388669f54 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 8 May 2008 22:16:33 +0000 Subject: added dot transformation to body of email when sending via SMTP --- system/libraries/Email.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index e0fa689b3..aa08971f9 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1436,8 +1436,9 @@ class CI_Email { } $this->_send_command('data'); - - $this->_send_data($this->_header_str . $this->_finalbody); + + // perform dot transformation on any lines that begin with a dot + $this->_send_data($this->_header_str . preg_replace('/^\./m', '..$1', $this->_finalbody)); $this->_send_data('.'); -- cgit v1.2.3-24-g4f1b From 5583e1aae64ff7e902136c4ba610d438dc2015d4 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sun, 11 May 2008 15:48:20 +0000 Subject: removed closing PHP tag from all framework files --- system/libraries/Benchmark.php | 1 - system/libraries/Calendar.php | 1 - system/libraries/Config.php | 1 - system/libraries/Controller.php | 1 - system/libraries/Email.php | 1 - system/libraries/Encrypt.php | 1 - system/libraries/Exceptions.php | 1 - system/libraries/Ftp.php | 1 - system/libraries/Hooks.php | 1 - system/libraries/Image_lib.php | 1 - system/libraries/Input.php | 1 - system/libraries/Language.php | 1 - system/libraries/Loader.php | 1 - system/libraries/Log.php | 1 - system/libraries/Model.php | 1 - system/libraries/Output.php | 1 - system/libraries/Pagination.php | 1 - system/libraries/Parser.php | 1 - system/libraries/Profiler.php | 1 - system/libraries/Router.php | 1 - system/libraries/Session.php | 1 - system/libraries/Sha1.php | 1 - system/libraries/Table.php | 1 - system/libraries/Trackback.php | 1 - system/libraries/URI.php | 1 - system/libraries/Unit_test.php | 1 - system/libraries/Upload.php | 1 - system/libraries/User_agent.php | 1 - system/libraries/Validation.php | 1 - system/libraries/Xmlrpc.php | 1 - system/libraries/Xmlrpcs.php | 1 - system/libraries/Zip.php | 1 - 32 files changed, 32 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index 323d9668d..db9239d61 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -108,4 +108,3 @@ class CI_Benchmark { } // END CI_Benchmark class -?> \ No newline at end of file diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index e9621fec1..42e70f4de 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -472,4 +472,3 @@ class CI_Calendar { } // END CI_Calendar class -?> \ No newline at end of file diff --git a/system/libraries/Config.php b/system/libraries/Config.php index 73f1986a0..a3a7d9d75 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -242,4 +242,3 @@ class CI_Config { } // END CI_Config class -?> \ No newline at end of file diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 4957fc35e..e5b2f2796 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -121,4 +121,3 @@ class Controller extends CI_Base { } // END _Controller class -?> \ No newline at end of file diff --git a/system/libraries/Email.php b/system/libraries/Email.php index aa08971f9..bb72ad439 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1848,4 +1848,3 @@ class CI_Email { } // END CI_Email class -?> \ No newline at end of file diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 9a784d254..7463fd0a6 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -481,4 +481,3 @@ class CI_Encrypt { } // END CI_Encrypt class -?> \ No newline at end of file diff --git a/system/libraries/Exceptions.php b/system/libraries/Exceptions.php index 7c9640554..0b647df39 100644 --- a/system/libraries/Exceptions.php +++ b/system/libraries/Exceptions.php @@ -167,4 +167,3 @@ class CI_Exceptions { } // END Exceptions Class -?> \ No newline at end of file diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 74b7728fa..f45f992d1 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -613,4 +613,3 @@ class CI_FTP { } // END FTP Class -?> \ No newline at end of file diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index a41320c5e..c68b42353 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -221,4 +221,3 @@ class CI_Hooks { } // END CI_Hooks class -?> \ No newline at end of file diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index c236e391e..d2f464044 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1533,4 +1533,3 @@ class CI_Image_lib { } // END Image_lib Class -?> \ No newline at end of file diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 8a0478be2..9d64a2cb4 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -923,4 +923,3 @@ class CI_Input { } // END Input class -?> \ No newline at end of file diff --git a/system/libraries/Language.php b/system/libraries/Language.php index a8e6366bb..45c839250 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -118,4 +118,3 @@ class CI_Language { } // END Language Class -?> \ No newline at end of file diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 5966aebf6..60dc73b1f 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -1027,4 +1027,3 @@ class CI_Loader { } } -?> \ No newline at end of file diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 26757ba50..1754b3980 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -115,4 +115,3 @@ class CI_Log { } // END Log Class -?> \ No newline at end of file diff --git a/system/libraries/Model.php b/system/libraries/Model.php index e87d6045c..ce8e128ad 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -79,4 +79,3 @@ class Model { } // END Model Class -?> \ No newline at end of file diff --git a/system/libraries/Output.php b/system/libraries/Output.php index d513a1279..69206f519 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -383,4 +383,3 @@ class CI_Output { } // END Output Class -?> \ No newline at end of file diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index e1212035a..68bd1892d 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -215,4 +215,3 @@ class CI_Pagination { } } // END Pagination Class -?> \ No newline at end of file diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 417e04f29..d2bdba11a 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -168,4 +168,3 @@ class CI_Parser { } // END Parser Class -?> \ No newline at end of file diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 807c1aff6..38f0d2346 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -340,4 +340,3 @@ class CI_Profiler { } // END CI_Profiler class -?> \ No newline at end of file diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 6bb85518f..ade01a6c1 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -374,4 +374,3 @@ class CI_Router { } // END Router Class -?> \ No newline at end of file diff --git a/system/libraries/Session.php b/system/libraries/Session.php index d4fdd3ac7..c77eb9e0a 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -649,4 +649,3 @@ class CI_Session { } // END Session Class -?> \ No newline at end of file diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index 6bb891177..768ffa166 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -246,4 +246,3 @@ class CI_SHA { } } // END CI_SHA -?> \ No newline at end of file diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 01b490a5d..5edb5e4cc 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -435,4 +435,3 @@ class CI_Table { } -?> \ No newline at end of file diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index 3e1c20210..b4c296d1e 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -545,4 +545,3 @@ class CI_Trackback { } // END Trackback Class -?> \ No newline at end of file diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 8ee888a2e..59fcff3d7 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -586,4 +586,3 @@ class CI_URI { } // END URI Class -?> \ No newline at end of file diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 3cdf45f12..e02ecf037 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -340,4 +340,3 @@ function is_false($test) return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; } -?> \ No newline at end of file diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 317cf9560..e0ce2b037 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -875,4 +875,3 @@ class CI_Upload { } // END Upload Class -?> \ No newline at end of file diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index dd60a56a1..a8ce787dc 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -497,4 +497,3 @@ class CI_User_agent { } -?> \ No newline at end of file diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index f628d8612..8a81568c4 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -805,4 +805,3 @@ class CI_Validation { } // END Validation Class -?> \ No newline at end of file diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index f8ad01714..dee71f4d1 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -1416,4 +1416,3 @@ class XML_RPC_Values extends CI_Xmlrpc } // END XML_RPC_Values Class -?> \ No newline at end of file diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 7a4bc825e..11f0cfc40 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -531,4 +531,3 @@ class CI_Xmlrpcs extends CI_Xmlrpc } // END XML_RPC_Server class -?> \ No newline at end of file diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index f7f47ab42..1940ded37 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -374,4 +374,3 @@ class CI_Zip { } } -?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c7deac9f2f9e43cedb18202542e8a46061df046e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sun, 11 May 2008 16:27:41 +0000 Subject: Undoing change committed in r1115 --- system/libraries/Benchmark.php | 1 + system/libraries/Calendar.php | 1 + system/libraries/Config.php | 1 + system/libraries/Controller.php | 1 + system/libraries/Email.php | 1 + system/libraries/Encrypt.php | 1 + system/libraries/Exceptions.php | 1 + system/libraries/Ftp.php | 1 + system/libraries/Hooks.php | 1 + system/libraries/Image_lib.php | 1 + system/libraries/Input.php | 1 + system/libraries/Language.php | 1 + system/libraries/Loader.php | 1 + system/libraries/Log.php | 1 + system/libraries/Model.php | 1 + system/libraries/Output.php | 1 + system/libraries/Pagination.php | 1 + system/libraries/Parser.php | 1 + system/libraries/Profiler.php | 1 + system/libraries/Router.php | 1 + system/libraries/Session.php | 1 + system/libraries/Sha1.php | 1 + system/libraries/Table.php | 1 + system/libraries/Trackback.php | 1 + system/libraries/URI.php | 1 + system/libraries/Unit_test.php | 1 + system/libraries/Upload.php | 1 + system/libraries/User_agent.php | 1 + system/libraries/Validation.php | 1 + system/libraries/Xmlrpc.php | 1 + system/libraries/Xmlrpcs.php | 1 + system/libraries/Zip.php | 1 + 32 files changed, 32 insertions(+) (limited to 'system/libraries') diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index db9239d61..323d9668d 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -108,3 +108,4 @@ class CI_Benchmark { } // END CI_Benchmark class +?> \ No newline at end of file diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 42e70f4de..e9621fec1 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -472,3 +472,4 @@ class CI_Calendar { } // END CI_Calendar class +?> \ No newline at end of file diff --git a/system/libraries/Config.php b/system/libraries/Config.php index a3a7d9d75..73f1986a0 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -242,3 +242,4 @@ class CI_Config { } // END CI_Config class +?> \ No newline at end of file diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index e5b2f2796..4957fc35e 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -121,3 +121,4 @@ class Controller extends CI_Base { } // END _Controller class +?> \ No newline at end of file diff --git a/system/libraries/Email.php b/system/libraries/Email.php index bb72ad439..aa08971f9 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1848,3 +1848,4 @@ class CI_Email { } // END CI_Email class +?> \ No newline at end of file diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 7463fd0a6..9a784d254 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -481,3 +481,4 @@ class CI_Encrypt { } // END CI_Encrypt class +?> \ No newline at end of file diff --git a/system/libraries/Exceptions.php b/system/libraries/Exceptions.php index 0b647df39..7c9640554 100644 --- a/system/libraries/Exceptions.php +++ b/system/libraries/Exceptions.php @@ -167,3 +167,4 @@ class CI_Exceptions { } // END Exceptions Class +?> \ No newline at end of file diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index f45f992d1..74b7728fa 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -613,3 +613,4 @@ class CI_FTP { } // END FTP Class +?> \ No newline at end of file diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index c68b42353..a41320c5e 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -221,3 +221,4 @@ class CI_Hooks { } // END CI_Hooks class +?> \ No newline at end of file diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index d2f464044..c236e391e 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1533,3 +1533,4 @@ class CI_Image_lib { } // END Image_lib Class +?> \ No newline at end of file diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 9d64a2cb4..8a0478be2 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -923,3 +923,4 @@ class CI_Input { } // END Input class +?> \ No newline at end of file diff --git a/system/libraries/Language.php b/system/libraries/Language.php index 45c839250..a8e6366bb 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -118,3 +118,4 @@ class CI_Language { } // END Language Class +?> \ No newline at end of file diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 60dc73b1f..5966aebf6 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -1027,3 +1027,4 @@ class CI_Loader { } } +?> \ No newline at end of file diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 1754b3980..26757ba50 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -115,3 +115,4 @@ class CI_Log { } // END Log Class +?> \ No newline at end of file diff --git a/system/libraries/Model.php b/system/libraries/Model.php index ce8e128ad..e87d6045c 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -79,3 +79,4 @@ class Model { } // END Model Class +?> \ No newline at end of file diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 69206f519..d513a1279 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -383,3 +383,4 @@ class CI_Output { } // END Output Class +?> \ No newline at end of file diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 68bd1892d..e1212035a 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -215,3 +215,4 @@ class CI_Pagination { } } // END Pagination Class +?> \ No newline at end of file diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index d2bdba11a..417e04f29 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -168,3 +168,4 @@ class CI_Parser { } // END Parser Class +?> \ No newline at end of file diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 38f0d2346..807c1aff6 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -340,3 +340,4 @@ class CI_Profiler { } // END CI_Profiler class +?> \ No newline at end of file diff --git a/system/libraries/Router.php b/system/libraries/Router.php index ade01a6c1..6bb85518f 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -374,3 +374,4 @@ class CI_Router { } // END Router Class +?> \ No newline at end of file diff --git a/system/libraries/Session.php b/system/libraries/Session.php index c77eb9e0a..d4fdd3ac7 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -649,3 +649,4 @@ class CI_Session { } // END Session Class +?> \ No newline at end of file diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index 768ffa166..6bb891177 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -246,3 +246,4 @@ class CI_SHA { } } // END CI_SHA +?> \ No newline at end of file diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 5edb5e4cc..01b490a5d 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -435,3 +435,4 @@ class CI_Table { } +?> \ No newline at end of file diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index b4c296d1e..3e1c20210 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -545,3 +545,4 @@ class CI_Trackback { } // END Trackback Class +?> \ No newline at end of file diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 59fcff3d7..8ee888a2e 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -586,3 +586,4 @@ class CI_URI { } // END URI Class +?> \ No newline at end of file diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index e02ecf037..3cdf45f12 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -340,3 +340,4 @@ function is_false($test) return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; } +?> \ No newline at end of file diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index e0ce2b037..317cf9560 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -875,3 +875,4 @@ class CI_Upload { } // END Upload Class +?> \ No newline at end of file diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index a8ce787dc..dd60a56a1 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -497,3 +497,4 @@ class CI_User_agent { } +?> \ No newline at end of file diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 8a81568c4..f628d8612 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -805,3 +805,4 @@ class CI_Validation { } // END Validation Class +?> \ No newline at end of file diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index dee71f4d1..f8ad01714 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -1416,3 +1416,4 @@ class XML_RPC_Values extends CI_Xmlrpc } // END XML_RPC_Values Class +?> \ No newline at end of file diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 11f0cfc40..7a4bc825e 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -531,3 +531,4 @@ class CI_Xmlrpcs extends CI_Xmlrpc } // END XML_RPC_Server class +?> \ No newline at end of file diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 1940ded37..f7f47ab42 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -374,3 +374,4 @@ class CI_Zip { } } +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From a3ffbbb75ab9403941e4f810703313432b3993cc Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sun, 11 May 2008 18:18:29 +0000 Subject: Removed closing PHP tags, replaced with a comment block identifying the end of the file --- system/libraries/Benchmark.php | 4 +++- system/libraries/Calendar.php | 4 +++- system/libraries/Config.php | 4 +++- system/libraries/Controller.php | 4 +++- system/libraries/Email.php | 4 +++- system/libraries/Encrypt.php | 4 +++- system/libraries/Exceptions.php | 4 +++- system/libraries/Ftp.php | 4 +++- system/libraries/Hooks.php | 4 +++- system/libraries/Image_lib.php | 4 +++- system/libraries/Input.php | 4 +++- system/libraries/Language.php | 4 +++- system/libraries/Loader.php | 4 +++- system/libraries/Log.php | 4 +++- system/libraries/Model.php | 4 +++- system/libraries/Output.php | 4 +++- system/libraries/Pagination.php | 4 +++- system/libraries/Parser.php | 4 +++- system/libraries/Profiler.php | 4 +++- system/libraries/Router.php | 4 +++- system/libraries/Session.php | 4 +++- system/libraries/Sha1.php | 4 +++- system/libraries/Table.php | 4 +++- system/libraries/Trackback.php | 4 +++- system/libraries/URI.php | 4 +++- system/libraries/Unit_test.php | 4 +++- system/libraries/Upload.php | 4 +++- system/libraries/User_agent.php | 4 +++- system/libraries/Validation.php | 4 +++- system/libraries/Xmlrpc.php | 4 +++- system/libraries/Xmlrpcs.php | 4 +++- system/libraries/Zip.php | 4 +++- 32 files changed, 96 insertions(+), 32 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index 323d9668d..f83e86482 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -108,4 +108,6 @@ class CI_Benchmark { } // END CI_Benchmark class -?> \ No newline at end of file + +/* End of file Benchmark.php */ +/* Location: ./system/libraries/Benchmark.php */ \ No newline at end of file diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index e9621fec1..fbb275c5f 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -472,4 +472,6 @@ class CI_Calendar { } // END CI_Calendar class -?> \ No newline at end of file + +/* End of file Calendar.php */ +/* Location: ./system/libraries/Calendar.php */ \ No newline at end of file diff --git a/system/libraries/Config.php b/system/libraries/Config.php index 73f1986a0..f3ae76390 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -242,4 +242,6 @@ class CI_Config { } // END CI_Config class -?> \ No newline at end of file + +/* End of file Config.php */ +/* Location: ./system/libraries/Config.php */ \ No newline at end of file diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 4957fc35e..1a1e3df53 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -121,4 +121,6 @@ class Controller extends CI_Base { } // END _Controller class -?> \ No newline at end of file + +/* End of file Controller.php */ +/* Location: ./system/libraries/Controller.php */ \ No newline at end of file diff --git a/system/libraries/Email.php b/system/libraries/Email.php index aa08971f9..d32928a66 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1848,4 +1848,6 @@ class CI_Email { } // END CI_Email class -?> \ No newline at end of file + +/* End of file Email.php */ +/* Location: ./system/libraries/Email.php */ \ No newline at end of file diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 9a784d254..4b13efda3 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -481,4 +481,6 @@ class CI_Encrypt { } // END CI_Encrypt class -?> \ No newline at end of file + +/* End of file Encrypt.php */ +/* Location: ./system/libraries/Encrypt.php */ \ No newline at end of file diff --git a/system/libraries/Exceptions.php b/system/libraries/Exceptions.php index 7c9640554..428759042 100644 --- a/system/libraries/Exceptions.php +++ b/system/libraries/Exceptions.php @@ -167,4 +167,6 @@ class CI_Exceptions { } // END Exceptions Class -?> \ No newline at end of file + +/* End of file Exceptions.php */ +/* Location: ./system/libraries/Exceptions.php */ \ No newline at end of file diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 74b7728fa..01354cf05 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -613,4 +613,6 @@ class CI_FTP { } // END FTP Class -?> \ No newline at end of file + +/* End of file Ftp.php */ +/* Location: ./system/libraries/Ftp.php */ \ No newline at end of file diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index a41320c5e..d7637c39e 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -221,4 +221,6 @@ class CI_Hooks { } // END CI_Hooks class -?> \ No newline at end of file + +/* End of file Hooks.php */ +/* Location: ./system/libraries/Hooks.php */ \ No newline at end of file diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index c236e391e..0750b6454 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1533,4 +1533,6 @@ class CI_Image_lib { } // END Image_lib Class -?> \ No newline at end of file + +/* End of file Image_lib.php */ +/* Location: ./system/libraries/Image_lib.php */ \ No newline at end of file diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 8a0478be2..ee7e9ad31 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -923,4 +923,6 @@ class CI_Input { } // END Input class -?> \ No newline at end of file + +/* End of file Input.php */ +/* Location: ./system/libraries/Input.php */ \ No newline at end of file diff --git a/system/libraries/Language.php b/system/libraries/Language.php index a8e6366bb..aacc6c1f9 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -118,4 +118,6 @@ class CI_Language { } // END Language Class -?> \ No newline at end of file + +/* End of file Language.php */ +/* Location: ./system/libraries/Language.php */ \ No newline at end of file diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 5966aebf6..687598096 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -1027,4 +1027,6 @@ class CI_Loader { } } -?> \ No newline at end of file + +/* End of file Loader.php */ +/* Location: ./system/libraries/Loader.php */ \ No newline at end of file diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 26757ba50..22b505906 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -115,4 +115,6 @@ class CI_Log { } // END Log Class -?> \ No newline at end of file + +/* End of file Log.php */ +/* Location: ./system/libraries/Log.php */ \ No newline at end of file diff --git a/system/libraries/Model.php b/system/libraries/Model.php index e87d6045c..1e7b9a184 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -79,4 +79,6 @@ class Model { } // END Model Class -?> \ No newline at end of file + +/* End of file Model.php */ +/* Location: ./system/libraries/Model.php */ \ No newline at end of file diff --git a/system/libraries/Output.php b/system/libraries/Output.php index d513a1279..f76550e2b 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -383,4 +383,6 @@ class CI_Output { } // END Output Class -?> \ No newline at end of file + +/* End of file Output.php */ +/* Location: ./system/libraries/Output.php */ \ No newline at end of file diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index e1212035a..c3f6bd89c 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -215,4 +215,6 @@ class CI_Pagination { } } // END Pagination Class -?> \ No newline at end of file + +/* End of file Pagination.php */ +/* Location: ./system/libraries/Pagination.php */ \ No newline at end of file diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 417e04f29..f260b2e19 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -168,4 +168,6 @@ class CI_Parser { } // END Parser Class -?> \ No newline at end of file + +/* End of file Parser.php */ +/* Location: ./system/libraries/Parser.php */ \ No newline at end of file diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 807c1aff6..fe4fb6d62 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -340,4 +340,6 @@ class CI_Profiler { } // END CI_Profiler class -?> \ No newline at end of file + +/* End of file Profiler.php */ +/* Location: ./system/libraries/Profiler.php */ \ No newline at end of file diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 6bb85518f..3b2520dce 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -374,4 +374,6 @@ class CI_Router { } // END Router Class -?> \ No newline at end of file + +/* End of file Router.php */ +/* Location: ./system/libraries/Router.php */ \ No newline at end of file diff --git a/system/libraries/Session.php b/system/libraries/Session.php index d4fdd3ac7..ce1b75e66 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -649,4 +649,6 @@ class CI_Session { } // END Session Class -?> \ No newline at end of file + +/* End of file Session.php */ +/* Location: ./system/libraries/Session.php */ \ No newline at end of file diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index 6bb891177..a7b9b98d3 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -246,4 +246,6 @@ class CI_SHA { } } // END CI_SHA -?> \ No newline at end of file + +/* End of file Sha1.php */ +/* Location: ./system/libraries/Sha1.php */ \ No newline at end of file diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 01b490a5d..f4df02e76 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -435,4 +435,6 @@ class CI_Table { } -?> \ No newline at end of file + +/* End of file Table.php */ +/* Location: ./system/libraries/Table.php */ \ No newline at end of file diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index 3e1c20210..41ac5fca8 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -545,4 +545,6 @@ class CI_Trackback { } // END Trackback Class -?> \ No newline at end of file + +/* End of file Trackback.php */ +/* Location: ./system/libraries/Trackback.php */ \ No newline at end of file diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 8ee888a2e..26a7b4a33 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -586,4 +586,6 @@ class CI_URI { } // END URI Class -?> \ No newline at end of file + +/* End of file URI.php */ +/* Location: ./system/libraries/URI.php */ \ No newline at end of file diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 3cdf45f12..2fb2bbd32 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -340,4 +340,6 @@ function is_false($test) return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; } -?> \ No newline at end of file + +/* End of file Unit_test.php */ +/* Location: ./system/libraries/Unit_test.php */ \ No newline at end of file diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 317cf9560..07cbd924b 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -875,4 +875,6 @@ class CI_Upload { } // END Upload Class -?> \ No newline at end of file + +/* End of file Upload.php */ +/* Location: ./system/libraries/Upload.php */ \ No newline at end of file diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index dd60a56a1..ee1839277 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -497,4 +497,6 @@ class CI_User_agent { } -?> \ No newline at end of file + +/* End of file User_agent.php */ +/* Location: ./system/libraries/User_agent.php */ \ No newline at end of file diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index f628d8612..8796d7ffb 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -805,4 +805,6 @@ class CI_Validation { } // END Validation Class -?> \ No newline at end of file + +/* End of file Validation.php */ +/* Location: ./system/libraries/Validation.php */ \ No newline at end of file diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index f8ad01714..b8ac3bea7 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -1416,4 +1416,6 @@ class XML_RPC_Values extends CI_Xmlrpc } // END XML_RPC_Values Class -?> \ No newline at end of file + +/* End of file Xmlrpc.php */ +/* Location: ./system/libraries/Xmlrpc.php */ \ No newline at end of file diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 7a4bc825e..754b8ae26 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -531,4 +531,6 @@ class CI_Xmlrpcs extends CI_Xmlrpc } // END XML_RPC_Server class -?> \ No newline at end of file + +/* End of file Xmlrpcs.php */ +/* Location: ./system/libraries/Xmlrpcs.php */ \ No newline at end of file diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index f7f47ab42..5a24e4057 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -374,4 +374,6 @@ class CI_Zip { } } -?> \ No newline at end of file + +/* End of file Zip.php */ +/* Location: ./system/libraries/Zip.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 500fa6c3a934ac9d9f0a5c1ded5c00ad1709187f Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 12 May 2008 15:08:35 +0000 Subject: changed overlay_watermark() to check for an alpha value before applying the image to help support PNG-24s with alpha transparency http://codeigniter.com/bug_tracker/bug/4506/ --- system/libraries/Image_lib.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 0750b6454..4017afb13 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -943,10 +943,23 @@ class CI_Image_lib { { @imagealphablending($src_img, TRUE); } - - // Set RGB values for text and shadow - imagecolortransparent($wm_img, imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp)); - imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity); + + // Set RGB values for text and shadow + $rgba = imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp); + $alpha = ($rgba & 0x7F000000) >> 24; + + // make a best guess as to whether we're dealing with an image with alpha transparency or no/binary transparency + if ($alpha > 0) + { + // copy the image directly, the image's alpha transparency being the sole determinant of blending + imagecopy($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height); + } + else + { + // set our RGB value from above to be transparent and merge the images with the specified opacity + imagecolortransparent($wm_img, imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp)); + imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity); + } // Output the image if ($this->dynamic_output == TRUE) @@ -1533,6 +1546,6 @@ class CI_Image_lib { } // END Image_lib Class - -/* End of file Image_lib.php */ + +/* End of file Image_lib.php */ /* Location: ./system/libraries/Image_lib.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d56743b0d65603ebd556a05f740d5bd5da05101b Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 12 May 2008 16:17:58 +0000 Subject: fixed a bug that would lead to a PHP notice error of array to string conversion in prep_for_form() http://codeigniter.com/bug_tracker/bug/4425/ --- system/libraries/Validation.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 8796d7ffb..a0f038c02 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -726,6 +726,8 @@ class CI_Validation { { $data[$key] = $this->prep_for_form($val); } + + return $data; } if ($this->_safe_form_data == FALSE OR $data == '') @@ -805,6 +807,6 @@ class CI_Validation { } // END Validation Class - -/* End of file Validation.php */ + +/* End of file Validation.php */ /* Location: ./system/libraries/Validation.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c14968d0a2d6f25cdaf333b8f697991177387bed Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 12 May 2008 17:19:51 +0000 Subject: changed $xmlrpcDateTime property to all lowercase 'datetime.iso8601' so it can be recognized as a valid XML-RPC type http://codeigniter.com/bug_tracker/bug/4153/ --- system/libraries/Xmlrpc.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index b8ac3bea7..32d739689 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -38,7 +38,7 @@ class CI_Xmlrpc { var $xmlrpcBoolean = 'boolean'; var $xmlrpcDouble = 'double'; var $xmlrpcString = 'string'; - var $xmlrpcDateTime = 'dateTime.iso8601'; + var $xmlrpcDateTime = 'datetime.iso8601'; var $xmlrpcBase64 = 'base64'; var $xmlrpcArray = 'array'; var $xmlrpcStruct = 'struct'; @@ -1416,6 +1416,6 @@ class XML_RPC_Values extends CI_Xmlrpc } // END XML_RPC_Values Class - -/* End of file Xmlrpc.php */ + +/* End of file Xmlrpc.php */ /* Location: ./system/libraries/Xmlrpc.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 53437de1f94dd4c0ab270f0c6d2309344d323d9e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 12 May 2008 18:07:08 +0000 Subject: Added protection in xss_clean() for GET variables in URLs http://codeigniter.com/bug_tracker/bug/4167/ --- system/libraries/Input.php | 58 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index ee7e9ad31..9b012d320 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -28,6 +28,7 @@ */ class CI_Input { var $use_xss_clean = FALSE; + var $xss_hash = ''; var $ip_address = FALSE; var $user_agent = FALSE; var $allow_get_array = FALSE; @@ -530,7 +531,21 @@ class CI_Input { * @return string */ function xss_clean($str) - { + { + /* + * Is the string an array? + * + */ + if (is_array($str)) + { + while (list($key) = each($str)) + { + $str[$key] = $this->xss_clean($str[$key]); + } + + return $str; + } + /* * Remove Null Characters * @@ -541,6 +556,14 @@ class CI_Input { $str = preg_replace('/\0+/', '', $str); $str = preg_replace('/(\\\\0)+/', '', $str); + /* + * Protect GET variables in URLs + */ + + // 901119URL5918AMP18930PROTECT8198 + + $str = preg_replace('|\&([a-z\_0-9]+)\=([a-z\_0-9]+)|i', $this->xss_hash()."\\1=\\2", $str); + /* * Validate standard character entities * @@ -558,6 +581,12 @@ class CI_Input { */ $str = preg_replace('#(&\#x?)([0-9A-F]+);?#i',"\\1\\2;",$str); + /* + * Un-Protect GET variables in URLs + */ + + $str = str_replace($this->xss_hash(), '&', $str); + /* * URL Decode * @@ -796,6 +825,29 @@ class CI_Input { // -------------------------------------------------------------------- + /** + * Random Hash for protecting URLs + * + * @access public + * @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; + } + + // -------------------------------------------------------------------- + /** * JS Link Removal * @@ -923,6 +975,6 @@ class CI_Input { } // END Input class - -/* End of file Input.php */ + +/* End of file Input.php */ /* Location: ./system/libraries/Input.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 15dcf49a0ea6895cbf009dc15277858cfdd422ef Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 12 May 2008 21:37:04 +0000 Subject: removed an ereg from config added a qualifier to a str_replace for \t in Input changed substr to strncmp in Codeigniter.php and directory_map function added braces in an if statement of unit test Removed "scripts" from the auto-load search path. Scripts were deprecated in Version 1.4.1 (September 21, 2006). If you still need to use them for legacy reasons, they must now be manually loaded in each Controller. --- system/libraries/Config.php | 11 +- system/libraries/Input.php | 222 +++++++++++++++++++++-------------------- system/libraries/Loader.php | 8 +- system/libraries/Unit_test.php | 8 +- 4 files changed, 125 insertions(+), 124 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Config.php b/system/libraries/Config.php index f3ae76390..b1a9defe0 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -172,12 +172,9 @@ class CI_Config { $pref = $this->config[$item]; - if ($pref != '') + if ($pref != '' && substr($pref, -1) != '/') { - if (ereg("/$", $pref) === FALSE) - { - $pref .= '/'; - } + $pref .= '/'; } return $pref; @@ -242,6 +239,6 @@ class CI_Config { } // END CI_Config class - -/* End of file Config.php */ + +/* End of file Config.php */ /* Location: ./system/libraries/Config.php */ \ No newline at end of file diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 9b012d320..e3515661d 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -32,7 +32,7 @@ class CI_Input { var $ip_address = FALSE; var $user_agent = FALSE; var $allow_get_array = FALSE; - + /** * Constructor * @@ -40,19 +40,19 @@ class CI_Input { * and whether to allow the $_GET array * * @access public - */ + */ function CI_Input() - { + { log_message('debug', "Input Class Initialized"); - + $CFG =& load_class('Config'); $this->use_xss_clean = ($CFG->item('global_xss_filtering') === TRUE) ? TRUE : FALSE; - $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; + $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; $this->_sanitize_globals(); } - + // -------------------------------------------------------------------- - + /** * Sanitize Globals * @@ -72,7 +72,7 @@ class CI_Input { // Would kind of be "wrong" to unset any of these GLOBALS $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 security. // This is effectively the same as register_globals = off foreach (array($_GET, $_POST, $_COOKIE, $_SERVER, $_FILES, $_ENV, (isset($_SESSION) && is_array($_SESSION)) ? $_SESSION : array()) as $global) @@ -92,7 +92,7 @@ class CI_Input { { unset($GLOBALS[$key]); } - + if (is_array($val)) { foreach($val as $k => $v) @@ -103,7 +103,7 @@ class CI_Input { } } } - } + } } } @@ -122,30 +122,30 @@ class CI_Input { } } } - + // Clean $_POST Data if (is_array($_POST) AND count($_POST) > 0) { foreach($_POST as $key => $val) - { + { $_POST[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); - } + } } - + // Clean $_COOKIE Data if (is_array($_COOKIE) AND count($_COOKIE) > 0) { foreach($_COOKIE as $key => $val) - { + { $_COOKIE[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); - } + } } - + log_message('debug', "Global POST and COOKIE data sanitized"); - } - + } + // -------------------------------------------------------------------- - + /** * Clean Input Data * @@ -155,7 +155,7 @@ class CI_Input { * @access private * @param string * @return string - */ + */ function _clean_input_data($str) { if (is_array($str)) @@ -167,25 +167,25 @@ class CI_Input { } return $new_array; } - + // We strip slashes if magic quotes is on to keep things consistent if (get_magic_quotes_gpc()) { $str = stripslashes($str); } - + // Should we filter the input data? if ($this->use_xss_clean === TRUE) { $str = $this->xss_clean($str); } - + // Standardize newlines return preg_replace("/\015\012|\015|\012/", "\n", $str); } - + // -------------------------------------------------------------------- - + /** * Clean Keys * @@ -198,7 +198,7 @@ class CI_Input { * @return string */ function _clean_input_keys($str) - { + { if (! preg_match("/^[a-z0-9:_\/-]+$/i", $str)) { exit('Disallowed Key Characters.'); @@ -208,7 +208,7 @@ class CI_Input { } // -------------------------------------------------------------------- - + /** * Fetch an item from the GET array * @@ -218,7 +218,7 @@ class CI_Input { * @return string */ function get($index = '', $xss_clean = FALSE) - { + { if (! isset($_GET[$index])) { return FALSE; @@ -229,7 +229,7 @@ class CI_Input { if (is_array($_GET[$index])) { foreach($_GET[$index] as $key => $val) - { + { $_GET[$index][$key] = $this->xss_clean($val); } } @@ -241,9 +241,9 @@ class CI_Input { return $_GET[$index]; } - + // -------------------------------------------------------------------- - + /** * Fetch an item from the POST array * @@ -253,7 +253,7 @@ class CI_Input { * @return string */ function post($index = '', $xss_clean = FALSE) - { + { if (! isset($_POST[$index])) { return FALSE; @@ -264,7 +264,7 @@ class CI_Input { if (is_array($_POST[$index])) { foreach($_POST[$index] as $key => $val) - { + { $_POST[$index][$key] = $this->xss_clean($val); } } @@ -276,9 +276,9 @@ class CI_Input { return $_POST[$index]; } - + // -------------------------------------------------------------------- - + /** * Fetch an item from the COOKIE array * @@ -303,7 +303,7 @@ class CI_Input { { $cookie[$key] = $this->xss_clean($val); } - + return $cookie; } else @@ -318,7 +318,7 @@ class CI_Input { } // -------------------------------------------------------------------- - + /** * Fetch an item from the SERVER array * @@ -328,7 +328,7 @@ class CI_Input { * @return string */ function server($index = '', $xss_clean = FALSE) - { + { if (! isset($_SERVER[$index])) { return FALSE; @@ -338,12 +338,12 @@ class CI_Input { { return $this->xss_clean($_SERVER[$index]); } - + return $_SERVER[$index]; } - + // -------------------------------------------------------------------- - + /** * Fetch the IP Address * @@ -356,7 +356,7 @@ class CI_Input { { return $this->ip_address; } - + if ($this->server('REMOTE_ADDR') AND $this->server('HTTP_CLIENT_IP')) { $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; @@ -373,29 +373,29 @@ class CI_Input { { $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; } - + if ($this->ip_address === FALSE) { $this->ip_address = '0.0.0.0'; return $this->ip_address; } - + if (strstr($this->ip_address, ',')) { $x = explode(',', $this->ip_address); $this->ip_address = end($x); } - + if (! $this->valid_ip($this->ip_address)) { $this->ip_address = '0.0.0.0'; } - + return $this->ip_address; } - + // -------------------------------------------------------------------- - + /** * Validate IP Address * @@ -408,7 +408,7 @@ class CI_Input { function valid_ip($ip) { $ip_segments = explode('.', $ip); - + // Always 4 segments needed if (count($ip_segments) != 4) { @@ -429,12 +429,12 @@ class CI_Input { return FALSE; } } - + return TRUE; } - + // -------------------------------------------------------------------- - + /** * User Agent * @@ -447,14 +447,14 @@ class CI_Input { { return $this->user_agent; } - + $this->user_agent = (! isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT']; - + return $this->user_agent; } - + // -------------------------------------------------------------------- - + /** * Filename Security * @@ -497,13 +497,13 @@ class CI_Input { "%3f", // ? "%3b", // ; "%3d" // = - ); - - return stripslashes(str_replace($bad, '', $str)); + ); + + return stripslashes(str_replace($bad, '', $str)); } - + // -------------------------------------------------------------------- - + /** * XSS Clean * @@ -542,10 +542,10 @@ class CI_Input { { $str[$key] = $this->xss_clean($str[$key]); } - + return $str; } - + /* * Remove Null Characters * @@ -572,7 +572,7 @@ class CI_Input { * */ $str = preg_replace('#(&\#?[0-9a-z]+)[\x00-\x20]*;?#i', "\\1;", $str); - + /* * Validate UTF16 two byte encoding (x00) * @@ -586,7 +586,7 @@ class CI_Input { */ $str = str_replace($this->xss_hash(), '&', $str); - + /* * URL Decode * @@ -596,9 +596,9 @@ class CI_Input { * * Note: Use rawurldecode() so it does not remove plus signs * - */ + */ $str = rawurldecode($str); - + /* * Convert character entities to ASCII * @@ -607,15 +607,15 @@ class CI_Input { * these are the ones that will pose security problems. * */ - + $str = preg_replace_callback("/[a-z]+=([\'\"]).*?\\1/si", array($this, '_attribute_conversion'), $str); $str = preg_replace_callback("/<([\w]+)[^>]*>/si", array($this, '_html_entity_decode_callback'), $str); /* - + Old Code that when modified to use preg_replace()'s above became more efficient memory-wise - + if (preg_match_all("/[a-z]+=([\'\"]).*?\\1/si", $str, $matches)) { for ($i = 0; $i < count($matches[0]); $i++) @@ -639,7 +639,7 @@ class CI_Input { } } */ - + /* * Convert all tabs to spaces * @@ -649,12 +649,14 @@ class CI_Input { * so we use str_replace. * */ - - $str = str_replace("\t", " ", $str); + + if (strpos($str, "\t") !== FALSE) { + $str = str_replace("\t", " ", $str); + } /* * Not Allowed Under Any Conditions - */ + */ $bad = array( 'document.cookie' => '[removed]', 'document.write' => '[removed]', @@ -677,12 +679,12 @@ class CI_Input { "expression\s*\(" => '[removed]', // CSS and IE "Redirect\s+302" => '[removed]' ); - + foreach ($bad as $key => $val) { $str = preg_replace("#".$key."#i", $val, $str); } - + /* * Makes PHP tags safe * @@ -692,16 +694,16 @@ class CI_Input { * * But it doesn't seem to pose a problem. * - */ + */ $str = str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); - + /* * Compact any exploded words * * This corrects words like: j a v a s c r i p t * These words are compacted back to their correct state. * - */ + */ $words = array('javascript', 'expression', 'vbscript', 'script', 'applet', 'alert', 'document', 'write', 'cookie', 'window'); foreach ($words as $word) { @@ -710,31 +712,31 @@ class CI_Input { { $temp .= substr($word, $i, 1)."\s*"; } - + // We only want to do this when it is followed by a non-word character // That way valid stuff like "dealer to" does not become "dealerto" $str = preg_replace('#('.substr($temp, 0, -3).')(\W)#ise', "preg_replace('/\s+/s', '', '\\1').'\\2'", $str); } - + /* * Remove disallowed Javascript in links or img tags */ do { $original = $str; - + if ((version_compare(PHP_VERSION, '5.0', '>=') === TRUE && stripos($str, '') !== FALSE) OR preg_match("/<\/a>/i", $str)) { $str = preg_replace_callback("##si", array($this, '_js_link_removal'), $str); } - + if ((version_compare(PHP_VERSION, '5.0', '>=') === TRUE && stripos($str, '#si", array($this, '_js_img_removal'), $str); } - + if ((version_compare(PHP_VERSION, '5.0', '>=') === TRUE && (stripos($str, 'script') !== FALSE OR stripos($str, 'xss') !== FALSE)) OR preg_match("/(script|xss)/i", $str)) { @@ -742,7 +744,7 @@ class CI_Input { } } while($original != $str); - + unset($original); /* @@ -752,10 +754,10 @@ class CI_Input { * the event handler and anything up to the closing >, * but it's unlikely to be a problem. * - */ + */ $event_handlers = array('onblur','onchange','onclick','onfocus','onload','onmouseover','onmouseup','onmousedown','onselect','onsubmit','onunload','onkeypress','onkeydown','onkeyup','onresize', 'xmlns'); $str = preg_replace("#<([^>]+)(".implode('|', $event_handlers).")([^>]*)>#iU", "<\\1\\2\\3>", $str); - + /* * Sanitize naughty HTML elements * @@ -765,9 +767,9 @@ class CI_Input { * So this: * Becomes: <blink> * - */ + */ $str = preg_replace('#<(/*\s*)(alert|applet|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|layer|link|meta|object|plaintext|style|script|textarea|title|xml|xss)([^>]*)>#is', "<\\1\\2\\3>", $str); - + /* * Sanitize naughty scripting elements * @@ -782,14 +784,14 @@ class CI_Input { * */ $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 * * This adds a bit of extra precaution in case * something got through the above filters * - */ + */ $bad = array( 'document.cookie' => '[removed]', 'document.write' => '[removed]', @@ -812,19 +814,19 @@ class CI_Input { "expression\s*\(" => '[removed]', // CSS and IE "Redirect\s+302" => '[removed]' ); - + foreach ($bad as $key => $val) { $str = preg_replace("#".$key."#i", $val, $str); } - - + + log_message('debug', "XSS Filtering completed"); return $str; } // -------------------------------------------------------------------- - + /** * Random Hash for protecting URLs * @@ -832,22 +834,22 @@ class CI_Input { * @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; } // -------------------------------------------------------------------- - + /** * JS Link Removal * @@ -864,7 +866,7 @@ class CI_Input { { return preg_replace("#.*?#si", "", $match[0]); } - + /** * JS Image Removal * @@ -883,7 +885,7 @@ class CI_Input { } // -------------------------------------------------------------------- - + /** * Attribute Conversion * @@ -897,7 +899,7 @@ class CI_Input { { return str_replace('>', '<', $match[0]); } - + // -------------------------------------------------------------------- /** @@ -918,7 +920,7 @@ class CI_Input { } // -------------------------------------------------------------------- - + /** * HTML Entities Decode * @@ -937,7 +939,7 @@ class CI_Input { /* ------------------------------------------------- /* Replacement for html_entity_decode() /* -------------------------------------------------*/ - + /* NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the character set, and the PHP developers said they were not back porting the @@ -946,30 +948,30 @@ class CI_Input { function _html_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 version_compare(phpversion(), '5.0.0', '>='))) { $str = html_entity_decode($str, ENT_COMPAT, $charset); $str = preg_replace('~&#x([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-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; } diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 687598096..b5a69bbdd 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -905,8 +905,8 @@ class CI_Loader { } } - // Autoload plugins, helpers, scripts and languages - foreach (array('helper', 'plugin', 'script', 'language') as $type) + // Autoload plugins, helpers and languages + foreach (array('helper', 'plugin', 'language') as $type) { if (isset($autoload[$type]) AND count($autoload[$type]) > 0) { @@ -1027,6 +1027,6 @@ class CI_Loader { } } - -/* End of file Loader.php */ + +/* End of file Loader.php */ /* Location: ./system/libraries/Loader.php */ \ No newline at end of file diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 2fb2bbd32..bfa6d5dc5 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -55,8 +55,10 @@ class CI_Unit_test { function run($test, $expected = TRUE, $test_name = 'undefined') { if ($this->active == FALSE) + { return FALSE; - + } + if (in_array($expected, array('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); @@ -340,6 +342,6 @@ function is_false($test) return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; } - -/* End of file Unit_test.php */ + +/* End of file Unit_test.php */ /* Location: ./system/libraries/Unit_test.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 751506e7dd58dd1c257c7170b61fe1f439e25021 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 12 May 2008 21:43:54 +0000 Subject: fixed a misspelling in the Input library of CDATA --- system/libraries/Input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index e3515661d..f98757947 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -666,7 +666,7 @@ class CI_Input { '-moz-binding' => '[removed]', '' => '-->', - ' '<![CDATA[' + ' '<![CDATA[' ); foreach ($bad as $key => $val) -- cgit v1.2.3-24-g4f1b From 20d2405051bae7da50299df94c6bcdd9d55e86a2 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 12 May 2008 22:12:11 +0000 Subject: substr checks swapped out with strncmp { braces } added around if and for statements --- system/libraries/Email.php | 88 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 72 insertions(+), 16 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index d32928a66..b7d9d2ebf 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -168,12 +168,16 @@ class CI_Email { function from($from, $name = '') { if (preg_match( '/\<(.*)\>/', $from, $match)) + { $from = $match['1']; + } if ($this->validate) + { $this->validate_email($this->_str_to_array($from)); + } - if ($name != '' && substr($name, 0, 1) != '"') + if ($name != '' && strncmp($name, '"', 1) != 0) { $name = '"'.$name.'"'; } @@ -195,17 +199,21 @@ class CI_Email { function reply_to($replyto, $name = '') { if (preg_match( '/\<(.*)\>/', $replyto, $match)) + { $replyto = $match['1']; + } if ($this->validate) + { $this->validate_email($this->_str_to_array($replyto)); + } if ($name == '') { $name = $replyto; } - if (substr($name, 0, 1) != '"') + if (strncmp($name, '"', 1) != 0) { $name = '"'.$name.'"'; } @@ -229,10 +237,14 @@ class CI_Email { $to = $this->clean_email($to); if ($this->validate) + { $this->validate_email($to); + } if ($this->_get_protocol() != 'mail') + { $this->_set_header('To', implode(", ", $to)); + } switch ($this->_get_protocol()) { @@ -265,7 +277,9 @@ class CI_Email { $this->_set_header('Cc', implode(", ", $cc)); if ($this->_get_protocol() == "smtp") + { $this->_cc_array = $cc; + } } // -------------------------------------------------------------------- @@ -290,12 +304,18 @@ class CI_Email { $bcc = $this->clean_email($bcc); if ($this->validate) + { $this->validate_email($bcc); + } if (($this->_get_protocol() == "smtp") OR ($this->bcc_batch_mode && count($bcc) > $this->bcc_batch_size)) + { $this->_bcc_array = $bcc; + } else + { $this->_set_header('Bcc', implode(", ", $bcc)); + } } // -------------------------------------------------------------------- @@ -554,7 +574,9 @@ class CI_Email { $this->protocol = (! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol; if ($return == TRUE) + { return $this->protocol; + } } // -------------------------------------------------------------------- @@ -594,16 +616,22 @@ class CI_Email { */ function _get_content_type() { - if ($this->mailtype == 'html' && count($this->_attach_name) == 0) + if ($this->mailtype == 'html' && count($this->_attach_name) == 0) + { return 'html'; - + } elseif ($this->mailtype == 'html' && count($this->_attach_name) > 0) + { return 'html-attach'; - + } elseif ($this->mailtype == 'text' && count($this->_attach_name) > 0) + { return 'plain-attach'; - - else return 'plain'; + } + else + { + return 'plain'; + } } // -------------------------------------------------------------------- @@ -617,7 +645,7 @@ class CI_Email { function _set_date() { $timezone = date("Z"); - $operator = (substr($timezone, 0, 1) == '-') ? '-' : '+'; + $operator = (strncmp($timezone, '-', 1) == 0) ? '-' : '+'; $timezone = abs($timezone); $timezone = floor($timezone/3600) * 100 + ($timezone % 3600 ) / 60; @@ -692,9 +720,13 @@ class CI_Email { if (! is_array($email)) { if (preg_match('/\<(.*)\>/', $email, $match)) + { return $match['1']; + } else + { return $email; + } } $clean_email = array(); @@ -752,7 +784,9 @@ class CI_Email { $n = ""; for ($x = 1; $x <= $i; $x ++) + { $n .= "\n"; + } $body = str_replace($n, "\n\n", $body); } @@ -823,7 +857,7 @@ class CI_Email { } // Trim the word down - $temp .= substr($line, 0, $charlim-1); + $temp .= ($line, 0, $charlim-1); $line = substr($line, $charlim-1); } @@ -1213,9 +1247,13 @@ class CI_Email { $this->_build_message(); if (! $this->_spool_email()) + { return FALSE; + } else + { return TRUE; + } } // -------------------------------------------------------------------- @@ -1238,7 +1276,9 @@ class CI_Email { for ($i = 0; $i < count($this->_bcc_array); $i++) { if (isset($this->_bcc_array[$i])) + { $set .= ", ".$this->_bcc_array[$i]; + } if ($i == $float) { @@ -1248,7 +1288,9 @@ class CI_Email { } if ($i == count($this->_bcc_array)-1) - $chunk[] = substr($set, 1); + { + $chunk[] = substr($set, 1); + } } for ($i = 0; $i < count($chunk); $i++) @@ -1260,9 +1302,13 @@ class CI_Email { $bcc = $this->clean_email($bcc); if ($this->protocol != 'smtp') + { $this->_set_header('Bcc', implode(", ", $bcc)); + } else + { $this->_bcc_array = $bcc; + } $this->_build_message(); $this->_spool_email(); @@ -1446,7 +1492,7 @@ class CI_Email { $this->_set_error_message($reply); - if (substr($reply, 0, 3) != '250') + if (strncmp($reply, '250', 3) != 0) { $this->_set_error_message('email_smtp_error', $reply); return FALSE; @@ -1543,7 +1589,9 @@ class CI_Email { } if ($cmd == 'quit') + { fclose($this->_smtp_connect); + } return TRUE; } @@ -1559,7 +1607,9 @@ class CI_Email { function _smtp_authenticate() { if (! $this->_smtp_auth) + { return TRUE; + } if ($this->smtp_user == "" AND $this->smtp_pass == "") { @@ -1571,7 +1621,7 @@ class CI_Email { $reply = $this->_get_smtp_data(); - if (substr($reply, 0, 3) != '334') + if (strncmp($reply, '334', 3) != 0) { $this->_set_error_message('email_failed_smtp_login', $reply); return FALSE; @@ -1581,7 +1631,7 @@ class CI_Email { $reply = $this->_get_smtp_data(); - if (substr($reply, 0, 3) != '334') + if (strncmp($reply, '334', 3) != 0) { $this->_set_error_message('email_smtp_auth_un', $reply); return FALSE; @@ -1591,7 +1641,7 @@ class CI_Email { $reply = $this->_get_smtp_data(); - if (substr($reply, 0, 3) != '235') + if (strncmp($reply, '235', 3) != 0) { $this->_set_error_message('email_smtp_auth_pw', $reply); return FALSE; @@ -1616,7 +1666,9 @@ class CI_Email { return FALSE; } else + { return TRUE; + } } // -------------------------------------------------------------------- @@ -1636,7 +1688,9 @@ class CI_Email { $data .= $str; if (substr($str, 3, 1) == " ") + { break; + } } return $data; @@ -1686,7 +1740,9 @@ class CI_Email { } if (! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $this->_IP)) + { $this->_IP = '0.0.0.0'; + } unset($cip); unset($rip); @@ -1848,6 +1904,6 @@ class CI_Email { } // END CI_Email class - -/* End of file Email.php */ + +/* End of file Email.php */ /* Location: ./system/libraries/Email.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 62bd43029cbd290d684ee32a8387f66ccad3a64a Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 12 May 2008 22:19:03 +0000 Subject: preg_split changed to explode --- system/libraries/Email.php | 330 ++++++++++++++++++++++----------------------- 1 file changed, 165 insertions(+), 165 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index b7d9d2ebf..ebb969288 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -83,13 +83,13 @@ class CI_Email { * The constructor can be passed an array of config values */ function CI_Email($config = array()) - { + { if (count($config) > 0) { $this->initialize($config); } - $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; + $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE; log_message('debug', "Email Class Initialized"); @@ -112,7 +112,7 @@ class CI_Email { if (isset($this->$key)) { $method = 'set_'.$key; - + if (method_exists($this, $method)) { $this->$method($val); @@ -120,7 +120,7 @@ class CI_Email { else { $this->$key = $val; - } + } } } } @@ -143,16 +143,16 @@ class CI_Email { $this->_recipients = array(); $this->_headers = array(); $this->_debug_msg = array(); - - $this->_set_header('User-Agent', $this->useragent); + + $this->_set_header('User-Agent', $this->useragent); $this->_set_header('Date', $this->_set_date()); - + if ($clear_attachments !== FALSE) { $this->_attach_name = array(); $this->_attach_type = array(); $this->_attach_disp = array(); - } + } } // -------------------------------------------------------------------- @@ -176,7 +176,7 @@ class CI_Email { { $this->validate_email($this->_str_to_array($from)); } - + if ($name != '' && strncmp($name, '"', 1) != 0) { $name = '"'.$name.'"'; @@ -240,7 +240,7 @@ class CI_Email { { $this->validate_email($to); } - + if ($this->_get_protocol() != 'mail') { $this->_set_header('To', implode(", ", $to)); @@ -275,7 +275,7 @@ class CI_Email { $this->validate_email($cc); $this->_set_header('Cc', implode(", ", $cc)); - + if ($this->_get_protocol() == "smtp") { $this->_cc_array = $cc; @@ -302,7 +302,7 @@ class CI_Email { $bcc = $this->_str_to_array($bcc); $bcc = $this->clean_email($bcc); - + if ($this->validate) { $this->validate_email($bcc); @@ -331,8 +331,8 @@ class CI_Email { { $subject = preg_replace("/(\r\n)|(\r)|(\n)/", "", $subject); $subject = preg_replace("/(\t)/", " ", $subject); - - $this->_set_header('Subject', trim($subject)); + + $this->_set_header('Subject', trim($subject)); } // -------------------------------------------------------------------- @@ -357,9 +357,9 @@ class CI_Email { * @access public * @param string * @return string - */ + */ function attach($filename, $disposition = 'attachment') - { + { $this->_attach_name[] = $filename; $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename)))); $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters @@ -398,7 +398,7 @@ class CI_Email { $email = preg_split('/[\s,]/', $email, -1, PREG_SPLIT_NO_EMPTY); } else - { + { $email = trim($email); settype($email, "array"); } @@ -572,7 +572,7 @@ class CI_Email { { $this->protocol = strtolower($this->protocol); $this->protocol = (! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol; - + if ($return == TRUE) { return $this->protocol; @@ -589,9 +589,9 @@ class CI_Email { * @return string */ function _get_encoding($return = TRUE) - { + { $this->_encoding = (! in_array($this->_encoding, $this->_bit_depths)) ? '8bit' : $this->_encoding; - + foreach ($this->_base_charsets as $charset) { if (strncmp($charset, $this->charset, strlen($charset)) == 0) @@ -599,10 +599,10 @@ class CI_Email { $this->_encoding = '7bit'; } } - + if ($return == TRUE) { - return $this->_encoding; + return $this->_encoding; } } @@ -622,7 +622,7 @@ class CI_Email { } elseif ($this->mailtype == 'html' && count($this->_attach_name) > 0) { - return 'html-attach'; + return 'html-attach'; } elseif ($this->mailtype == 'text' && count($this->_attach_name) > 0) { @@ -648,7 +648,7 @@ class CI_Email { $operator = (strncmp($timezone, '-', 1) == 0) ? '-' : '+'; $timezone = abs($timezone); $timezone = floor($timezone/3600) * 100 + ($timezone % 3600 ) / 60; - + return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone); } @@ -678,7 +678,7 @@ class CI_Email { { if (! is_array($email)) { - $this->_set_error_message('email_must_be_array'); + $this->_set_error_message('email_must_be_array'); return FALSE; } @@ -686,7 +686,7 @@ class CI_Email { { if (! $this->valid_email($val)) { - $this->_set_error_message('email_invalid_address', $val); + $this->_set_error_message('email_invalid_address', $val); return FALSE; } } @@ -728,21 +728,21 @@ class CI_Email { return $email; } } - + $clean_email = array(); foreach ($email as $addy) { if (preg_match( '/\<(.*)\>/', $addy, $match)) { - $clean_email[] = $match['1']; + $clean_email[] = $match['1']; } else { - $clean_email[] = $addy; + $clean_email[] = $addy; } } - + return $clean_email; } @@ -765,7 +765,7 @@ class CI_Email { { return $this->word_wrap($this->alt_message, '76'); } - + if (preg_match('/\(.*)\<\/body\>/si', $this->_body, $match)) { $body = $match['1']; @@ -774,20 +774,20 @@ class CI_Email { { $body = $this->_body; } - + $body = trim(strip_tags($body)); $body = preg_replace( '# '.$message. ' '.$filepath.' '.$line, TRUE); } @@ -115,7 +115,7 @@ class CI_Exceptions { */ function show_error($heading, $message, $template = 'error_general') { - $message = '

'.implode('

', (! is_array($message)) ? array($message) : $message).'

'; + $message = '

'.implode('

', ( ! is_array($message)) ? array($message) : $message).'

'; if (ob_get_level() > $this->ob_level + 1) { @@ -142,7 +142,7 @@ class CI_Exceptions { */ function show_php_error($severity, $message, $filepath, $line) { - $severity = (! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; + $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; $filepath = str_replace("\\", "/", $filepath); @@ -167,6 +167,6 @@ class CI_Exceptions { } // END Exceptions Class - -/* End of file Exceptions.php */ + +/* End of file Exceptions.php */ /* Location: ./system/libraries/Exceptions.php */ \ No newline at end of file diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 01354cf05..170ebe1c4 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -1,4 +1,4 @@ -_login()) + if ( ! $this->_login()) { if ($this->debug == TRUE) { @@ -139,7 +139,7 @@ class CI_FTP { */ function _is_conn() { - if (! is_resource($this->conn_id)) + if ( ! is_resource($this->conn_id)) { if ($this->debug == TRUE) { @@ -216,7 +216,7 @@ class CI_FTP { } // Set file permissions if needed - if (! is_null($permissions)) + if ( ! is_null($permissions)) { $this->chmod($path, (int)$permissions); } @@ -237,12 +237,12 @@ class CI_FTP { */ function upload($locpath, $rempath, $mode = 'auto', $permissions = NULL) { - if (! $this->_is_conn()) + if ( ! $this->_is_conn()) { return FALSE; } - if (! file_exists($locpath)) + if ( ! file_exists($locpath)) { $this->_error('ftp_no_source_file'); return FALSE; @@ -270,7 +270,7 @@ class CI_FTP { } // Set file permissions if needed - if (! is_null($permissions)) + if ( ! is_null($permissions)) { $this->chmod($rempath, (int)$permissions); } @@ -291,7 +291,7 @@ class CI_FTP { */ function rename($old_file, $new_file, $move = FALSE) { - if (! $this->_is_conn()) + if ( ! $this->_is_conn()) { return FALSE; } @@ -338,7 +338,7 @@ class CI_FTP { */ function delete_file($filepath) { - if (! $this->_is_conn()) + if ( ! $this->_is_conn()) { return FALSE; } @@ -369,7 +369,7 @@ class CI_FTP { */ function delete_dir($filepath) { - if (! $this->_is_conn()) + if ( ! $this->_is_conn()) { return FALSE; } @@ -385,7 +385,7 @@ class CI_FTP { { // If we can't delete the item it's probaly a folder so // we'll recursively call delete_dir() - if (! @ftp_delete($this->conn_id, $item)) + if ( ! @ftp_delete($this->conn_id, $item)) { $this->delete_dir($item); } @@ -418,13 +418,13 @@ class CI_FTP { */ function chmod($path, $perm) { - if (! $this->_is_conn()) + if ( ! $this->_is_conn()) { return FALSE; } // Permissions can only be set when running PHP 5 - if (! function_exists('ftp_chmod')) + if ( ! function_exists('ftp_chmod')) { if ($this->debug == TRUE) { @@ -457,7 +457,7 @@ class CI_FTP { */ function list_files($path = '.') { - if (! $this->_is_conn()) + if ( ! $this->_is_conn()) { return FALSE; } @@ -481,7 +481,7 @@ class CI_FTP { */ function mirror($locpath, $rempath) { - if (! $this->_is_conn()) + if ( ! $this->_is_conn()) { return FALSE; } @@ -490,10 +490,10 @@ class CI_FTP { if ($fp = @opendir($locpath)) { // Attempt to open the remote file path. - if (! $this->changedir($rempath, TRUE)) + if ( ! $this->changedir($rempath, TRUE)) { // If it doesn't exist we'll attempt to create the direcotory - if (! $this->mkdir($rempath) OR ! $this->changedir($rempath)) + if ( ! $this->mkdir($rempath) OR ! $this->changedir($rempath)) { return FALSE; } @@ -586,7 +586,7 @@ class CI_FTP { */ function close() { - if (! $this->_is_conn()) + if ( ! $this->_is_conn()) { return FALSE; } @@ -613,6 +613,6 @@ class CI_FTP { } // END FTP Class - -/* End of file Ftp.php */ + +/* End of file Ftp.php */ /* Location: ./system/libraries/Ftp.php */ \ No newline at end of file diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index d7637c39e..8c99bdd10 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -1,4 +1,4 @@ -enabled OR ! isset($this->hooks[$which])) + if ( ! $this->enabled OR ! isset($this->hooks[$which])) { return FALSE; } @@ -123,7 +123,7 @@ class CI_Hooks { */ function _run_hook($data) { - if (! is_array($data)) + if ( ! is_array($data)) { return FALSE; } @@ -144,14 +144,14 @@ class CI_Hooks { // Set file path // ----------------------------------- - if (! isset($data['filepath']) OR ! isset($data['filename'])) + if ( ! isset($data['filepath']) OR ! isset($data['filename'])) { return FALSE; } $filepath = APPPATH.$data['filepath'].'/'.$data['filename']; - if (! file_exists($filepath)) + if ( ! file_exists($filepath)) { return FALSE; } @@ -196,7 +196,7 @@ class CI_Hooks { if ($class !== FALSE) { - if (! class_exists($class)) + if ( ! class_exists($class)) { require($filepath); } @@ -206,7 +206,7 @@ class CI_Hooks { } else { - if (! function_exists($function)) + if ( ! function_exists($function)) { require($filepath); } @@ -221,6 +221,6 @@ class CI_Hooks { } // END CI_Hooks class - -/* End of file Hooks.php */ + +/* End of file Hooks.php */ /* Location: ./system/libraries/Hooks.php */ \ No newline at end of file diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 4017afb13..a602b4645 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1,4 +1,4 @@ -set_error('imglib_gd_required_for_props'); return FALSE; @@ -188,7 +188,7 @@ class CI_Image_lib { $this->source_folder = str_replace($this->source_image, '', $full_source_path); // Set the Image Properties - if (! $this->get_image_properties($this->source_folder.$this->source_image)) + if ( ! $this->get_image_properties($this->source_folder.$this->source_image)) { return FALSE; } @@ -226,7 +226,7 @@ class CI_Image_lib { } // Is there a file name? - if (! preg_match("#[\.jpg|\.jpeg|\.gif|\.png]$#i", $full_dest_path)) + if ( ! preg_match("#[\.jpg|\.jpeg|\.gif|\.png]$#i", $full_dest_path)) { $this->dest_folder = $full_dest_path.'/'; $this->dest_image = $this->source_image; @@ -478,7 +478,7 @@ class CI_Image_lib { // we'll simply make a copy of the original with the new name if (($this->orig_width == $this->width AND $this->orig_height == $this->height) AND ($this->source_image != $this->new_image)) { - if (! @copy($this->full_src_path, $this->full_dst_path)) + if ( ! @copy($this->full_src_path, $this->full_dst_path)) { $this->set_error('imglib_copy_failed'); return FALSE; @@ -494,7 +494,7 @@ class CI_Image_lib { } // Create the image handle - if (! ($src_img = $this->image_create_gd())) + if ( ! ($src_img = $this->image_create_gd())) { return FALSE; } @@ -528,7 +528,7 @@ class CI_Image_lib { else { // Or save it - if (! $this->image_save_gd($dst_img)) + if ( ! $this->image_save_gd($dst_img)) { return FALSE; } @@ -564,9 +564,9 @@ class CI_Image_lib { return FALSE; } - if (! eregi("convert$", $this->library_path)) + if ( ! eregi("convert$", $this->library_path)) { - if (! eregi("/$", $this->library_path)) $this->library_path .= "/"; + if ( ! eregi("/$", $this->library_path)) $this->library_path .= "/"; $this->library_path .= 'convert'; } @@ -712,14 +712,14 @@ class CI_Image_lib { { // Is Image Rotation Supported? // this function is only supported as of PHP 4.3 - if (! function_exists('imagerotate')) + if ( ! function_exists('imagerotate')) { $this->set_error('imglib_rotate_unsupported'); return FALSE; } // Create the image handle - if (! ($src_img = $this->image_create_gd())) + if ( ! ($src_img = $this->image_create_gd())) { return FALSE; } @@ -742,7 +742,7 @@ class CI_Image_lib { else { // Or save it - if (! $this->image_save_gd($dst_img)) + if ( ! $this->image_save_gd($dst_img)) { return FALSE; } @@ -771,7 +771,7 @@ class CI_Image_lib { */ function image_mirror_gd() { - if (! $src_img = $this->image_create_gd()) + if ( ! $src_img = $this->image_create_gd()) { return FALSE; } @@ -828,7 +828,7 @@ class CI_Image_lib { else { // Or save it - if (! $this->image_save_gd($src_img)) + if ( ! $this->image_save_gd($src_img)) { return FALSE; } @@ -877,7 +877,7 @@ class CI_Image_lib { */ function overlay_watermark() { - if (! function_exists('imagecolortransparent')) + if ( ! function_exists('imagecolortransparent')) { $this->set_error('imglib_gd_required'); return FALSE; @@ -968,7 +968,7 @@ class CI_Image_lib { } else { - if (! $this->image_save_gd($src_img)) + if ( ! $this->image_save_gd($src_img)) { return FALSE; } @@ -990,7 +990,7 @@ class CI_Image_lib { */ function text_watermark() { - if (! ($src_img = $this->image_create_gd())) + if ( ! ($src_img = $this->image_create_gd())) { return FALSE; } @@ -1144,7 +1144,7 @@ class CI_Image_lib { switch ($image_type) { case 1 : - if (! function_exists('imagecreatefromgif')) + if ( ! function_exists('imagecreatefromgif')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); return FALSE; @@ -1153,7 +1153,7 @@ class CI_Image_lib { return imagecreatefromgif($path); break; case 2 : - if (! function_exists('imagecreatefromjpeg')) + if ( ! function_exists('imagecreatefromjpeg')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); return FALSE; @@ -1162,7 +1162,7 @@ class CI_Image_lib { return imagecreatefromjpeg($path); break; case 3 : - if (! function_exists('imagecreatefrompng')) + if ( ! function_exists('imagecreatefrompng')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); return FALSE; @@ -1194,7 +1194,7 @@ class CI_Image_lib { switch ($this->image_type) { case 1 : - if (! function_exists('imagegif')) + if ( ! function_exists('imagegif')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); return FALSE; @@ -1203,7 +1203,7 @@ class CI_Image_lib { @imagegif($resource, $this->full_dst_path); break; case 2 : - if (! function_exists('imagejpeg')) + if ( ! function_exists('imagejpeg')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); return FALSE; @@ -1217,7 +1217,7 @@ class CI_Image_lib { @imagejpeg($resource, $this->full_dst_path, $this->quality); break; case 3 : - if (! function_exists('imagepng')) + if ( ! function_exists('imagepng')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); return FALSE; @@ -1280,10 +1280,10 @@ class CI_Image_lib { */ function image_reproportion() { - if (! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0) + if ( ! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0) return; - if (! is_numeric($this->orig_width) OR ! is_numeric($this->orig_height) OR $this->orig_width == 0 OR $this->orig_height == 0) + if ( ! is_numeric($this->orig_width) OR ! is_numeric($this->orig_height) OR $this->orig_width == 0 OR $this->orig_height == 0) return; $new_width = ceil($this->orig_width*$this->height/$this->orig_height); @@ -1328,7 +1328,7 @@ class CI_Image_lib { if ($path == '') $path = $this->full_src_path; - if (! file_exists($path)) + if ( ! file_exists($path)) { $this->set_error('imglib_invalid_path'); return FALSE; @@ -1382,14 +1382,14 @@ class CI_Image_lib { */ function size_calculator($vals) { - if (! is_array($vals)) + if ( ! is_array($vals)) return; $allowed = array('new_width', 'new_height', 'width', 'height'); foreach ($allowed as $item) { - if (! isset($vals[$item]) OR $vals[$item] == '') + if ( ! isset($vals[$item]) OR $vals[$item] == '') $vals[$item] = 0; } @@ -1460,9 +1460,9 @@ class CI_Image_lib { */ function gd_loaded() { - if (! extension_loaded('gd')) + if ( ! extension_loaded('gd')) { - if (! dl('gd.so')) + if ( ! dl('gd.so')) { return FALSE; } diff --git a/system/libraries/Input.php b/system/libraries/Input.php index f98757947..978d1ff34 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -1,4 +1,4 @@ - $val) { - if (! in_array($key, $protected)) + if ( ! in_array($key, $protected)) { unset($GLOBALS[$key]); } @@ -97,7 +97,7 @@ class CI_Input { { foreach($val as $k => $v) { - if (! in_array($k, $protected)) + if ( ! in_array($k, $protected)) { unset($GLOBALS[$k]); } @@ -181,7 +181,12 @@ class CI_Input { } // Standardize newlines - return preg_replace("/\015\012|\015|\012/", "\n", $str); + if (strpos($str, "\r") !== FALSE) + { + $str = str_replace(array("\r\n", "\r"), "\n", $str); + } + + return $str; } // -------------------------------------------------------------------- @@ -199,7 +204,7 @@ class CI_Input { */ function _clean_input_keys($str) { - if (! preg_match("/^[a-z0-9:_\/-]+$/i", $str)) + if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str)) { exit('Disallowed Key Characters.'); } @@ -219,7 +224,7 @@ class CI_Input { */ function get($index = '', $xss_clean = FALSE) { - if (! isset($_GET[$index])) + if ( ! isset($_GET[$index])) { return FALSE; } @@ -254,7 +259,7 @@ class CI_Input { */ function post($index = '', $xss_clean = FALSE) { - if (! isset($_POST[$index])) + if ( ! isset($_POST[$index])) { return FALSE; } @@ -289,7 +294,7 @@ class CI_Input { */ function cookie($index = '', $xss_clean = FALSE) { - if (! isset($_COOKIE[$index])) + if ( ! isset($_COOKIE[$index])) { return FALSE; } @@ -329,7 +334,7 @@ class CI_Input { */ function server($index = '', $xss_clean = FALSE) { - if (! isset($_SERVER[$index])) + if ( ! isset($_SERVER[$index])) { return FALSE; } @@ -386,7 +391,7 @@ class CI_Input { $this->ip_address = end($x); } - if (! $this->valid_ip($this->ip_address)) + if ( ! $this->valid_ip($this->ip_address)) { $this->ip_address = '0.0.0.0'; } @@ -448,7 +453,7 @@ class CI_Input { return $this->user_agent; } - $this->user_agent = (! isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT']; + $this->user_agent = ( ! isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT']; return $this->user_agent; } @@ -650,8 +655,9 @@ class CI_Input { * */ - if (strpos($str, "\t") !== FALSE) { - $str = str_replace("\t", " ", $str); + if (strpos($str, "\t") !== FALSE) + { + $str = str_replace("\t", ' ', $str); } /* diff --git a/system/libraries/Language.php b/system/libraries/Language.php index aacc6c1f9..f97db3506 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -1,4 +1,4 @@ -load->database($db_conn, FALSE, TRUE); } - if (! class_exists('Model')) + if ( ! class_exists('Model')) { load_class('Model', FALSE); } @@ -230,7 +230,7 @@ class CI_Loader { */ function dbutil() { - if (! class_exists('CI_DB')) + if ( ! class_exists('CI_DB')) { $this->database(); } @@ -260,7 +260,7 @@ class CI_Loader { */ function dbforge() { - if (! class_exists('CI_DB')) + if ( ! class_exists('CI_DB')) { $this->database(); } @@ -355,7 +355,7 @@ class CI_Loader { */ function helper($helpers = array()) { - if (! is_array($helpers)) + if ( ! is_array($helpers)) { $helpers = array($helpers); } @@ -376,7 +376,7 @@ class CI_Loader { { $base_helper = BASEPATH.'helpers/'.$helper.EXT; - if (! file_exists($base_helper)) + if ( ! file_exists($base_helper)) { show_error('Unable to load the requested file: helpers/'.$helper.EXT); } @@ -437,7 +437,7 @@ class CI_Loader { */ function plugin($plugins = array()) { - if (! is_array($plugins)) + if ( ! is_array($plugins)) { $plugins = array($plugins); } @@ -507,7 +507,7 @@ class CI_Loader { */ function script($scripts = array()) { - if (! is_array($scripts)) + if ( ! is_array($scripts)) { $scripts = array($scripts); } @@ -521,7 +521,7 @@ class CI_Loader { continue; } - if (! file_exists(APPPATH.'scripts/'.$script.EXT)) + if ( ! file_exists(APPPATH.'scripts/'.$script.EXT)) { show_error('Unable to load the requested script: scripts/'.$script.EXT); } @@ -546,7 +546,7 @@ class CI_Loader { { $CI =& get_instance(); - if (! is_array($file)) + if ( ! is_array($file)) { $file = array($file); } @@ -632,7 +632,7 @@ class CI_Loader { // Set the default data variables foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val) { - $$_ci_val = (! isset($_ci_data[$_ci_val])) ? FALSE : $_ci_data[$_ci_val]; + $$_ci_val = ( ! isset($_ci_data[$_ci_val])) ? FALSE : $_ci_data[$_ci_val]; } // Set the path to the requested file @@ -648,7 +648,7 @@ class CI_Loader { $_ci_file = end($_ci_x); } - if (! file_exists($_ci_path)) + if ( ! file_exists($_ci_path)) { show_error('Unable to load the requested file: '.$_ci_file); } @@ -662,7 +662,7 @@ class CI_Loader { $_ci_CI =& get_instance(); foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var) { - if (! isset($this->$_ci_key)) + if ( ! isset($this->$_ci_key)) { $this->$_ci_key =& $_ci_CI->$_ci_key; } @@ -703,7 +703,7 @@ class CI_Loader { if ((bool) @ini_get('short_open_tag') === FALSE AND config_item('rewrite_short_tags') == TRUE) { - echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace('/", "; ?>", str_replace('_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; + $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; // Instantiate the class $CI =& get_instance(); @@ -890,7 +890,7 @@ class CI_Loader { { include_once(APPPATH.'config/autoload'.EXT); - if (! isset($autoload)) + if ( ! isset($autoload)) { return FALSE; } @@ -918,7 +918,7 @@ class CI_Loader { // A little tweak to remain backward compatible // The $autoload['core'] item was deprecated - if (! isset($autoload['libraries'])) + if ( ! isset($autoload['libraries'])) { $autoload['libraries'] = $autoload['core']; } diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 22b505906..4d64cd328 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -1,4 +1,4 @@ -log_path = ($config['log_path'] != '') ? $config['log_path'] : BASEPATH.'logs/'; - if (! is_dir($this->log_path) OR ! is_really_writable($this->log_path)) + if ( ! is_dir($this->log_path) OR ! is_really_writable($this->log_path)) { $this->_enabled = FALSE; } @@ -84,7 +84,7 @@ class CI_Log { $level = strtoupper($level); - if (! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) + if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) { return FALSE; } @@ -92,12 +92,12 @@ class CI_Log { $filepath = $this->log_path.'log-'.date('Y-m-d').EXT; $message = ''; - if (! file_exists($filepath)) + if ( ! file_exists($filepath)) { - $message .= "<"."?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; + $message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; } - if (! $fp = @fopen($filepath, FOPEN_WRITE_CREATE)) + if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE)) { return FALSE; } @@ -115,6 +115,6 @@ class CI_Log { } // END Log Class - -/* End of file Log.php */ + +/* End of file Log.php */ /* Location: ./system/libraries/Log.php */ \ No newline at end of file diff --git a/system/libraries/Model.php b/system/libraries/Model.php index 1e7b9a184..5c8d43363 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -1,4 +1,4 @@ -$key) AND $key != $this->_parent_name) + if ( ! isset($this->$key) AND $key != $this->_parent_name) { // In some cases using references can cause // problems so we'll conditionally use them @@ -79,6 +79,6 @@ class Model { } // END Model Class - -/* End of file Model.php */ + +/* End of file Model.php */ /* Location: ./system/libraries/Model.php */ \ No newline at end of file diff --git a/system/libraries/Output.php b/system/libraries/Output.php index f76550e2b..49cfc0a28 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -1,4 +1,4 @@ -cache_expiration = (! is_numeric($time)) ? 0 : $time; + $this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time; } // -------------------------------------------------------------------- @@ -187,7 +187,7 @@ class CI_Output { $elapsed = $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end'); $output = str_replace('{elapsed_time}', $elapsed, $output); - $memory = (! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; + $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; $output = str_replace('{memory_usage}', $memory, $output); // -------------------------------------------------------------------- @@ -220,7 +220,7 @@ class CI_Output { // Does the get_instance() function exist? // If not we know we are dealing with a cache file so we'll // simply echo out the data and exit. - if (! function_exists('get_instance')) + if ( ! function_exists('get_instance')) { echo $output; log_message('debug', "Final output sent to browser"); @@ -285,7 +285,7 @@ class CI_Output { $cache_path = ($path == '') ? BASEPATH.'cache/' : $path; - if (! is_dir($cache_path) OR ! is_really_writable($cache_path)) + if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path)) { return; } @@ -296,7 +296,7 @@ class CI_Output { $cache_path .= md5($uri); - if (! $fp = @fopen($cache_path, 'wb')) + if ( ! $fp = @fopen($cache_path, 'wb')) { log_message('error', "Unable to write cache file: ".$cache_path); return; @@ -327,7 +327,7 @@ class CI_Output { $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); - if (! is_dir($cache_path) OR ! is_really_writable($cache_path)) + if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path)) { return FALSE; } @@ -339,12 +339,12 @@ class CI_Output { $filepath = $cache_path.md5($uri); - if (! @file_exists($filepath)) + if ( ! @file_exists($filepath)) { return FALSE; } - if (! $fp = @fopen($filepath, 'rb')) + if ( ! $fp = @fopen($filepath, 'rb')) { return FALSE; } @@ -361,7 +361,7 @@ class CI_Output { fclose($fp); // Strip out the embedded timestamp - if (! preg_match("/(\d+TS--->)/", $cache, $match)) + if ( ! preg_match("/(\d+TS--->)/", $cache, $match)) { return FALSE; } @@ -383,6 +383,6 @@ class CI_Output { } // END Output Class - -/* End of file Output.php */ + +/* End of file Output.php */ /* Location: ./system/libraries/Output.php */ \ No newline at end of file diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index c3f6bd89c..10af3fd11 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -1,4 +1,4 @@ -cur_page)) + if ( ! is_numeric($this->cur_page)) { $this->cur_page = 0; } @@ -215,6 +215,6 @@ class CI_Pagination { } } // END Pagination Class - -/* End of file Pagination.php */ + +/* End of file Pagination.php */ /* Location: ./system/libraries/Pagination.php */ \ No newline at end of file diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index f260b2e19..d349e26d3 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -1,4 +1,4 @@ - $val) { - if (! is_array($val)) + if ( ! is_array($val)) { $temp = $this->_parse_single($key, $val, $temp); } @@ -158,7 +158,7 @@ class CI_Parser { */ function _match_pair($string, $variable) { - if (! preg_match("|".$this->l_delim . $variable . $this->r_delim."(.+)".$this->l_delim . '/' . $variable . $this->r_delim."|s", $string, $match)) + if ( ! preg_match("|".$this->l_delim . $variable . $this->r_delim."(.+)".$this->l_delim . '/' . $variable . $this->r_delim."|s", $string, $match)) { return FALSE; } @@ -168,6 +168,6 @@ class CI_Parser { } // END Parser Class - -/* End of file Parser.php */ + +/* End of file Parser.php */ /* Location: ./system/libraries/Parser.php */ \ No newline at end of file diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index fe4fb6d62..da1fff19b 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -1,4 +1,4 @@ -'; $output .= "\n"; - if (! class_exists('CI_DB_driver')) + if ( ! class_exists('CI_DB_driver')) { $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; $output .= "\n"; @@ -175,7 +175,7 @@ class CI_Profiler { foreach ($_GET as $key => $val) { - if (! is_numeric($key)) + if ( ! is_numeric($key)) { $key = "'".$key."'"; } @@ -225,7 +225,7 @@ class CI_Profiler { foreach ($_POST as $key => $val) { - if (! is_numeric($key)) + if ( ! is_numeric($key)) { $key = "'".$key."'"; } @@ -340,6 +340,6 @@ class CI_Profiler { } // END CI_Profiler class - -/* End of file Profiler.php */ + +/* End of file Profiler.php */ /* Location: ./system/libraries/Profiler.php */ \ No newline at end of file diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 3b2520dce..6e705f842 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -1,4 +1,4 @@ -routes = (! isset($route) OR ! is_array($route)) ? array() : $route; + $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']); // Fetch the complete URI string $this->uri->_fetch_uri_string(); @@ -202,7 +202,7 @@ class CI_Router { if (count($segments) > 0) { // Does the requested controller exist in the sub-folder? - if (! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT)) + if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT)) { show_404($this->fetch_directory().$segments[0]); } @@ -213,7 +213,7 @@ class CI_Router { $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)) + if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT)) { $this->directory = ''; return array(); @@ -374,6 +374,6 @@ class CI_Router { } // END Router Class - -/* End of file Router.php */ + +/* End of file Router.php */ /* Location: ./system/libraries/Router.php */ \ No newline at end of file diff --git a/system/libraries/Session.php b/system/libraries/Session.php index ce1b75e66..31a162e81 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -1,4 +1,4 @@ -sess_read()) + if ( ! $this->sess_read()) { $this->sess_create(); } @@ -214,7 +214,7 @@ class CI_Session { $session = @unserialize($this->strip_slashes($session)); - if (! is_array($session) OR ! isset($session['last_activity'])) + if ( ! is_array($session) OR ! isset($session['last_activity'])) { log_message('error', 'The session cookie data did not contain a valid array. This could be a possible hacking attempt.'); return FALSE; @@ -439,7 +439,7 @@ class CI_Session { */ function userdata($item) { - return (! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; + return ( ! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; } // -------------------------------------------------------------------- @@ -452,7 +452,7 @@ class CI_Session { */ function all_userdata() { - return (! isset($this->userdata)) ? FALSE : $this->userdata; + return ( ! isset($this->userdata)) ? FALSE : $this->userdata; } // -------------------------------------------------------------------- @@ -649,6 +649,6 @@ class CI_Session { } // END Session Class - -/* End of file Session.php */ + +/* End of file Session.php */ /* Location: ./system/libraries/Session.php */ \ No newline at end of file diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index a7b9b98d3..71b4ccd0d 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -1,4 +1,4 @@ -rows as $row) { - if (! is_array($row)) + if ( ! is_array($row)) { break; } @@ -308,7 +308,7 @@ class CI_Table { */ function _set_from_object($query) { - if (! is_object($query)) + if ( ! is_object($query)) { return FALSE; } @@ -316,7 +316,7 @@ class CI_Table { // First generate the headings from the table column names if (count($this->heading) == 0) { - if (! method_exists($query, 'list_fields')) + if ( ! method_exists($query, 'list_fields')) { return FALSE; } @@ -346,7 +346,7 @@ class CI_Table { */ function _set_from_array($data, $set_heading = TRUE) { - if (! is_array($data) OR count($data) == 0) + if ( ! is_array($data) OR count($data) == 0) { return FALSE; } @@ -354,7 +354,7 @@ class CI_Table { $i = 0; foreach ($data as $row) { - if (! is_array($row)) + if ( ! is_array($row)) { $this->rows[] = $data; break; @@ -393,7 +393,7 @@ class CI_Table { $this->temp = $this->_default_template(); foreach (array('table_open','heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end', 'row_start', 'row_end', 'cell_start', 'cell_end', 'row_alt_start', 'row_alt_end', 'cell_alt_start', 'cell_alt_end', 'table_close') as $val) { - if (! isset($this->template[$val])) + if ( ! isset($this->template[$val])) { $this->template[$val] = $this->temp[$val]; } @@ -435,6 +435,6 @@ class CI_Table { } - -/* End of file Table.php */ + +/* End of file Table.php */ /* Location: ./system/libraries/Table.php */ \ No newline at end of file diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index 41ac5fca8..6696fd2da 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -1,4 +1,4 @@ -set_error('The send() method must be passed an array'); return FALSE; @@ -65,7 +65,7 @@ class CI_Trackback { // Pre-process the Trackback Data foreach (array('url', 'title', 'excerpt', 'blog_name', 'ping_url') as $item) { - if (! isset($tb_data[$item])) + if ( ! isset($tb_data[$item])) { $this->set_error('Required item missing: '.$item); return FALSE; @@ -102,7 +102,7 @@ class CI_Trackback { } // Build the Trackback data string - $charset = (! isset($tb_data['charset'])) ? $this->charset : $tb_data['charset']; + $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); @@ -139,13 +139,13 @@ class CI_Trackback { { foreach (array('url', 'title', 'blog_name', 'excerpt') as $val) { - if (! isset($_POST[$val]) OR $_POST[$val] == '') + if ( ! isset($_POST[$val]) OR $_POST[$val] == '') { $this->set_error('The following required POST variable is missing: '.$val); return FALSE; } - $this->data['charset'] = (! isset($_POST['charset'])) ? 'auto' : strtoupper(trim($_POST['charset'])); + $this->data['charset'] = ( ! isset($_POST['charset'])) ? 'auto' : strtoupper(trim($_POST['charset'])); if ($val != 'url' && function_exists('mb_convert_encoding')) { @@ -212,7 +212,7 @@ class CI_Trackback { */ function data($item) { - return (! isset($this->data[$item])) ? '' : $this->data[$item]; + return ( ! isset($this->data[$item])) ? '' : $this->data[$item]; } // -------------------------------------------------------------------- @@ -233,14 +233,14 @@ class CI_Trackback { $target = parse_url($url); // Open the socket - if (! $fp = @fsockopen($target['host'], 80)) + if ( ! $fp = @fsockopen($target['host'], 80)) { $this->set_error('Invalid Connection: '.$url); return FALSE; } // Build the path - $ppath = (! isset($target['path'])) ? $url : $target['path']; + $ppath = ( ! isset($target['path'])) ? $url : $target['path']; $path = (isset($target['query']) && $target['query'] != "") ? $ppath.'?'.$target['query'] : $ppath; @@ -261,13 +261,13 @@ class CI_Trackback { // Was it successful? $this->response = ""; - while(!feof($fp)) + while( ! feof($fp)) { $this->response .= fgets($fp, 128); } @fclose($fp); - if (! eregi("0", $this->response)) + if ( ! eregi("0", $this->response)) { $message = 'An unknown error was encountered'; @@ -360,7 +360,7 @@ class CI_Trackback { $tb_array = explode('/', $url); $tb_end = $tb_array[count($tb_array)-1]; - if (! is_numeric($tb_end)) + if ( ! is_numeric($tb_end)) { $tb_end = $tb_array[count($tb_array)-2]; } @@ -378,13 +378,13 @@ class CI_Trackback { $tb_array = explode('/', $url); $tb_id = $tb_array[count($tb_array)-1]; - if (! is_numeric($tb_id)) + if ( ! is_numeric($tb_id)) { $tb_id = $tb_array[count($tb_array)-2]; } } - if (! preg_match ("/^([0-9]+)$/", $tb_id)) + if ( ! preg_match ("/^([0-9]+)$/", $tb_id)) { return false; } @@ -439,8 +439,8 @@ class CI_Trackback { { return $str; } - - $str = preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $str)); + + $str = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str)); if (strlen($str) <= $n) { @@ -545,6 +545,6 @@ class CI_Trackback { } // END Trackback Class - -/* End of file Trackback.php */ + +/* End of file Trackback.php */ /* Location: ./system/libraries/Trackback.php */ \ No newline at end of file diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 26a7b4a33..4d0cd9c17 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -1,4 +1,4 @@ -config->item('permitted_uri_chars') != '') { - if (! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) + if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) { exit('The URI you submitted has disallowed characters.'); } @@ -279,7 +279,7 @@ class CI_URI { */ function segment($n, $no_result = FALSE) { - return (! isset($this->segments[$n])) ? $no_result : $this->segments[$n]; + return ( ! isset($this->segments[$n])) ? $no_result : $this->segments[$n]; } // -------------------------------------------------------------------- @@ -298,7 +298,7 @@ class CI_URI { */ function rsegment($n, $no_result = FALSE) { - return (! isset($this->rsegments[$n])) ? $no_result : $this->rsegments[$n]; + return ( ! isset($this->rsegments[$n])) ? $no_result : $this->rsegments[$n]; } // -------------------------------------------------------------------- @@ -361,7 +361,7 @@ class CI_URI { $segment_array = 'rsegment_array'; } - if (! is_numeric($n)) + if ( ! is_numeric($n)) { return $default; } @@ -410,7 +410,7 @@ class CI_URI { { foreach ($default as $val) { - if (! array_key_exists($val, $retval)) + if ( ! array_key_exists($val, $retval)) { $retval[$val] = FALSE; } @@ -586,6 +586,6 @@ class CI_URI { } // END URI Class - -/* End of file URI.php */ + +/* End of file URI.php */ /* Location: ./system/libraries/URI.php */ \ No newline at end of file diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index bfa6d5dc5..e53e04c15 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -1,4 +1,4 @@ - $file, 'line' => $line); } @@ -302,7 +302,7 @@ class CI_Unit_test { */ function _parse_template() { - if (! is_null($this->_template_rows)) + if ( ! is_null($this->_template_rows)) { return; } @@ -313,7 +313,7 @@ class CI_Unit_test { return; } - if (! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match)) + if ( ! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match)) { $this->_default_template(); return; diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 07cbd924b..1225ee36b 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -1,4 +1,4 @@ -set_error('upload_no_file_selected'); return FALSE; } // Is the upload path valid? - if (! $this->validate_upload_path()) + if ( ! $this->validate_upload_path()) { // errors will already be set by validate_upload_path() so just return FALSE return FALSE; } // Was the file able to be uploaded? If not, determine the reason why. - if (! is_uploaded_file($_FILES[$field]['tmp_name'])) + if ( ! is_uploaded_file($_FILES[$field]['tmp_name'])) { - $error = (! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error']; + $error = ( ! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error']; switch($error) { @@ -198,14 +198,14 @@ class CI_Upload { } // Is the file type allowed to be uploaded? - if (! $this->is_allowed_filetype()) + if ( ! $this->is_allowed_filetype()) { $this->set_error('upload_invalid_filetype'); return FALSE; } // Is the file size within the allowed maximum? - if (! $this->is_allowed_filesize()) + if ( ! $this->is_allowed_filesize()) { $this->set_error('upload_invalid_filesize'); return FALSE; @@ -213,7 +213,7 @@ class CI_Upload { // Are the image dimensions within the allowed size? // Note: This can fail if the server has an open_basdir restriction. - if (! $this->is_allowed_dimensions()) + if ( ! $this->is_allowed_dimensions()) { $this->set_error('upload_invalid_dimensions'); return FALSE; @@ -253,9 +253,9 @@ class CI_Upload { * we'll use move_uploaded_file(). One of the two should * reliably work in most environments */ - if (! @copy($this->file_temp, $this->upload_path.$this->file_name)) + if ( ! @copy($this->file_temp, $this->upload_path.$this->file_name)) { - if (! @move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name)) + if ( ! @move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name)) { $this->set_error('upload_destination_error'); return FALSE; @@ -350,7 +350,7 @@ class CI_Upload { $filename = md5(uniqid(mt_rand())).$this->file_ext; } - if (! file_exists($path.$filename)) + if ( ! file_exists($path.$filename)) { return $filename; } @@ -360,7 +360,7 @@ class CI_Upload { $new_filename = ''; for ($i = 1; $i < 100; $i++) { - if (! file_exists($path.$filename.$i.$this->file_ext)) + if ( ! file_exists($path.$filename.$i.$this->file_ext)) { $new_filename = $filename.$i.$this->file_ext; break; @@ -389,7 +389,7 @@ class CI_Upload { */ function set_max_filesize($n) { - $this->max_size = (! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + $this->max_size = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; } // -------------------------------------------------------------------- @@ -403,7 +403,7 @@ class CI_Upload { */ function set_max_width($n) { - $this->max_width = (! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + $this->max_width = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; } // -------------------------------------------------------------------- @@ -417,7 +417,7 @@ class CI_Upload { */ function set_max_height($n) { - $this->max_height = (! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + $this->max_height = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; } // -------------------------------------------------------------------- @@ -447,7 +447,7 @@ class CI_Upload { */ function set_image_properties($path = '') { - if (! $this->is_image()) + if ( ! $this->is_image()) { return; } @@ -460,7 +460,7 @@ class CI_Upload { $this->image_width = $D['0']; $this->image_height = $D['1']; - $this->image_type = (! isset($types[$D['2']])) ? 'unknown' : $types[$D['2']]; + $this->image_type = ( ! isset($types[$D['2']])) ? 'unknown' : $types[$D['2']]; $this->image_size_str = $D['3']; // string containing height and width } } @@ -528,7 +528,7 @@ class CI_Upload { */ function is_allowed_filetype() { - if (count($this->allowed_types) == 0 || ! is_array($this->allowed_types)) + if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types)) { $this->set_error('upload_no_file_types'); return FALSE; @@ -587,7 +587,7 @@ class CI_Upload { */ function is_allowed_dimensions() { - if (! $this->is_image()) + if ( ! $this->is_image()) { return TRUE; } @@ -636,13 +636,13 @@ class CI_Upload { $this->upload_path = str_replace("\\", "/", realpath($this->upload_path)); } - if (! @is_dir($this->upload_path)) + if ( ! @is_dir($this->upload_path)) { $this->set_error('upload_no_filepath'); return FALSE; } - if (! is_really_writable($this->upload_path)) + if ( ! is_really_writable($this->upload_path)) { $this->set_error('upload_not_writable'); return FALSE; @@ -741,7 +741,7 @@ class CI_Upload { return FALSE; } - if (! $fp = @fopen($file, FOPEN_READ_WRITE)) + if ( ! $fp = @fopen($file, FOPEN_READ_WRITE)) { return FALSE; } @@ -830,7 +830,7 @@ class CI_Upload { } } - return (! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime]; + return ( ! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime]; } /** @@ -875,6 +875,6 @@ class CI_Upload { } // END Upload Class - -/* End of file Upload.php */ + +/* End of file Upload.php */ /* Location: ./system/libraries/Upload.php */ \ No newline at end of file diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index ee1839277..86b249ccd 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -1,4 +1,4 @@ -agent = trim($_SERVER['HTTP_USER_AGENT']); } - if (! is_null($this->agent)) + if ( ! is_null($this->agent)) { if ($this->_load_agent_file()) { @@ -84,7 +84,7 @@ class CI_User_agent { */ function _load_agent_file() { - if (! @include(APPPATH.'config/user_agents'.EXT)) + if ( ! @include(APPPATH.'config/user_agents'.EXT)) { return FALSE; } @@ -339,7 +339,7 @@ class CI_User_agent { */ function is_referral() { - return (! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE; + return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -429,7 +429,7 @@ class CI_User_agent { */ function referrer() { - return (! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']); + return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']); } // -------------------------------------------------------------------- @@ -497,6 +497,6 @@ class CI_User_agent { } - -/* End of file User_agent.php */ + +/* End of file User_agent.php */ /* Location: ./system/libraries/User_agent.php */ \ No newline at end of file diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index a0f038c02..9654b4f4e 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -1,4 +1,4 @@ - $field); } @@ -87,10 +87,10 @@ class CI_Validation { foreach($this->_fields as $key => $val) { - $this->$key = (! isset($_POST[$key])) ? '' : $this->prep_for_form($_POST[$key]); + $this->$key = ( ! isset($_POST[$key])) ? '' : $this->prep_for_form($_POST[$key]); $error = $key.'_error'; - if (! isset($this->$error)) + if ( ! isset($this->$error)) { $this->$error = ''; } @@ -112,7 +112,7 @@ class CI_Validation { */ function set_rules($data, $rules = '') { - if (! is_array($data)) + if ( ! is_array($data)) { if ($rules == '') return; @@ -141,7 +141,7 @@ class CI_Validation { */ function set_message($lang, $val = '') { - if (! is_array($lang)) + if ( ! is_array($lang)) { $lang = array($lang => $val); } @@ -195,9 +195,9 @@ class CI_Validation { $ex = explode('|', $rules); // Is the field required? If not, if the field is blank we'll move on to the next test - if (! in_array('required', $ex, TRUE)) + if ( ! in_array('required', $ex, TRUE)) { - if (! isset($_POST[$field]) OR $_POST[$field] == '') + if ( ! isset($_POST[$field]) OR $_POST[$field] == '') { continue; } @@ -212,11 +212,11 @@ class CI_Validation { * test for it here since there's not reason to go * further */ - if (! isset($_POST[$field])) + if ( ! isset($_POST[$field])) { if (in_array('isset', $ex, TRUE) OR in_array('required', $ex)) { - if (! isset($this->_error_messages['isset'])) + if ( ! isset($this->_error_messages['isset'])) { if (FALSE === ($line = $this->CI->lang->line('isset'))) { @@ -229,7 +229,7 @@ class CI_Validation { } // Build the error message - $mfield = (! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; + $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; $message = sprintf($line, $mfield); // Set the error variable. Example: $this->username_error @@ -274,7 +274,7 @@ class CI_Validation { // Call the function that corresponds to the rule if ($callback === TRUE) { - if (! method_exists($this->CI, $rule)) + if ( ! method_exists($this->CI, $rule)) { continue; } @@ -282,7 +282,7 @@ class CI_Validation { $result = $this->CI->$rule($_POST[$field], $param); // If the field isn't required and we just processed a callback we'll move on... - if (! in_array('required', $ex, TRUE) AND $result !== FALSE) + if ( ! in_array('required', $ex, TRUE) AND $result !== FALSE) { continue 2; } @@ -290,7 +290,7 @@ class CI_Validation { } else { - if (! method_exists($this, $rule)) + if ( ! method_exists($this, $rule)) { /* * Run the native PHP function if called for @@ -314,7 +314,7 @@ class CI_Validation { // Did the rule test negatively? If so, grab the error. if ($result === FALSE) { - if (! isset($this->_error_messages[$rule])) + if ( ! isset($this->_error_messages[$rule])) { if (FALSE === ($line = $this->CI->lang->line($rule))) { @@ -327,8 +327,8 @@ class CI_Validation { } // Build the error message - $mfield = (! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; - $mparam = (! isset($this->_fields[$param])) ? $param : $this->_fields[$param]; + $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; + $mparam = ( ! isset($this->_fields[$param])) ? $param : $this->_fields[$param]; $message = sprintf($line, $mfield, $mparam); // Set the error variable. Example: $this->username_error @@ -385,13 +385,13 @@ class CI_Validation { */ function required($str) { - if (! is_array($str)) + if ( ! is_array($str)) { return (trim($str) == '') ? FALSE : TRUE; } else { - return (! empty($str)); + return ( ! empty($str)); } } @@ -406,7 +406,7 @@ class CI_Validation { */ function matches($str, $field) { - if (! isset($_POST[$field])) + if ( ! isset($_POST[$field])) { return FALSE; } @@ -482,7 +482,7 @@ class CI_Validation { */ function valid_email($str) { - return (! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; + return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -537,7 +537,7 @@ class CI_Validation { */ function alpha($str) { - return (! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE; + return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -551,7 +551,7 @@ class CI_Validation { */ function alpha_numeric($str) { - return (! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE; + return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -565,7 +565,7 @@ class CI_Validation { */ function alpha_dash($str) { - return (! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE; + return ( ! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -594,7 +594,7 @@ class CI_Validation { */ function is_numeric($str) { - return (! is_numeric($str)) ? FALSE : TRUE; + return ( ! is_numeric($str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 32d739689..1748ab833 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -1,4 +1,4 @@ -client) && is_int($seconds)) + if ( ! is_null($this->client) && is_int($seconds)) { $this->client->timeout = $seconds; } @@ -199,7 +199,7 @@ class CI_Xmlrpc { function request($incoming) { - if (! is_array($incoming)) + if ( ! is_array($incoming)) { // Send Error } @@ -231,7 +231,7 @@ class CI_Xmlrpc { { if (is_array($value) && isset($value['0'])) { - if (! isset($value['1']) OR ! isset($this->xmlrpcTypes[strtolower($value['1'])])) + if ( ! isset($value['1']) OR ! isset($this->xmlrpcTypes[strtolower($value['1'])])) { if (is_array($value[0])) { @@ -275,12 +275,12 @@ 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)) + if ( ! $this->result = $this->client->send($this->message)) { $this->error = $this->result->errstr; return FALSE; } - elseif(! is_object($this->result->val)) + elseif( ! is_object($this->result->val)) { $this->error = $this->result->errstr; return FALSE; @@ -384,7 +384,7 @@ class XML_RPC_Client extends CI_Xmlrpc { $fp = @fsockopen($this->server, $this->port,$this->errno, $this->errstr, $this->timeout); - if (! is_resource($fp)) + if ( ! is_resource($fp)) { error_log($this->xmlrpcstr['http_error']); $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'],$this->xmlrpcstr['http_error']); @@ -406,7 +406,7 @@ class XML_RPC_Client extends CI_Xmlrpc $op .= $msg->payload; - if (!fputs($fp, $op, strlen($op))) + if ( ! fputs($fp, $op, strlen($op))) { error_log($this->xmlrpcstr['http_error']); $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']); @@ -442,7 +442,7 @@ class XML_RPC_Response $this->errno = $code; $this->errstr = htmlentities($fstr); } - else if (!is_object($val)) + else if ( ! is_object($val)) { // programmer error, not an object error_log("Invalid type '" . gettype($val) . "' (value: $val) passed to XML_RPC_Response. Defaulting to empty value."); @@ -737,7 +737,7 @@ class XML_RPC_Message extends CI_Xmlrpc // PARSE XML DATA //------------------------------------- - if (!xml_parse($parser, $data, sizeof($data))) + if ( ! xml_parse($parser, $data, sizeof($data))) { $errstr = sprintf('XML error: %s at line %d', xml_error_string(xml_get_error_code($parser)), @@ -765,7 +765,7 @@ 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; } - elseif (! is_object($this->xh[$parser]['value'])) + elseif ( ! is_object($this->xh[$parser]['value'])) { $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); return $r; @@ -862,7 +862,7 @@ class XML_RPC_Message extends CI_Xmlrpc else { // not top level element: see if parent is OK - if (!in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name], TRUE)) + if ( ! in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name], TRUE)) { $this->xh[$the_parser]['isf'] = 2; $this->xh[$the_parser]['isf_reason'] = "XML-RPC element $name cannot be child of ".$this->xh[$the_parser]['stack'][0]; @@ -961,7 +961,7 @@ class XML_RPC_Message extends CI_Xmlrpc case 'STRUCT': case 'ARRAY': $cur_val = array_shift($this->xh[$the_parser]['valuestack']); - $this->xh[$the_parser]['value'] = (! isset($cur_val['values'])) ? array() : $cur_val['values']; + $this->xh[$the_parser]['value'] = ( ! isset($cur_val['values'])) ? array() : $cur_val['values']; $this->xh[$the_parser]['vt'] = strtolower($name); break; case 'NAME': @@ -1005,7 +1005,7 @@ class XML_RPC_Message extends CI_Xmlrpc { // we have a DOUBLE // we must check that only 0123456789-. are characters here - if (! preg_match('/^[+-]?[eE0-9\t \.]+$/', $this->xh[$the_parser]['ac'])) + if ( ! preg_match('/^[+-]?[eE0-9\t \.]+$/', $this->xh[$the_parser]['ac'])) { $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND'; } @@ -1018,7 +1018,7 @@ class XML_RPC_Message extends CI_Xmlrpc { // we have an I4/INT // we must check that only 0123456789- are characters here - if (! preg_match('/^[+-]?[0-9\t ]+$/', $this->xh[$the_parser]['ac'])) + if ( ! preg_match('/^[+-]?[0-9\t ]+$/', $this->xh[$the_parser]['ac'])) { $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND'; } @@ -1101,7 +1101,7 @@ class XML_RPC_Message extends CI_Xmlrpc $this->xh[$the_parser]['lv'] = 2; // Found a value } - if(! @isset($this->xh[$the_parser]['ac'])) + if( ! @isset($this->xh[$the_parser]['ac'])) { $this->xh[$the_parser]['ac'] = ''; } @@ -1213,7 +1213,7 @@ class XML_RPC_Values extends CI_Xmlrpc { parent::CI_Xmlrpc(); - if ($val != -1 || $type != '') + if ($val != -1 OR $type != '') { $type = $type == '' ? 'string' : $type; @@ -1250,7 +1250,7 @@ class XML_RPC_Values extends CI_Xmlrpc if ($type == $this->xmlrpcBoolean) { - if (strcasecmp($val,'true')==0 || $val==1 || ($val==true && strcasecmp($val,'false'))) + if (strcasecmp($val,'true')==0 OR $val==1 OR ($val==true && strcasecmp($val,'false'))) { $val = 1; } diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 754b8ae26..a9cf19d2c 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -1,4 +1,4 @@ -methods[$methName]['function'])) + if ( ! isset($this->methods[$methName]['function'])) { return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); } @@ -265,18 +265,18 @@ class CI_Xmlrpcs extends CI_Xmlrpc if ($system_call === TRUE) { - if (! is_callable(array($this,$method_parts['1']))) + if ( ! is_callable(array($this,$method_parts['1']))) { return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); } } else { - if ($objectCall && !is_callable(array($method_parts['0'],$method_parts['1']))) + if ($objectCall && ! is_callable(array($method_parts['0'],$method_parts['1']))) { return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); } - elseif (!$objectCall && !is_callable($this->methods[$methName]['function'])) + elseif ( ! $objectCall && ! is_callable($this->methods[$methName]['function'])) { return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); } @@ -494,17 +494,17 @@ class CI_Xmlrpcs extends CI_Xmlrpc { if ($call->kindOf() != 'struct') return $this->multicall_error('notstruct'); - elseif (!$methName = $call->me['struct']['methodName']) + 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' || $scalar_type != 'string') + if ($methName->kindOf() != 'scalar' OR $scalar_type != 'string') return $this->multicall_error('notstring'); elseif ($scalar_value == 'system.multicall') return $this->multicall_error('recursion'); - elseif (!$params = $call->me['struct']['params']) + elseif ( ! $params = $call->me['struct']['params']) return $this->multicall_error('noparams'); elseif ($params->kindOf() != 'array') return $this->multicall_error('notarray'); @@ -531,6 +531,6 @@ class CI_Xmlrpcs extends CI_Xmlrpc } // END XML_RPC_Server class - -/* End of file Xmlrpcs.php */ + +/* End of file Xmlrpcs.php */ /* Location: ./system/libraries/Xmlrpcs.php */ \ No newline at end of file diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 5a24e4057..97695a07f 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -1,4 +1,4 @@ - Date: Tue, 13 May 2008 13:31:18 +0000 Subject: The Zip class has undergone a substantial re-write for speed and clarity --- system/libraries/Zip.php | 221 ++++++++++++++++++++++------------------------- 1 file changed, 101 insertions(+), 120 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 97695a07f..ed476ab48 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -32,9 +32,10 @@ */ class CI_Zip { - var $zipfile = ''; - var $zipdata = array(); - var $directory = array(); + var $zipdata = ''; + var $directory = ''; + var $entries = 0; + var $file_num = 0; var $offset = 0; function CI_Zip() @@ -61,7 +62,7 @@ class CI_Zip { { $dir .= '/'; } - + $this->_add_dir($dir); } } @@ -78,35 +79,36 @@ class CI_Zip { function _add_dir($dir) { $dir = str_replace("\\", "/", $dir); - - $this->zipdata[] = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" - .pack('V', 0) - .pack('V', 0) - .pack('V', 0) - .pack('v', strlen($dir)) - .pack('v', 0) - .$dir - .pack('V', 0) - .pack('V', 0) - .pack('V', 0); - - $newoffset = strlen(implode('', $this->zipdata)); - - $record = "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" - .pack('V',0) - .pack('V',0) - .pack('V',0) - .pack('v', strlen($dir)) - .pack('v', 0) - .pack('v', 0) - .pack('v', 0) - .pack('v', 0) - .pack('V', 16) - .pack('V', $this->offset) - .$dir; - - $this->offset = $newoffset; - $this->directory[] = $record; + + $this->zipdata .= + "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" + .pack('V', 0) // crc32 + .pack('V', 0) // compressed filesize + .pack('V', 0) // uncompressed filesize + .pack('v', strlen($dir)) // length of pathname + .pack('v', 0) // extra field length + .$dir + // below is "data descriptor" segment + .pack('V', 0) // crc32 + .pack('V', 0) // compressed filesize + .pack('V', 0); // uncompressed filesize + + $this->directory .= + "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" + .pack('V',0) // crc32 + .pack('V',0) // compressed filesize + .pack('V',0) // uncompressed filesize + .pack('v', strlen($dir)) // length of pathname + .pack('v', 0) // extra field length + .pack('v', 0) // file comment length + .pack('v', 0) // disk number start + .pack('v', 0) // internal file attributes + .pack('V', 16) // external file attributes - 'directory' bit set + .pack('V', $this->offset) // relative offset of local header + .$dir; + + $this->offset = strlen($this->zipdata); + $this->entries++; } // -------------------------------------------------------------------- @@ -137,7 +139,7 @@ class CI_Zip { $this->_add_data($filepath, $data); } } - + // -------------------------------------------------------------------- /** @@ -149,41 +151,43 @@ class CI_Zip { * @return void */ function _add_data($filepath, $data) - { + { $filepath = str_replace("\\", "/", $filepath); - - $oldlen = strlen($data); - $crc32 = crc32($data); - + + $uncompressed_size = strlen($data); + $crc32 = crc32($data); + $gzdata = gzcompress($data); $gzdata = substr($gzdata, 2, -4); - $newlen = strlen($gzdata); - - $this->zipdata[] = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" - .pack('V', $crc32) - .pack('V', $newlen) - .pack('V', $oldlen) - .pack('v', strlen($filepath)) - .pack('v', 0) - .$filepath - .$gzdata; - - $newoffset = strlen(implode("", $this->zipdata)); - - $record = "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" - .pack('V', $crc32) - .pack('V', $newlen) - .pack('V', $oldlen) - .pack('v', strlen($filepath)) - .pack('v', 0) - .pack('v', 0) - .pack('v', 0) - .pack('v', 0) - .pack('V', 32) - .pack('V', $this->offset); - - $this->offset = $newoffset; - $this->directory[] = $record.$filepath; + $compressed_size = strlen($gzdata); + + $this->zipdata .= + "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" + .pack('V', $crc32) + .pack('V', $compressed_size) + .pack('V', $uncompressed_size) + .pack('v', strlen($filepath)) // length of filename + .pack('v', 0) // extra field length + .$filepath + .$gzdata; // "file data" segment + + $this->directory .= + "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" + .pack('V', $crc32) + .pack('V', $compressed_size) + .pack('V', $uncompressed_size) + .pack('v', strlen($filepath)) // length of filename + .pack('v', 0) // extra field length + .pack('v', 0) // file comment length + .pack('v', 0) // disk number start + .pack('v', 0) // internal file attributes + .pack('V', 32) // external file attributes - 'archive' bit set + .pack('V', $this->offset) // relative offset of local header + .$filepath; + + $this->offset = strlen($this->zipdata); + $this->entries++; + $this->file_num++; } // -------------------------------------------------------------------- @@ -200,7 +204,7 @@ class CI_Zip { { return FALSE; } - + if (FALSE !== ($data = file_get_contents($path))) { $name = str_replace("\\", "/", $path); @@ -209,7 +213,7 @@ class CI_Zip { { $name = preg_replace("|.*/(.+)|", "\\1", $name); } - + $this->add_data($name, $data); return TRUE; } @@ -261,30 +265,21 @@ class CI_Zip { */ function get_zip() { - // We cache the zip data so multiple calls - // do not require recompiling - if ($this->zipfile != '') - { - return $this->zipfile; - } - // Is there any data to return? - if (count($this->zipdata) == 0) + if ($this->entries == 0) { return FALSE; } - - $data = implode('', $this->zipdata); - $dir = implode('', $this->directory); - - $this->zipfile = $data.$dir."\x50\x4b\x05\x06\x00\x00\x00\x00" - .pack('v', sizeof($this->directory)) - .pack('v', sizeof($this->directory)) - .pack('V', strlen($dir)) - .pack('V', strlen($data)) - ."\x00\x00"; - - return $this->zipfile; + + $zip_data = $this->zipdata; + $zip_data .= $this->directory."\x50\x4b\x05\x06\x00\x00\x00\x00"; + $zip_data .= pack('v', $this->entries); // total # of entries "on this disk" + $zip_data .= pack('v', $this->entries); // total # of entries overall + $zip_data .= pack('V', strlen($this->directory)); // size of central dir + $zip_data .= pack('V', strlen($this->zipdata)); // offset to start of central dir + $zip_data .= "\x00\x00"; // .zip file comment length + + return $zip_data; } // -------------------------------------------------------------------- @@ -305,7 +300,7 @@ class CI_Zip { { return FALSE; } - + flock($fp, LOCK_EX); fwrite($fp, $this->get_zip()); flock($fp, LOCK_UN); @@ -323,35 +318,20 @@ class CI_Zip { * @param string the file name * @param string the data to be encoded * @return bool - */ + */ function download($filename = 'backup.zip') { - if ( ! preg_match("|.+?\.zip$|", $filename)) - { - $filename .= '.zip'; - } - - if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) - { - header('Content-Type: application/x-zip'); - header('Content-Disposition: inline; filename="'.$filename.'"'); - header('Expires: 0'); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header("Content-Transfer-Encoding: binary"); - header('Pragma: public'); - header("Content-Length: ".strlen($this->get_zip())); - } - else - { - header('Content-Type: application/x-zip'); - header('Content-Disposition: attachment; filename="'.$filename.'"'); - header("Content-Transfer-Encoding: binary"); - header('Expires: 0'); - header('Pragma: no-cache'); - header("Content-Length: ".strlen($this->get_zip())); - } - - exit($this->get_zip()); + if ( ! preg_match("|.+?\.zip$|", $filename)) + { + $filename .= '.zip'; + } + + $zip_content =& $this->get_zip(); + + $CI =& get_instance(); + $CI->load->helper('download'); + + force_download($filename, $zip_content); } // -------------------------------------------------------------------- @@ -367,10 +347,11 @@ class CI_Zip { */ function clear_data() { - $this->zipfile = ''; - $this->zipdata = array(); - $this->directory = array(); - $this->offset = array(); + $this->zipdata = ''; + $this->directory = ''; + $this->entries = 0; + $this->file_num = 0; + $this->offset = 0; } } -- cgit v1.2.3-24-g4f1b From e3332b0ab5dfcc42994fe4c2c1827f4e41f35c7b Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 13 May 2008 14:44:32 +0000 Subject: increased security and performance of xss_clean(), added _sanitize_naughty_html() callback and removed "never allowed" items to a class property --- system/libraries/Input.php | 80 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 24 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 978d1ff34..c86a3cec0 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -32,7 +32,26 @@ class CI_Input { var $ip_address = FALSE; var $user_agent = FALSE; var $allow_get_array = FALSE; - + + /* never allowed, string replacement */ + var $never_allowed_str = array( + 'document.cookie' => '[removed]', + 'document.write' => '[removed]', + '.parentNode' => '[removed]', + '.innerHTML' => '[removed]', + 'window.location' => '[removed]', + '-moz-binding' => '[removed]', + '' => '-->', + ' '<![CDATA[' + ); + /* never allowed, regex replacement */ + var $never_allowed_regex = array( + "javascript\s*:" => '[removed]', + "expression\s*\(" => '[removed]', // CSS and IE + "Redirect\s+302" => '[removed]' + ); + /** * Constructor * @@ -663,30 +682,13 @@ class CI_Input { /* * Not Allowed Under Any Conditions */ - $bad = array( - 'document.cookie' => '[removed]', - 'document.write' => '[removed]', - '.parentNode' => '[removed]', - '.innerHTML' => '[removed]', - 'window.location' => '[removed]', - '-moz-binding' => '[removed]', - '' => '-->', - ' '<![CDATA[' - ); - - foreach ($bad as $key => $val) + + foreach ($this->never_allowed_str as $key => $val) { $str = str_replace($key, $val, $str); } - - $bad = array( - "javascript\s*:" => '[removed]', - "expression\s*\(" => '[removed]', // CSS and IE - "Redirect\s+302" => '[removed]' - ); - - foreach ($bad as $key => $val) + + foreach ($this->never_allowed_regex as $key => $val) { $str = preg_replace("#".$key."#i", $val, $str); } @@ -774,7 +776,8 @@ class CI_Input { * Becomes: <blink> * */ - $str = preg_replace('#<(/*\s*)(alert|applet|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|layer|link|meta|object|plaintext|style|script|textarea|title|xml|xss)([^>]*)>#is', "<\\1\\2\\3>", $str); + $naughty = 'alert|applet|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|layer|link|meta|object|plaintext|style|script|textarea|title|xml|xss'; + $str = preg_replace_callback('#<(/*\s*)('.$naughty.')([^><]*)([><]*)#is', array($this, '_sanitize_naughty_html'), $str); /* * Sanitize naughty scripting elements @@ -807,7 +810,7 @@ class CI_Input { '-moz-binding' => '[removed]', '' => '-->', - ' '<![CDATA[' + ' '<![CDATA[' ); foreach ($bad as $key => $val) @@ -855,7 +858,36 @@ class CI_Input { } // -------------------------------------------------------------------- + + /** + * Sanitize Naughty HTML + * + * Callback function for xss_clean() to remove naughty HTML elements + * + * @access private + * @param array + * @return string + */ + function _sanitize_naughty_html($matches) + { + // encode opening brace + $str = '<'.$matches[1].$matches[2].$matches[3]; + + // encode captured opening or closing brace to prevent recursive vectors + if ($matches[4] == '>') + { + $str .= '>'; + } + elseif ($matches[4] == '<') + { + $str .= '<'; + } + return $str; + } + + // -------------------------------------------------------------------- + /** * JS Link Removal * -- cgit v1.2.3-24-g4f1b From 000ab69f536420a0214e4d8d15898bcacf918ece Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 13 May 2008 14:46:38 +0000 Subject: Hey you! Yeah, you, that other set of hardcoded arrays in xss_clean(). You're coming with me, pal! --- system/libraries/Input.php | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index c86a3cec0..ec06101e6 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -801,30 +801,12 @@ class CI_Input { * something got through the above filters * */ - $bad = array( - 'document.cookie' => '[removed]', - 'document.write' => '[removed]', - '.parentNode' => '[removed]', - '.innerHTML' => '[removed]', - 'window.location' => '[removed]', - '-moz-binding' => '[removed]', - '' => '-->', - ' '<![CDATA[' - ); - - foreach ($bad as $key => $val) + foreach ($this->never_allowed_str as $key => $val) { $str = str_replace($key, $val, $str); } - - $bad = array( - "javascript\s*:" => '[removed]', - "expression\s*\(" => '[removed]', // CSS and IE - "Redirect\s+302" => '[removed]' - ); - - foreach ($bad as $key => $val) + + foreach ($this->never_allowed_regex as $key => $val) { $str = preg_replace("#".$key."#i", $val, $str); } -- cgit v1.2.3-24-g4f1b From 454fa7e0039689ca480eb6ef999d3fa753f5f875 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 13 May 2008 22:26:09 +0000 Subject: force closing tag on eval() for servers not running short_open_tags --- system/libraries/Loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 5e3819ea6..3346f0a2a 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -703,7 +703,7 @@ class CI_Loader { if ((bool) @ini_get('short_open_tag') === FALSE AND config_item('rewrite_short_tags') == TRUE) { - echo eval(preg_replace("/;*\s*\?>/", "; ?>", str_replace(''.preg_replace("/;*\s*\?>/", "; ?>", str_replace(' Date: Wed, 14 May 2008 21:26:35 +0000 Subject: Set the mime type check in the Upload class to reference the global mimes variable. --- system/libraries/Upload.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 1225ee36b..23e52e403 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -821,9 +821,11 @@ class CI_Upload { */ function mimes_types($mime) { + global $mimes; + if (count($this->mimes) == 0) { - if (@include(APPPATH.'config/mimes'.EXT)) + if (@require_once(APPPATH.'config/mimes'.EXT)) { $this->mimes = $mimes; unset($mimes); -- cgit v1.2.3-24-g4f1b From 63fc5fe5c6d8c9c8a2d693b0f65c3c8af8f2a74f Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 15 May 2008 20:13:14 +0000 Subject: added ability to use xss_clean() to test images, and improved security for vectors particular to the Opera family of browsers --- system/libraries/Input.php | 86 ++++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 37 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index ec06101e6..e6ac460b0 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -554,7 +554,7 @@ class CI_Input { * @param string * @return string */ - function xss_clean($str) + function xss_clean($str, $is_image = FALSE, $loops = 0) { /* * Is the string an array? @@ -569,6 +569,15 @@ class CI_Input { return $str; } + + /* + * Runaway loop prevention. If the text has had to be examined this many times + * I think it's safe to say that it is best to simply ignore it. + */ + if ($loops > 9) + { + return ''; + } /* * Remove Null Characters @@ -608,7 +617,6 @@ class CI_Input { /* * Un-Protect GET variables in URLs */ - $str = str_replace($this->xss_hash(), '&', $str); /* @@ -622,7 +630,7 @@ class CI_Input { * */ $str = rawurldecode($str); - + /* * Convert character entities to ASCII * @@ -634,35 +642,7 @@ class CI_Input { $str = preg_replace_callback("/[a-z]+=([\'\"]).*?\\1/si", array($this, '_attribute_conversion'), $str); - $str = preg_replace_callback("/<([\w]+)[^>]*>/si", array($this, '_html_entity_decode_callback'), $str); - - /* - - Old Code that when modified to use preg_replace()'s above became more efficient memory-wise - - if (preg_match_all("/[a-z]+=([\'\"]).*?\\1/si", $str, $matches)) - { - for ($i = 0; $i < count($matches[0]); $i++) - { - if (stristr($matches[0][$i], '>')) - { - $str = str_replace( $matches['0'][$i], - str_replace('>', '<', $matches[0][$i]), - $str); - } - } - } - - if (preg_match_all("/<([\w]+)[^>]*>/si", $str, $matches)) - { - for ($i = 0; $i < count($matches[0]); $i++) - { - $str = str_replace($matches[0][$i], - $this->_html_entity_decode($matches[0][$i], $charset), - $str); - } - } - */ + $str = preg_replace_callback("/<\w+.*?(?=>|<|$)/si", array($this, '_html_entity_decode_callback'), $str); /* * Convert all tabs to spaces @@ -679,6 +659,9 @@ class CI_Input { $str = str_replace("\t", ' ', $str); } + // capture for comparison at the end + $converted_string = $str; + /* * Not Allowed Under Any Conditions */ @@ -808,10 +791,39 @@ class CI_Input { foreach ($this->never_allowed_regex as $key => $val) { - $str = preg_replace("#".$key."#i", $val, $str); + $str = preg_replace("#".$key."#i", $val, $str); } + /* + * Images are Handled in a Special Way + * - Essentially, we want to know that after all of the character conversion is done whether + * any unwanted, likely XSS, code was found. If not, we return TRUE, as the image is clean. + * However, if the string post-conversion does not matched the string post-removal of XSS, + * then it fails, as there was unwanted XSS code found and removed/changed during processing. + */ + if ($is_image === TRUE) + { + if ($str == $converted_string) + { + return TRUE; + } + else + { + return FALSE; + } + } + + /* + * If something changed after character conversion, we can be fairly confident that something + * malicious was removed, so let's take no chances that the attacker is counting on specific + * mutations taking place to allow a new attack to reveal itself. So say we all. + */ + if ($converted_string != $str) + { + $str = $this->xss_clean($str, $is_image, ++$loops); + } + log_message('debug', "XSS Filtering completed"); return $str; } @@ -884,7 +896,7 @@ class CI_Input { */ function _js_link_removal($match) { - return preg_replace("#.*?#si", "", $match[0]); + return preg_replace("#.*?#si", "", $match[0]); } /** @@ -901,7 +913,7 @@ class CI_Input { */ function _js_img_removal($match) { - return preg_replace("##si", "", $match[0]); + return preg_replace("##si", "", $match[0]); } // -------------------------------------------------------------------- @@ -978,12 +990,12 @@ class CI_Input { if (function_exists('html_entity_decode') && (strtolower($charset) != 'utf-8' OR version_compare(phpversion(), '5.0.0', '>='))) { $str = html_entity_decode($str, ENT_COMPAT, $charset); - $str = preg_replace('~&#x([0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); + $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-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); + $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 -- cgit v1.2.3-24-g4f1b From 245038d6a5121f396b231d268d3ca5edac9c105a Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 15 May 2008 21:58:07 +0000 Subject: addition xss protection against certain data urls, stripping of anything sent with utf-7 encoding --- system/libraries/Input.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index e6ac460b0..c1659ab8d 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -747,6 +747,16 @@ class CI_Input { * */ $event_handlers = array('onblur','onchange','onclick','onfocus','onload','onmouseover','onmouseup','onmousedown','onselect','onsubmit','onunload','onkeypress','onkeydown','onkeyup','onresize', 'xmlns'); + + if ($is_image === TRUE) + { + /* + * 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).")([^>]*)>#iU", "<\\1\\2\\3>", $str); /* @@ -896,7 +906,7 @@ class CI_Input { */ function _js_link_removal($match) { - return preg_replace("#.*?#si", "", $match[0]); + return preg_replace("#.*?#si", "", $match[0]); } /** @@ -913,7 +923,7 @@ class CI_Input { */ function _js_img_removal($match) { - return preg_replace("##si", "", $match[0]); + return preg_replace("##si", "", $match[0]); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From ef40640f53351cea789a9657050422917f0b581f Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 16 May 2008 04:14:36 +0000 Subject: fixed regular expression in Image lib, CI bug #4542 --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index a602b4645..430369786 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -226,7 +226,7 @@ class CI_Image_lib { } // Is there a file name? - if ( ! preg_match("#[\.jpg|\.jpeg|\.gif|\.png]$#i", $full_dest_path)) + if ( ! preg_match("#\.(jpg|jpeg|gif|png)$#i", $full_dest_path)) { $this->dest_folder = $full_dest_path.'/'; $this->dest_image = $this->source_image; -- cgit v1.2.3-24-g4f1b From 5453b8e306b6d3d0ce96bfd0cb5bbbe331084bdc Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 16 May 2008 14:38:40 +0000 Subject: changed foreach() reindexing of segment arrays to array_unshift() - teensy tiny memory and speed improvement. --- system/libraries/URI.php | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 4d0cd9c17..8d979d0d2 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -246,22 +246,9 @@ class CI_URI { */ function _reindex_segments() { - $i = 1; - - foreach ($this->segments as $val) - { - $this->segments[$i++] = $val; - } - + array_unshift($this->segments, NULL); + array_unshift($this->rsegments, NULL); unset($this->segments[0]); - - $i = 1; - - foreach ($this->rsegments as $val) - { - $this->rsegments[$i++] = $val; - } - unset($this->rsegments[0]); } -- cgit v1.2.3-24-g4f1b From bd08d84525e5f9af869d3aaba92906d2047272cc Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 20 May 2008 15:07:27 +0000 Subject: improved security in xss_clean(), added
"; - $output .= "
"; - return $output; } @@ -467,8 +465,6 @@ class CI_Profiler { $output .= "\n"; $output .= ""; - $output .= ""; - return $output; } -- cgit v1.2.3-24-g4f1b From 3fff87d3c7f7374fae3c4013d4ba1c7ba10f17be Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 7 Apr 2010 14:23:01 -0500 Subject: Fixing typo in XMLRpc error message: http://codeigniter.com/bug_tracker/bug/11556/ --- system/libraries/Xmlrpc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 2e0df5c9b..ee04400f5 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -112,7 +112,7 @@ class CI_Xmlrpc { $this->xmlrpcerr['unknown_method'] = '1'; $this->xmlrpcstr['unknown_method'] = 'This is not a known method for this XML-RPC Server'; $this->xmlrpcerr['invalid_return'] = '2'; - $this->xmlrpcstr['invalid_return'] = 'The XML data receieved was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.'; + $this->xmlrpcstr['invalid_return'] = 'The XML data received was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.'; $this->xmlrpcerr['incorrect_params'] = '3'; $this->xmlrpcstr['incorrect_params'] = 'Incorrect parameters were passed to method'; $this->xmlrpcerr['introspect_unknown'] = '4'; -- cgit v1.2.3-24-g4f1b From ef88a906ed8b2050f4c6e6d8fbd73cc5b6adc7a3 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 14 Apr 2010 18:22:23 -0500 Subject: Removing deprecated Validation class. Form_validation going forward! Removed references to the validation classes documentation page in the changelog as well. --- system/libraries/Validation.php | 875 ---------------------------------------- 1 file changed, 875 deletions(-) delete mode 100644 system/libraries/Validation.php (limited to 'system/libraries') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php deleted file mode 100644 index a42b7760b..000000000 --- a/system/libraries/Validation.php +++ /dev/null @@ -1,875 +0,0 @@ -'; - var $_error_suffix = '

'; - - - - /** - * Constructor - * - */ - function CI_Validation() - { - $this->CI =& get_instance(); - - if (function_exists('mb_internal_encoding')) - { - mb_internal_encoding($this->CI->config->item('charset')); - } - - log_message('debug', "Validation Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Set Fields - * - * This function takes an array of field names as input - * and generates class variables with the same name, which will - * either be blank or contain the $_POST value corresponding to it - * - * @access public - * @param string - * @param string - * @return void - */ - function set_fields($data = '', $field = '') - { - if ($data == '') - { - if (count($this->_fields) == 0) - { - return FALSE; - } - } - else - { - if ( ! is_array($data)) - { - $data = array($data => $field); - } - - if (count($data) > 0) - { - $this->_fields = $data; - } - } - - foreach($this->_fields as $key => $val) - { - $this->$key = ( ! isset($_POST[$key])) ? '' : $this->prep_for_form($_POST[$key]); - - $error = $key.'_error'; - if ( ! isset($this->$error)) - { - $this->$error = ''; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Set Rules - * - * This function takes an array of field names and validation - * rules as input ad simply stores is for use later. - * - * @access public - * @param mixed - * @param string - * @return void - */ - function set_rules($data, $rules = '') - { - if ( ! is_array($data)) - { - if ($rules == '') - return; - - $data = array($data => $rules); - } - - foreach ($data as $key => $val) - { - $this->_rules[$key] = $val; - } - } - - // -------------------------------------------------------------------- - - /** - * Set Error Message - * - * Lets users set their own error messages on the fly. Note: The key - * name has to match the function name that it corresponds to. - * - * @access public - * @param string - * @param string - * @return string - */ - function set_message($lang, $val = '') - { - if ( ! is_array($lang)) - { - $lang = array($lang => $val); - } - - $this->_error_messages = array_merge($this->_error_messages, $lang); - } - - // -------------------------------------------------------------------- - - /** - * Set The Error Delimiter - * - * Permits a prefix/suffix to be added to each error message - * - * @access public - * @param string - * @param string - * @return void - */ - function set_error_delimiters($prefix = '

', $suffix = '

') - { - $this->_error_prefix = $prefix; - $this->_error_suffix = $suffix; - } - - // -------------------------------------------------------------------- - - /** - * Run the Validator - * - * This function does all the work. - * - * @access public - * @return bool - */ - function run() - { - // Do we even have any data to process? Mm? - if (count($_POST) == 0 OR count($this->_rules) == 0) - { - return FALSE; - } - - // Load the language file containing error messages - $this->CI->lang->load('validation'); - - // Cycle through the rules and test for errors - foreach ($this->_rules as $field => $rules) - { - //Explode out the rules! - $ex = explode('|', $rules); - - // Is the field required? If not, if the field is blank we'll move on to the next test - if ( ! in_array('required', $ex, TRUE)) - { - if ( ! isset($_POST[$field]) OR $_POST[$field] == '') - { - continue; - } - } - - /* - * Are we dealing with an "isset" rule? - * - * Before going further, we'll see if one of the rules - * is to check whether the item is set (typically this - * applies only to checkboxes). If so, we'll - * test for it here since there's not reason to go - * further - */ - if ( ! isset($_POST[$field])) - { - if (in_array('isset', $ex, TRUE) OR in_array('required', $ex)) - { - if ( ! isset($this->_error_messages['isset'])) - { - if (FALSE === ($line = $this->CI->lang->line('isset'))) - { - $line = 'The field was not set'; - } - } - else - { - $line = $this->_error_messages['isset']; - } - - // Build the error message - $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; - $message = sprintf($line, $mfield); - - // Set the error variable. Example: $this->username_error - $error = $field.'_error'; - $this->$error = $this->_error_prefix.$message.$this->_error_suffix; - $this->_error_array[] = $message; - } - - continue; - } - - /* - * Set the current field - * - * The various prepping functions need to know the - * current field name so they can do this: - * - * $_POST[$this->_current_field] == 'bla bla'; - */ - $this->_current_field = $field; - - // Cycle through the rules! - foreach ($ex As $rule) - { - // 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; - if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match)) - { - $rule = $match[1]; - $param = $match[2]; - } - - // Call the function that corresponds to the rule - if ($callback === TRUE) - { - if ( ! method_exists($this->CI, $rule)) - { - continue; - } - - $result = $this->CI->$rule($_POST[$field], $param); - - // If the field isn't required and we just processed a callback we'll move on... - if ( ! in_array('required', $ex, TRUE) AND $result !== FALSE) - { - continue 2; - } - - } - else - { - if ( ! method_exists($this, $rule)) - { - /* - * Run the native PHP function if called for - * - * 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)) - { - $_POST[$field] = $rule($_POST[$field]); - $this->$field = $_POST[$field]; - } - - continue; - } - - $result = $this->$rule($_POST[$field], $param); - } - - // 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]; - } - - // Build the error message - $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; - $mparam = ( ! isset($this->_fields[$param])) ? $param : $this->_fields[$param]; - $message = sprintf($line, $mfield, $mparam); - - // Set the error variable. Example: $this->username_error - $error = $field.'_error'; - $this->$error = $this->_error_prefix.$message.$this->_error_suffix; - - // Add the error to the error array - $this->_error_array[] = $message; - continue 2; - } - } - - } - - $total_errors = count($this->_error_array); - - /* - * Recompile the class variables - * - * If any prepping functions were called the $_POST data - * might now be different then the corresponding class - * variables so we'll set them anew. - */ - if ($total_errors > 0) - { - $this->_safe_form_data = TRUE; - } - - $this->set_fields(); - - // Did we end up with any errors? - if ($total_errors == 0) - { - return TRUE; - } - - // Generate the error string - foreach ($this->_error_array as $val) - { - $this->error_string .= $this->_error_prefix.$val.$this->_error_suffix."\n"; - } - - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Required - * - * @access public - * @param string - * @return bool - */ - function required($str) - { - if ( ! is_array($str)) - { - return (trim($str) == '') ? FALSE : TRUE; - } - else - { - return ( ! empty($str)); - } - } - - // -------------------------------------------------------------------- - - /** - * Match one field to another - * - * @access public - * @param string - * @param field - * @return bool - */ - function matches($str, $field) - { - if ( ! isset($_POST[$field])) - { - return FALSE; - } - - return ($str !== $_POST[$field]) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Minimum Length - * - * @access public - * @param string - * @param value - * @return bool - */ - function min_length($str, $val) - { - if (preg_match("/[^0-9]/", $val)) - { - return FALSE; - } - - if (function_exists('mb_strlen')) - { - return (mb_strlen($str) < $val) ? FALSE : TRUE; - } - - return (strlen($str) < $val) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Max Length - * - * @access public - * @param string - * @param value - * @return bool - */ - function max_length($str, $val) - { - if (preg_match("/[^0-9]/", $val)) - { - return FALSE; - } - - if (function_exists('mb_strlen')) - { - return (mb_strlen($str) > $val) ? FALSE : TRUE; - } - - return (strlen($str) > $val) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Exact Length - * - * @access public - * @param string - * @param value - * @return bool - */ - function exact_length($str, $val) - { - if (preg_match("/[^0-9]/", $val)) - { - return FALSE; - } - - if (function_exists('mb_strlen')) - { - 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) - { - return FALSE; - } - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Validate IP Address - * - * @access public - * @param string - * @return string - */ - function valid_ip($ip) - { - return $this->CI->input->valid_ip($ip); - } - - // -------------------------------------------------------------------- - - /** - * 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); - - } - - // -------------------------------------------------------------------- - - /** - * 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, 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; - } - - // -------------------------------------------------------------------- - - /** - * Valid Base64 - * - * Tests a string for characters outside of the Base64 alphabet - * as defined by RFC 2045 http://www.faqs.org/rfcs/rfc2045 - * - * @access public - * @param string - * @return bool - */ - function valid_base64($str) - { - return (bool) ! preg_match('/[^a-zA-Z0-9\/\+=]/', $str); - } - - // -------------------------------------------------------------------- - - /** - * Set Select - * - * Enables pull-down lists to be set to the value the user - * selected in the event of an error - * - * @access public - * @param string - * @param string - * @return string - */ - function set_select($field = '', $value = '') - { - if ($field == '' OR $value == '' OR ! isset($_POST[$field])) - { - return ''; - } - - if ($_POST[$field] == $value) - { - return ' selected="selected"'; - } - } - - // -------------------------------------------------------------------- - - /** - * Set Radio - * - * Enables radio buttons to be set to the value the user - * selected in the event of an error - * - * @access public - * @param string - * @param string - * @return string - */ - function set_radio($field = '', $value = '') - { - if ($field == '' OR $value == '' OR ! isset($_POST[$field])) - { - return ''; - } - - if ($_POST[$field] == $value) - { - return ' checked="checked"'; - } - } - - // -------------------------------------------------------------------- - - /** - * Set Checkbox - * - * Enables checkboxes to be set to the value the user - * selected in the event of an error - * - * @access public - * @param string - * @param string - * @return string - */ - function set_checkbox($field = '', $value = '') - { - if ($field == '' OR $value == '' OR ! isset($_POST[$field])) - { - return ''; - } - - if ($_POST[$field] == $value) - { - return ' checked="checked"'; - } - } - - // -------------------------------------------------------------------- - - /** - * Prep data for form - * - * This function allows HTML to be safely shown in a form. - * Special characters are converted. - * - * @access public - * @param string - * @return string - */ - function prep_for_form($data = '') - { - if (is_array($data)) - { - foreach ($data as $key => $val) - { - $data[$key] = $this->prep_for_form($val); - } - - return $data; - } - - if ($this->_safe_form_data == FALSE OR $data == '') - { - return $data; - } - - return str_replace(array("'", '"', '<', '>'), array("'", """, '<', '>'), stripslashes($data)); - } - - // -------------------------------------------------------------------- - - /** - * Prep URL - * - * @access public - * @param string - * @return string - */ - function prep_url($str = '') - { - if ($str == 'http://' OR $str == '') - { - $_POST[$this->_current_field] = ''; - return; - } - - if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') - { - $str = 'http://'.$str; - } - - $_POST[$this->_current_field] = $str; - } - - // -------------------------------------------------------------------- - - /** - * Strip Image Tags - * - * @access public - * @param string - * @return string - */ - function strip_image_tags($str) - { - $_POST[$this->_current_field] = $this->CI->input->strip_image_tags($str); - } - - // -------------------------------------------------------------------- - - /** - * XSS Clean - * - * @access public - * @param string - * @return string - */ - function xss_clean($str) - { - $_POST[$this->_current_field] = $this->CI->input->xss_clean($str); - } - - // -------------------------------------------------------------------- - - /** - * Convert PHP tags to entities - * - * @access public - * @param string - * @return string - */ - function encode_php_tags($str) - { - $_POST[$this->_current_field] = str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); - } - -} -// END Validation Class - -/* End of file Validation.php */ -/* Location: ./system/libraries/Validation.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 757dda61aa0556aca8172dc2a8175596afe28ce2 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 14 Apr 2010 19:06:19 -0500 Subject: Fixing a bug where odbc/mssql/oci8 db drivers would encounter a PHP error due to a function being moved from the input to security class. Moving remove_invisible_characters() to Common.php so the entire class does not need to be instantiated in those database drivers. --- system/libraries/Security.php | 42 ++---------------------------------------- 1 file changed, 2 insertions(+), 40 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Security.php b/system/libraries/Security.php index 60adf0a27..cdae50168 100644 --- a/system/libraries/Security.php +++ b/system/libraries/Security.php @@ -198,7 +198,7 @@ class CI_Security { /* * Remove Invisible Characters */ - $str = $this->_remove_invisible_characters($str); + $str = remove_invisible_characters($str); /* * Protect GET variables in URLs @@ -258,7 +258,7 @@ class CI_Security { /* * Remove Invisible Characters Again! */ - $str = $this->_remove_invisible_characters($str); + $str = remove_invisible_characters($str); /* * Convert all tabs to spaces @@ -480,44 +480,6 @@ class CI_Security { // -------------------------------------------------------------------- - /** - * Remove Invisible Characters - * - * This prevents sandwiching null characters - * between ascii characters, like Java\0script. - * - * @access public - * @param string - * @return string - */ - 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), - $non_displayables = array( - '/%0[0-8bcef]/', // url encoded 00-08, 11, 12, 14, 15 - '/%1[0-9a-f]/', // url encoded 16-31 - '/[\x00-\x08]/', // 00-08 - '/\x0b/', '/\x0c/', // 11, 12 - '/[\x0e-\x1f]/' // 14-31 - ); - } - - do - { - $cleaned = $str; - $str = preg_replace($non_displayables, '', $str); - } - while ($cleaned != $str); - - return $str; - } - - // -------------------------------------------------------------------- - /** * Compact Exploded Words * -- cgit v1.2.3-24-g4f1b From f82e51cd8f46b112c3c400d43db9044854a8e805 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 14 Apr 2010 19:33:50 -0500 Subject: Update to File Upload library to return boolean on do_xss_clean(). --- system/libraries/Upload.php | 61 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 13 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index ac9323c08..3131469de 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -276,9 +276,13 @@ class CI_Upload { * embedded within a file. Scripts can easily * be disguised as images or other file types. */ - if ($this->xss_clean == TRUE) + if ($this->xss_clean) { - $this->do_xss_clean(); + if ($this->do_xss_clean() === FALSE) + { + $this->set_error('upload_unable_to_write_file'); + return FALSE; + } } /* @@ -803,24 +807,55 @@ class CI_Upload { { 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($this->new_name) + $current), 0, '.', ''); + + ini_set('memory_limit', $new_memory); // When an integer is used, the value is measured in bytes. - PHP.net + } - if (($data = @file_get_contents($file)) === FALSE) + // If the file being uploaded is an image, then we should have no problem with XSS attacks (in theory), but + // 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 + // attempted XSS attack. + + if (function_exists('getimagesize') && @getimagesize($file) !== FALSE) { - return FALSE; + 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); + + // These are known to throw IE into mime-type detection chaos + // ]/i', $opening_bytes)) + { + return TRUE; // its an image, no "triggers" detected in the first 256 bytes, we're good + } } - - if ( ! $fp = @fopen($file, FOPEN_READ_WRITE)) + + if (($data = @file_get_contents($file)) === FALSE) { return FALSE; } - $CI =& get_instance(); - $data = $CI->security->xss_clean($data); - - flock($fp, LOCK_EX); - fwrite($fp, $data); - flock($fp, LOCK_UN); - fclose($fp); + $CI =& get_instance(); + + return $CI->security->xss_clean($data, TRUE); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From ff3ecaede7e7154d1897307a390919b655b15096 Mon Sep 17 00:00:00 2001 From: Robin Sowell Date: Fri, 16 Apr 2010 16:13:23 -0400 Subject: Added class var xss_clean to the XML_RPC_Response class to prevent php error. Not noted in changelog, as I figure it's covered by the original note about adding xss clean at all. --- system/libraries/Xmlrpc.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system/libraries') diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index ee04400f5..e2b149b73 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -434,6 +434,7 @@ class XML_RPC_Response var $errno = 0; var $errstr = ''; var $headers = array(); + var $xss_clean = TRUE; function XML_RPC_Response($val, $code = 0, $fstr = '') { -- cgit v1.2.3-24-g4f1b From 47cd452c91a3dc7dab4a8285136bee2048fc7bba Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Thu, 22 Apr 2010 12:34:13 +0100 Subject: Fixed Upload bug that would break when files and images were both included on an allowed filetype list in the wrong order: http://codeigniter.com/bug_tracker/bug/11552/ --- system/libraries/Upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 3131469de..0e71aee6b 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -578,7 +578,7 @@ class CI_Upload { $mime = $this->mimes_types(strtolower($val)); // Images get some additional checks - if (in_array($val, $image_types)) + if ($this->file_ext == '.' . $val && in_array($val, $image_types)) { if (getimagesize($this->file_temp) === FALSE) { -- cgit v1.2.3-24-g4f1b From 52c592bb08ad5fbc4ded7aedaa81e2f3fb329b8c Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 22 Apr 2010 16:36:40 -0500 Subject: tiny modification to whitespace from philsturgeon's bugfix to match CI style guidelines --- system/libraries/Upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 0e71aee6b..b85663bcc 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -578,7 +578,7 @@ class CI_Upload { $mime = $this->mimes_types(strtolower($val)); // Images get some additional checks - if ($this->file_ext == '.' . $val && in_array($val, $image_types)) + if ($this->file_ext == '.'.$val && in_array($val, $image_types)) { if (getimagesize($this->file_temp) === FALSE) { -- cgit v1.2.3-24-g4f1b From dcae4490998dc111d265da11507c0dad660eb1b4 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Thu, 22 Apr 2010 13:34:09 +0100 Subject: Some mime types are wrapped with " which breaks file type checking. This will remove any wrapping \ and " --- system/libraries/Upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index b85663bcc..751044968 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -190,7 +190,7 @@ class CI_Upload { $this->file_name = $this->_prep_filename($_FILES[$field]['name']); $this->file_size = $_FILES[$field]['size']; $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']); - $this->file_type = strtolower($this->file_type); + $this->file_type = trim(stripslashes($this->file_type), '"'); $this->file_ext = $this->get_extension($_FILES[$field]['name']); // Convert the file size to kilobytes -- cgit v1.2.3-24-g4f1b From 616fb0281ba4bd2339accc47c0a94f7034c61a1a Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 22 Apr 2010 16:52:18 -0500 Subject: reapplied strtolower() to ->file_type from philsturgeon's changeset 5fe3b04bdf44 to standardize input --- system/libraries/Upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 751044968..3227c3747 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -190,7 +190,7 @@ class CI_Upload { $this->file_name = $this->_prep_filename($_FILES[$field]['name']); $this->file_size = $_FILES[$field]['size']; $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']); - $this->file_type = trim(stripslashes($this->file_type), '"'); + $this->file_type = strtolower(trim(stripslashes($this->file_type), '"')); $this->file_ext = $this->get_extension($_FILES[$field]['name']); // Convert the file size to kilobytes -- cgit v1.2.3-24-g4f1b From 5640a7158559f4521911444b50798a6a9536f38b Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 23 Apr 2010 11:22:40 -0500 Subject: ensured the security lib was loaded in a few calls to xss_clean() in other libraries. Fixes #35 --- system/libraries/Form_validation.php | 7 ++++++- system/libraries/Upload.php | 7 ++++++- system/libraries/Xmlrpc.php | 10 ++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index bb70f0f7f..73cb6b853 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -1254,7 +1254,12 @@ class CI_Form_validation { */ function xss_clean($str) { - return $this->CI->input->xss_clean($str); + if ( ! is_object($this->CI->security)) + { + $this->CI->load('security'); + } + + return $this->CI->security->xss_clean($str); } // -------------------------------------------------------------------- diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 3227c3747..d7cf236f8 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -854,7 +854,12 @@ class CI_Upload { } $CI =& get_instance(); - + + if ( ! is_object($CI->security)) + { + $CI->load('security'); + } + return $CI->security->xss_clean($data, TRUE); } diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index e2b149b73..ee65398ec 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -505,6 +505,11 @@ class XML_RPC_Response { $CI =& get_instance(); + if ($this->xss_clean && ! is_object($CI->security)) + { + $CI->load('security'); + } + if ($array !== FALSE && is_array($array)) { while (list($key) = each($array)) @@ -1119,6 +1124,11 @@ class XML_RPC_Message extends CI_Xmlrpc { $CI =& get_instance(); + if ($this->xss_clean && ! is_object($CI->security)) + { + $CI->load('security'); + } + if ($array !== FALSE && is_array($array)) { while (list($key) = each($array)) -- cgit v1.2.3-24-g4f1b From 30841679f57da9de8053c8291a665043f8f92c03 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 26 Apr 2010 09:09:21 -0500 Subject: fixed errant syntax in changeset 53ace78c4b45, fixes #37 --- system/libraries/Form_validation.php | 6 +++--- system/libraries/Upload.php | 2 +- system/libraries/Xmlrpc.php | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 73cb6b853..64baaef25 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -1254,11 +1254,11 @@ class CI_Form_validation { */ function xss_clean($str) { - if ( ! is_object($this->CI->security)) + if ( ! isset($this->CI->security)) { - $this->CI->load('security'); + $this->CI->load->library('security'); } - + return $this->CI->security->xss_clean($str); } diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index d7cf236f8..b3c625eb1 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -855,7 +855,7 @@ class CI_Upload { $CI =& get_instance(); - if ( ! is_object($CI->security)) + if ( ! isset($CI->security)) { $CI->load('security'); } diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index ee65398ec..ff03a503a 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -505,9 +505,9 @@ class XML_RPC_Response { $CI =& get_instance(); - if ($this->xss_clean && ! is_object($CI->security)) + if ($this->xss_clean && ! isset($CI->security)) { - $CI->load('security'); + $CI->load->library('security'); } if ($array !== FALSE && is_array($array)) @@ -1124,9 +1124,9 @@ class XML_RPC_Message extends CI_Xmlrpc { $CI =& get_instance(); - if ($this->xss_clean && ! is_object($CI->security)) + if ($this->xss_clean && ! isset($CI->security)) { - $CI->load('security'); + $CI->load->library('security'); } if ($array !== FALSE && is_array($array)) -- cgit v1.2.3-24-g4f1b From 247f02925e04a8a45f2e6e9acbf72ccd6848fd32 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 26 Apr 2010 09:10:21 -0500 Subject: fixed errant syntax in changeset 53ace78c4b45, fixes #37 --- system/libraries/Upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index b3c625eb1..7a5eef0f3 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -857,7 +857,7 @@ class CI_Upload { if ( ! isset($CI->security)) { - $CI->load('security'); + $CI->load->library('security'); } return $CI->security->xss_clean($data, TRUE); -- cgit v1.2.3-24-g4f1b From e602683aa6362e2efeb03408cea749cfeaaeef4f Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 29 Apr 2010 13:41:39 -0500 Subject: Changing order of available sections in the output profiler. --- system/libraries/Profiler.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 3285bc531..49a6774c1 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -36,14 +36,14 @@ class CI_Profiler { var $_available_sections = array( 'benchmarks', - 'config', - 'controller_info', 'get', - 'http_headers', 'memory_usage', 'post', + 'uri_string', + 'controller_info', 'queries', - 'uri_string' + 'http_headers', + 'config' ); function CI_Profiler($config = array()) @@ -459,6 +459,11 @@ class CI_Profiler { foreach($this->CI->config->config as $config=>$val) { + if (is_array($val)) + { + $val = print_r($val, TRUE); + } + $output .= "".$config."  ".$val."\n"; } -- cgit v1.2.3-24-g4f1b From 26872de184e4aa2ae92bae645782089e9656115d Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Tue, 11 May 2010 11:41:59 +0100 Subject: Added an option to remove the preceding trail of empty folders when creating a Zip archive. --- system/libraries/Zip.php | 49 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 2c4bd255d..3ba3ddc83 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -270,27 +270,48 @@ class CI_Zip { * @access public * @param string path to source * @return bool - */ - function read_dir($path) - { - if ($fp = @opendir($path)) + */ + function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL) + { + if (!$fp = @opendir($path)) + { + return FALSE; + } + + // Set the original directory root for child dir's to use as relative + if ($root_path === NULL) + { + $root_path = dirname($path).'/'; + } + + while (FALSE !== ($file = readdir($fp))) { - while (FALSE !== ($file = readdir($fp))) + if(substr($file, 0, 1) == '.') { - if (@is_dir($path.$file) && substr($file, 0, 1) != '.') - { - $this->read_dir($path.$file."/"); - } - elseif (substr($file, 0, 1) != ".") + continue; + } + + if (@is_dir($path.$file)) + { + $this->read_dir($path.$file."/", $preserve_filepath, $root_path); + } + + else + { + if (FALSE !== ($data = file_get_contents($path.$file))) { - if (FALSE !== ($data = file_get_contents($path.$file))) - { - $this->add_data(str_replace("\\", "/", $path).$file, $data); + $name = str_replace("\\", "/", $path); + + if ($preserve_filepath === FALSE) + { + $name = str_replace($root_path, '', $name); } + + $this->add_data($name.$file, $data); } } - return TRUE; } + return TRUE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 2735b3eeb3403ba813aac56ed6f10be536839ff6 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 11 May 2010 08:58:21 -0500 Subject: fixed whitespace, massaged Zip read_dir() docs --- system/libraries/Zip.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 3ba3ddc83..92dfc814d 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -273,7 +273,7 @@ class CI_Zip { */ function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL) { - if (!$fp = @opendir($path)) + if ( ! $fp = @opendir($path)) { return FALSE; } @@ -295,7 +295,6 @@ class CI_Zip { { $this->read_dir($path.$file."/", $preserve_filepath, $root_path); } - else { if (FALSE !== ($data = file_get_contents($path.$file))) @@ -311,6 +310,7 @@ class CI_Zip { } } } + return TRUE; } -- cgit v1.2.3-24-g4f1b From 511e3d72b875401b5cc61a28df45fb65acfd689a Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 13 May 2010 09:03:30 -0500 Subject: added htmlspecialchars to config item output, fixes #41 --- system/libraries/Profiler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 49a6774c1..0900a300d 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -303,7 +303,7 @@ class CI_Profiler { $output .= "$_POST[".$key."]   "; if (is_array($val)) { - $output .= "
" . htmlspecialchars(stripslashes(print_r($val, true))) . "
"; + $output .= "
" . htmlspecialchars(stripslashes(print_r($val, TRUE))) . "
"; } else { @@ -464,7 +464,7 @@ class CI_Profiler { $val = print_r($val, TRUE); } - $output .= "".$config."  ".$val."\n"; + $output .= "".$config."  ".htmlspecialchars($val)."\n"; } $output .= "\n"; -- cgit v1.2.3-24-g4f1b From 23e796f7561832a929c1a78c1fb60667563b0756 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 21 May 2010 12:45:25 -0500 Subject: fixed a bug in the Parser where the regex would not correctly match pair variables, fixes #42 --- system/libraries/Parser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 9387f1a9a..41a438bac 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -197,7 +197,7 @@ class CI_Parser { */ function _match_pair($string, $variable) { - if ( ! preg_match("|" . preg_quote($this->l_delim) . $variable . preg_quote($this->r_delim) . "(.+?) ". preg_quote($this->l_delim) . '/' . $variable . preg_quote($this->r_delim) . "|s", $string, $match)) + if ( ! preg_match("|" . preg_quote($this->l_delim) . $variable . preg_quote($this->r_delim) . "(.+?)". preg_quote($this->l_delim) . '/' . $variable . preg_quote($this->r_delim) . "|s", $string, $match)) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 2a6c1da49b38abb8767192a064b8c6b01d1e421e Mon Sep 17 00:00:00 2001 From: Robin Sowell Date: Mon, 24 May 2010 12:20:03 -0400 Subject: Added $prefix, $suffix and $first_url properties to Pagination library. --- system/libraries/Pagination.php | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index d6321f41c..ccd3e8261 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -27,6 +27,9 @@ class CI_Pagination { var $base_url = ''; // The page we are linking to + 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 $num_links = 2; // Number of "digit" links to show before/after the currently viewed page @@ -42,6 +45,7 @@ class CI_Pagination { var $first_tag_close = ' '; var $last_tag_open = ' '; var $last_tag_close = ''; + var $first_url = ''; // Alternative URL for the First Page. var $cur_tag_open = ' '; var $cur_tag_close = ''; var $next_tag_open = ' '; @@ -185,15 +189,25 @@ class CI_Pagination { // Render the "First" link if ($this->cur_page > ($this->num_links + 1)) { - $output .= $this->first_tag_open.'
'.$this->first_link.''.$this->first_tag_close; + $first_url = ($this->first_url == '') ? $this->base_url : $this->first_url; + $output .= $this->first_tag_open.''.$this->first_link.''.$this->first_tag_close; } // Render the "previous" link if ($this->cur_page != 1) { $i = $uri_page_number - $this->per_page; - if ($i == 0) $i = ''; - $output .= $this->prev_tag_open.''.$this->prev_link.''.$this->prev_tag_close; + + if ($i == 0 && $this->first_url != '') + { + $output .= $this->prev_tag_open.''.$this->prev_link.''.$this->prev_tag_close; + } + else + { + $i = ($i == 0) ? '' : $this->prefix.$i.$this->suffix; + $output .= $this->prev_tag_open.''.$this->prev_link.''.$this->prev_tag_close; + } + } // Write the digit links @@ -210,7 +224,17 @@ class CI_Pagination { else { $n = ($i == 0) ? '' : $i; - $output .= $this->num_tag_open.''.$loop.''.$this->num_tag_close; + + if ($n == '' && $this->first_url != '') + { + $output .= $this->num_tag_open.''.$loop.''.$this->num_tag_close; + } + else + { + $n = ($n == '') ? '' : $this->prefix.$n.$this->suffix; + + $output .= $this->num_tag_open.''.$loop.''.$this->num_tag_close; + } } } } @@ -218,14 +242,14 @@ class CI_Pagination { // Render the "next" link if ($this->cur_page < $num_pages) { - $output .= $this->next_tag_open.''.$this->next_link.''.$this->next_tag_close; + $output .= $this->next_tag_open.''.$this->next_link.''.$this->next_tag_close; } // Render the "Last" link if (($this->cur_page + $this->num_links) < $num_pages) { $i = (($num_pages * $this->per_page) - $this->per_page); - $output .= $this->last_tag_open.''.$this->last_link.''.$this->last_tag_close; + $output .= $this->last_tag_open.''.$this->last_link.''.$this->last_tag_close; } // Kill double slashes. Note: Sometimes we can end up with a double slash -- cgit v1.2.3-24-g4f1b From c78a259b4af7430f237636b5f93d6eb59443a1e2 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 9 Jun 2010 11:45:32 -0500 Subject: Fixed an undefined variable PHP error in the do_xss_clean() method of the Upload library. --- system/libraries/Upload.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 7a5eef0f3..8bdb4be19 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -812,13 +812,13 @@ class CI_Upload { { $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($this->new_name) + $current), 0, '.', ''); - - ini_set('memory_limit', $new_memory); // When an integer is used, the value is measured in bytes. - PHP.net + // 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 } // If the file being uploaded is an image, then we should have no problem with XSS attacks (in theory), but -- cgit v1.2.3-24-g4f1b From 96bb75cd4e9b1cbd82fe7496e9b831054c8228f1 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 5 Jul 2010 10:54:30 -0400 Subject: Added the ability to suppress first, previous, next and last links by setting their values to FALSE in the pagination library. --- system/libraries/Pagination.php | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index ccd3e8261..68c35a57e 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -56,6 +56,7 @@ class CI_Pagination { var $num_tag_close = ''; var $page_query_string = FALSE; var $query_string_segment = 'per_page'; + var $anchor_class = ''; /** * Constructor @@ -70,6 +71,11 @@ class CI_Pagination { $this->initialize($params); } + if ($this->anchor_class != '') + { + $this->anchor_class = 'class="'.$this->anchor_class.'" '; + } + log_message('debug', "Pagination Class Initialized"); } @@ -187,25 +193,25 @@ class CI_Pagination { $output = ''; // Render the "First" link - if ($this->cur_page > ($this->num_links + 1)) + if ($this->first_link !== FALSE AND $this->cur_page > ($this->num_links + 1)) { $first_url = ($this->first_url == '') ? $this->base_url : $this->first_url; - $output .= $this->first_tag_open.''.$this->first_link.''.$this->first_tag_close; + $output .= $this->first_tag_open.'anchor_class.'href="'.$first_url.'">'.$this->first_link.''.$this->first_tag_close; } // Render the "previous" link - if ($this->cur_page != 1) + 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.''.$this->prev_link.''.$this->prev_tag_close; + $output .= $this->prev_tag_open.'anchor_class.'href="'.$this->first_url.'">'.$this->prev_link.''.$this->prev_tag_close; } else { $i = ($i == 0) ? '' : $this->prefix.$i.$this->suffix; - $output .= $this->prev_tag_open.''.$this->prev_link.''.$this->prev_tag_close; + $output .= $this->prev_tag_open.'anchor_class.'href="'.$this->base_url.$i.'">'.$this->prev_link.''.$this->prev_tag_close; } } @@ -227,29 +233,29 @@ class CI_Pagination { if ($n == '' && $this->first_url != '') { - $output .= $this->num_tag_open.''.$loop.''.$this->num_tag_close; + $output .= $this->num_tag_open.'anchor_class.'href="'.$this->first_url.'">'.$loop.''.$this->num_tag_close; } else { $n = ($n == '') ? '' : $this->prefix.$n.$this->suffix; - $output .= $this->num_tag_open.''.$loop.''.$this->num_tag_close; + $output .= $this->num_tag_open.'anchor_class.'href="'.$this->base_url.$n.'">'.$loop.''.$this->num_tag_close; } } } } // Render the "next" link - if ($this->cur_page < $num_pages) + if ($this->next_link !== FALSE AND $this->cur_page < $num_pages) { - $output .= $this->next_tag_open.''.$this->next_link.''.$this->next_tag_close; + $output .= $this->next_tag_open.'anchor_class.'href="'.$this->base_url.$this->prefix.($this->cur_page * $this->per_page).$this->suffix.'">'.$this->next_link.''.$this->next_tag_close; } // Render the "Last" link - if (($this->cur_page + $this->num_links) < $num_pages) + if ($this->last_link !== FALSE AND ($this->cur_page + $this->num_links) < $num_pages) { $i = (($num_pages * $this->per_page) - $this->per_page); - $output .= $this->last_tag_open.''.$this->last_link.''.$this->last_tag_close; + $output .= $this->last_tag_open.'anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->last_link.''.$this->last_tag_close; } // Kill double slashes. Note: Sometimes we can end up with a double slash -- cgit v1.2.3-24-g4f1b From e01fd0fc3b694d12dc6b968727bd7f21f8c1a0fb Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 5 Jul 2010 11:06:07 -0400 Subject: suppress page list --- system/libraries/Pagination.php | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 68c35a57e..3a0632d09 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -56,6 +56,7 @@ class CI_Pagination { var $num_tag_close = ''; var $page_query_string = FALSE; var $query_string_segment = 'per_page'; + var $display_pages = TRUE; var $anchor_class = ''; /** @@ -216,30 +217,34 @@ class CI_Pagination { } - // Write the digit links - for ($loop = $start -1; $loop <= $end; $loop++) + // Render the pages + if ($this->display_pages !== FALSE) { - $i = ($loop * $this->per_page) - $this->per_page; - - if ($i >= 0) + // Write the digit links + for ($loop = $start -1; $loop <= $end; $loop++) { - if ($this->cur_page == $loop) - { - $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page - } - else + $i = ($loop * $this->per_page) - $this->per_page; + + if ($i >= 0) { - $n = ($i == 0) ? '' : $i; - - if ($n == '' && $this->first_url != '') + if ($this->cur_page == $loop) { - $output .= $this->num_tag_open.'anchor_class.'href="'.$this->first_url.'">'.$loop.''.$this->num_tag_close; + $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page } else { - $n = ($n == '') ? '' : $this->prefix.$n.$this->suffix; + $n = ($i == 0) ? '' : $i; + + if ($n == '' && $this->first_url != '') + { + $output .= $this->num_tag_open.'anchor_class.'href="'.$this->first_url.'">'.$loop.''.$this->num_tag_close; + } + else + { + $n = ($n == '') ? '' : $this->prefix.$n.$this->suffix; - $output .= $this->num_tag_open.'anchor_class.'href="'.$this->base_url.$n.'">'.$loop.''.$this->num_tag_close; + $output .= $this->num_tag_open.'anchor_class.'href="'.$this->base_url.$n.'">'.$loop.''.$this->num_tag_close; + } } } } -- cgit v1.2.3-24-g4f1b From e9d723fb2c13585fa8a502fde7dd83dc334874ff Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 12 Jul 2010 10:10:59 -0500 Subject: 201007 file upload bug fix --- system/libraries/Upload.php | 194 +++++++++++++++++++++++++------------------- 1 file changed, 109 insertions(+), 85 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 8bdb4be19..c94e4d448 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -26,31 +26,34 @@ */ class CI_Upload { - var $max_size = 0; - var $max_width = 0; - var $max_height = 0; - var $max_filename = 0; - var $allowed_types = ""; - var $file_temp = ""; - var $file_name = ""; - var $orig_name = ""; - var $file_type = ""; - var $file_size = ""; - var $file_ext = ""; - var $upload_path = ""; - var $overwrite = FALSE; - var $encrypt_name = FALSE; - var $is_image = FALSE; - var $image_width = ''; - var $image_height = ''; - var $image_type = ''; - var $image_size_str = ''; - var $error_msg = array(); - var $mimes = array(); - var $remove_spaces = TRUE; - var $xss_clean = FALSE; - var $temp_prefix = "temp_file_"; - + var $max_size = 0; + var $max_width = 0; + var $max_height = 0; + var $max_filename = 0; + var $allowed_types = ""; + var $file_temp = ""; + var $file_name = ""; + var $orig_name = ""; + var $file_type = ""; + var $file_size = ""; + var $file_ext = ""; + var $upload_path = ""; + var $overwrite = FALSE; + var $encrypt_name = FALSE; + var $is_image = FALSE; + var $image_width = ''; + var $image_height = ''; + var $image_type = ''; + var $image_size_str = ''; + var $error_msg = array(); + var $mimes = array(); + var $remove_spaces = TRUE; + var $xss_clean = FALSE; + var $temp_prefix = "temp_file_"; + var $client_name = ''; + + var $_file_name_override = ''; //@PHP4 (should be private) + /** * Constructor * @@ -75,6 +78,7 @@ class CI_Upload { * @param array * @return void */ + function initialize($config = array()) { $defaults = array( @@ -101,7 +105,8 @@ class CI_Upload { 'mimes' => array(), 'remove_spaces' => TRUE, 'xss_clean' => FALSE, - 'temp_prefix' => "temp_file_" + 'temp_prefix' => "temp_file_", + 'client_name' => '' ); @@ -124,6 +129,10 @@ class CI_Upload { $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; } // -------------------------------------------------------------------- @@ -185,20 +194,16 @@ class CI_Upload { return FALSE; } + // Set the uploaded data as class variables $this->file_temp = $_FILES[$field]['tmp_name']; - $this->file_name = $this->_prep_filename($_FILES[$field]['name']); - $this->file_size = $_FILES[$field]['size']; + $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_ext = $this->get_extension($_FILES[$field]['name']); + $this->file_name = $this->_prep_filename($_FILES[$field]['name']); + $this->file_ext = $this->get_extension($this->file_name); + $this->client_name = $this->file_name; - // Convert the file size to kilobytes - if ($this->file_size > 0) - { - $this->file_size = round($this->file_size/1024, 2); - } - // Is the file type allowed to be uploaded? if ( ! $this->is_allowed_filetype()) { @@ -206,6 +211,25 @@ class CI_Upload { return FALSE; } + // if we're overriding, let's now make sure the new name and type is allowed + if ($this->_file_name_override != '') + { + $this->file_name = $this->_prep_filename($this->_file_name_override); + $this->file_ext = $this->get_extension($this->file_name); + + if ( ! $this->is_allowed_filetype(TRUE)) + { + $this->set_error('upload_invalid_filetype'); + return FALSE; + } + } + + // Convert the file size to kilobytes + if ($this->file_size > 0) + { + $this->file_size = round($this->file_size/1024, 2); + } + // Is the file size within the allowed maximum? if ( ! $this->is_allowed_filesize()) { @@ -254,6 +278,21 @@ class CI_Upload { } } + /* + * Run the file through the XSS hacking filter + * This helps prevent malicious code from being + * embedded within a file. Scripts can easily + * be disguised as images or other file types. + */ + if ($this->xss_clean) + { + if ($this->do_xss_clean() === FALSE) + { + $this->set_error('upload_unable_to_write_file'); + return FALSE; + } + } + /* * Move the file to the final destination * To deal with different server configurations @@ -269,21 +308,6 @@ class CI_Upload { return FALSE; } } - - /* - * Run the file through the XSS hacking filter - * This helps prevent malicious code from being - * embedded within a file. Scripts can easily - * be disguised as images or other file types. - */ - if ($this->xss_clean) - { - if ($this->do_xss_clean() === FALSE) - { - $this->set_error('upload_unable_to_write_file'); - return FALSE; - } - } /* * Set the finalized image dimensions @@ -316,6 +340,7 @@ class CI_Upload { 'full_path' => $this->upload_path.$this->file_name, 'raw_name' => str_replace($this->file_ext, '', $this->file_name), 'orig_name' => $this->orig_name, + 'client_name' => $this->client_name, 'file_ext' => $this->file_ext, 'file_size' => $this->file_size, 'is_image' => $this->is_image(), @@ -558,7 +583,7 @@ class CI_Upload { * @access public * @return bool */ - function is_allowed_filetype() + function is_allowed_filetype($ignore_mime = FALSE) { if ($this->allowed_types == '*') { @@ -570,36 +595,42 @@ class CI_Upload { $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 $image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe'); - - foreach ($this->allowed_types as $val) + + if (in_array($ext, $image_types)) { - $mime = $this->mimes_types(strtolower($val)); - - // Images get some additional checks - if ($this->file_ext == '.'.$val && in_array($val, $image_types)) + if (getimagesize($this->file_temp) === FALSE) { - if (getimagesize($this->file_temp) === FALSE) - { - return FALSE; - } - } - - if (is_array($mime)) - { - if (in_array($this->file_type, $mime, TRUE)) - { - return TRUE; - } - } - else + 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)) { - if ($mime == $this->file_type) - { - return TRUE; - } - } + return TRUE; + } + } + elseif ($mime == $this->file_type) + { + return TRUE; } return FALSE; @@ -801,7 +832,7 @@ class CI_Upload { */ function do_xss_clean() { - $file = $this->upload_path.$this->file_name; + $file = $this->file_temp; if (filesize($file) == 0) { @@ -968,7 +999,7 @@ class CI_Upload { foreach ($parts as $part) { - if ($this->mimes_types(strtolower($part)) === FALSE) + if ( ! in_array(strtolower($part), $this->allowed_types) OR $this->mimes_types(strtolower($part)) === FALSE) { $filename .= '.'.$part.'_'; } @@ -978,13 +1009,6 @@ class CI_Upload { } } - // file name override, since the exact name is provided, no need to - // run it through a $this->mimes check. - if ($this->file_name != '') - { - $filename = $this->file_name; - } - $filename .= '.'.$ext; return $filename; -- cgit v1.2.3-24-g4f1b From 924000e27e10eb32cff6b7666a9d41546fd5f2bd Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 22 Jul 2010 11:04:58 -0500 Subject: Fixed a bug in the Upload class where a PHP error could occur when wildcards were used as the allowed_types. --- system/libraries/Upload.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index c94e4d448..c18c178df 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -988,7 +988,7 @@ class CI_Upload { */ function _prep_filename($filename) { - if (strpos($filename, '.') === FALSE) + if (strpos($filename, '.') === FALSE OR $this->allowed_types == '*') { return $filename; } @@ -1020,4 +1020,4 @@ class CI_Upload { // END Upload Class /* End of file Upload.php */ -/* Location: ./system/libraries/Upload.php */ \ No newline at end of file +/* Location: ./system/libraries/Upload.php */ -- cgit v1.2.3-24-g4f1b From 958543a38c2c97b0ec4c10fc9faf4f0753143880 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 22 Jul 2010 14:10:26 -0400 Subject: Adding CSRF into config Adding CSRF token into form open() --- system/libraries/Security.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Security.php b/system/libraries/Security.php index cdae50168..c8d435046 100644 --- a/system/libraries/Security.php +++ b/system/libraries/Security.php @@ -54,7 +54,7 @@ class CI_Security { { // Set the CSRF hash $this->_csrf_set_hash(); - + log_message('debug', "Security Class Initialized"); } @@ -67,21 +67,24 @@ class CI_Security { * @return null */ function csrf_verify() - { + { // If no POST data exists we will set the CSRF cookie if (count($_POST) == 0) { return $this->csrf_set_cookie(); } + // Append application specific cookie prefix to token name + $csrf_token_name = (config_item('cookie_prefix')) ? config_item('cookie_prefix').$this->csrf_token_name : $this->csrf_token_name; + // Do the tokens exist in both the _POST and _COOKIE arrays? - if ( ! isset($_POST[$this->csrf_token_name]) OR ! isset($_COOKIE[$this->csrf_token_name])) + if ( ! isset($_POST[$this->csrf_token_name]) OR ! isset($_COOKIE[$csrf_token_name])) { $this->csrf_show_error(); } // Do the tokens match? - if ($_POST[$this->csrf_token_name] != $_COOKIE[$this->csrf_token_name]) + if ($_POST[$this->csrf_token_name] != $_COOKIE[$csrf_token_name]) { $this->csrf_show_error(); } @@ -134,7 +137,10 @@ class CI_Security { $this->csrf_hash = md5(uniqid(rand(), TRUE)); } } - + + // Create the cookie before we finish up + $this->csrf_set_cookie(); + return $this->csrf_hash; } -- cgit v1.2.3-24-g4f1b From b3f10a23e4eb51f9236af0647eee4607776fee23 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sun, 25 Jul 2010 19:11:26 -0500 Subject: separated the CSRF cookie name from the token, forced new token on successful POST --- system/libraries/Security.php | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Security.php b/system/libraries/Security.php index c8d435046..29ac2612b 100644 --- a/system/libraries/Security.php +++ b/system/libraries/Security.php @@ -29,7 +29,8 @@ class CI_Security { var $csrf_hash = ''; var $csrf_expire = 7200; // Two hours (in seconds) var $csrf_token_name = 'ci_csrf_token'; - + var $csfr_cookie_name = 'ci_csrf_token'; + /* never allowed, string replacement */ var $never_allowed_str = array( 'document.cookie' => '[removed]', @@ -52,6 +53,9 @@ class CI_Security { function CI_Security() { + // Append application specific cookie prefix to token name + $this->csfr_cookie_name = (config_item('cookie_prefix')) ? config_item('cookie_prefix').$this->csrf_token_name : $this->csrf_token_name; + // Set the CSRF hash $this->_csrf_set_hash(); @@ -74,23 +78,25 @@ class CI_Security { return $this->csrf_set_cookie(); } - // Append application specific cookie prefix to token name - $csrf_token_name = (config_item('cookie_prefix')) ? config_item('cookie_prefix').$this->csrf_token_name : $this->csrf_token_name; - // Do the tokens exist in both the _POST and _COOKIE arrays? - if ( ! isset($_POST[$this->csrf_token_name]) OR ! isset($_COOKIE[$csrf_token_name])) + if ( ! isset($_POST[$this->csrf_token_name]) OR ! isset($_COOKIE[$this->csfr_cookie_name])) { $this->csrf_show_error(); } // Do the tokens match? - if ($_POST[$this->csrf_token_name] != $_COOKIE[$csrf_token_name]) + if ($_POST[$this->csrf_token_name] != $_COOKIE[$this->csfr_cookie_name]) { $this->csrf_show_error(); } // 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->csfr_cookie_name]); + $this->_csrf_set_hash(); + $this->csrf_set_cookie(); log_message('debug', "CSRF token verified "); } @@ -105,11 +111,9 @@ class CI_Security { */ function csrf_set_cookie() { - $prefix = ( ! is_string(config_item('cookie_prefix'))) ? '' : config_item('cookie_prefix'); - $expire = time() + $this->csrf_expire; - setcookie($prefix.$this->csrf_token_name, $this->csrf_hash, $expire, config_item('cookie_path'), config_item('cookie_domain'), 0); + setcookie($this->csfr_cookie_name, $this->csrf_hash, $expire, config_item('cookie_path'), config_item('cookie_domain'), 0); log_message('debug', "CRSF cookie Set"); } @@ -128,9 +132,9 @@ class CI_Security { { // If the cookie exists we will use it's value. We don't necessarily want to regenerate it with // each page load since a page could contain embedded sub-pages causing this feature to fail - if (isset($_COOKIE[$this->csrf_token_name]) AND $_COOKIE[$this->csrf_token_name] != '') + if (isset($_COOKIE[$this->csfr_cookie_name]) AND $_COOKIE[$this->csfr_cookie_name] != '') { - $this->csrf_hash = $_COOKIE[$this->csrf_token_name]; + $this->csrf_hash = $_COOKIE[$this->csfr_cookie_name]; } else { @@ -138,9 +142,6 @@ class CI_Security { } } - // Create the cookie before we finish up - $this->csrf_set_cookie(); - return $this->csrf_hash; } -- cgit v1.2.3-24-g4f1b From 4062d48ca89736c952e9be17bb395d36140f4668 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 10 Aug 2010 20:30:34 -0500 Subject: removed redundant upload lang file, after lang name changs, it was blocking the CI lang file from loading. Fixes #473 --- system/libraries/Upload.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index c18c178df..0aa6d4c20 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -937,9 +937,12 @@ class CI_Upload { */ function display_errors($open = '

', $close = '

') { + $CI =& get_instance(); + $CI->lang->load('upload'); $str = ''; foreach ($this->error_msg as $val) { + $str .= '
'.print_r($CI->lang->line($msg), TRUE).'
'; $str .= $open.$val.$close; } -- cgit v1.2.3-24-g4f1b From 23b7776accc6ebfa377c9b54bd04baaaf0c00132 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 10 Aug 2010 20:38:43 -0500 Subject: undoing mistaken changes in rev 8c54b3b0402f --- system/libraries/Upload.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 0aa6d4c20..c18c178df 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -937,12 +937,9 @@ class CI_Upload { */ function display_errors($open = '

', $close = '

') { - $CI =& get_instance(); - $CI->lang->load('upload'); $str = ''; foreach ($this->error_msg as $val) { - $str .= '
'.print_r($CI->lang->line($msg), TRUE).'
'; $str .= $open.$val.$close; } -- cgit v1.2.3-24-g4f1b From 595bfd1484ecc8212d6c3c028210b4d1ae78baba Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 20 Aug 2010 10:28:22 -0500 Subject: Added ability in the Image Library to handle PNG transparency for resize operations when using the GD lib. --- system/libraries/Image_lib.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'system/libraries') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 21e0a709b..806d942ba 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -513,6 +513,13 @@ class CI_Image_lib { } $dst_img = $create($this->width, $this->height); + + if ($this->image_type == 3) // png we can actually preserve transparency + { + 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 -- cgit v1.2.3-24-g4f1b From 5485db50775d4e2f76a593ef8b3425f6a1b90666 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 30 Aug 2010 21:31:08 -0500 Subject: Added fatal error to Session class when no encryption key is set in the config file, for additional assurance that session manipulation can be prevented --- system/libraries/Session.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'system/libraries') diff --git a/system/libraries/Session.php b/system/libraries/Session.php index cf6dc96e3..f413c0d1b 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -65,6 +65,11 @@ class CI_Session { $this->$key = (isset($params[$key])) ? $params[$key] : $this->CI->config->item($key); } + if ($this->encryption_key == '') + { + show_error('In order to use the Session class you are required to set an encryption key in your config file.'); + } + // Load the string helper so we can use the strip_slashes() function $this->CI->load->helper('string'); -- cgit v1.2.3-24-g4f1b From 7284f06585a689702ea86684893c999065621460 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 31 Aug 2010 00:30:21 -0500 Subject: changed key comparison to be loosely typed, so an error would be triggered when an empty string is attempted to be used as an encryption key --- system/libraries/Encrypt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index c893fbf9e..44fdce03b 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -72,7 +72,7 @@ class CI_Encrypt { $CI =& get_instance(); $key = $CI->config->item('encryption_key'); - if ($key === FALSE) + if ($key == FALSE) { show_error('In order to use the encryption class requires that you set an encryption key in your config file.'); } -- cgit v1.2.3-24-g4f1b From 95b183addfb1683583d401e04f2684ceb86f8b96 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 31 Aug 2010 09:42:39 -0500 Subject: fixed spelling error in Security class property for the CSRF cookie --- system/libraries/Security.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Security.php b/system/libraries/Security.php index 29ac2612b..9a1590b5c 100644 --- a/system/libraries/Security.php +++ b/system/libraries/Security.php @@ -29,7 +29,7 @@ class CI_Security { var $csrf_hash = ''; var $csrf_expire = 7200; // Two hours (in seconds) var $csrf_token_name = 'ci_csrf_token'; - var $csfr_cookie_name = 'ci_csrf_token'; + var $csrf_cookie_name = 'ci_csrf_token'; /* never allowed, string replacement */ var $never_allowed_str = array( @@ -54,7 +54,7 @@ class CI_Security { function CI_Security() { // Append application specific cookie prefix to token name - $this->csfr_cookie_name = (config_item('cookie_prefix')) ? config_item('cookie_prefix').$this->csrf_token_name : $this->csrf_token_name; + $this->csrf_cookie_name = (config_item('cookie_prefix')) ? config_item('cookie_prefix').$this->csrf_token_name : $this->csrf_token_name; // Set the CSRF hash $this->_csrf_set_hash(); @@ -79,13 +79,13 @@ class CI_Security { } // Do the tokens exist in both the _POST and _COOKIE arrays? - if ( ! isset($_POST[$this->csrf_token_name]) OR ! isset($_COOKIE[$this->csfr_cookie_name])) + if ( ! isset($_POST[$this->csrf_token_name]) OR ! isset($_COOKIE[$this->csrf_cookie_name])) { $this->csrf_show_error(); } // Do the tokens match? - if ($_POST[$this->csrf_token_name] != $_COOKIE[$this->csfr_cookie_name]) + if ($_POST[$this->csrf_token_name] != $_COOKIE[$this->csrf_cookie_name]) { $this->csrf_show_error(); } @@ -94,7 +94,7 @@ class CI_Security { unset($_POST[$this->csrf_token_name]); // Nothing should last forever - unset($_COOKIE[$this->csfr_cookie_name]); + unset($_COOKIE[$this->csrf_cookie_name]); $this->_csrf_set_hash(); $this->csrf_set_cookie(); @@ -113,7 +113,7 @@ class CI_Security { { $expire = time() + $this->csrf_expire; - setcookie($this->csfr_cookie_name, $this->csrf_hash, $expire, config_item('cookie_path'), config_item('cookie_domain'), 0); + setcookie($this->csrf_cookie_name, $this->csrf_hash, $expire, config_item('cookie_path'), config_item('cookie_domain'), 0); log_message('debug', "CRSF cookie Set"); } @@ -132,9 +132,9 @@ class CI_Security { { // If the cookie exists we will use it's value. We don't necessarily want to regenerate it with // each page load since a page could contain embedded sub-pages causing this feature to fail - if (isset($_COOKIE[$this->csfr_cookie_name]) AND $_COOKIE[$this->csfr_cookie_name] != '') + if (isset($_COOKIE[$this->csrf_cookie_name]) AND $_COOKIE[$this->csrf_cookie_name] != '') { - $this->csrf_hash = $_COOKIE[$this->csfr_cookie_name]; + $this->csrf_hash = $_COOKIE[$this->csrf_cookie_name]; } else { -- cgit v1.2.3-24-g4f1b From 09c7793b23ae77c54e25d12b63d8ca9c9232efeb Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 31 Aug 2010 13:17:10 -0500 Subject: Significant changes to the Encryption library - Removed double-encoding with XOR scheme when Mcrypt is available. Additional obfuscation was not significantly aiding security, and came at a very high performance cost. - Changed the default encryption mode from ECB to CBC for much improved security - Added an encode_from_legacy() method to allow re-encoding of permanent data that was originally encoded with the older methods. --- system/libraries/Encrypt.php | 75 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 6 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 44fdce03b..8beff75d6 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -116,12 +116,16 @@ class CI_Encrypt { function encode($string, $key = '') { $key = $this->get_key($key); - $enc = $this->_xor_encode($string, $key); - + if ($this->_mcrypt_exists === TRUE) { - $enc = $this->mcrypt_encode($enc, $key); + $enc = $this->mcrypt_encode($string, $key); + } + else + { + $enc = $this->_xor_encode($string, $key); } + return base64_encode($enc); } @@ -155,12 +159,71 @@ class CI_Encrypt { return FALSE; } } - - return $this->_xor_decode($dec, $key); + else + { + $dec = $this->_xor_decode($dec, $key); + } + + return $dec; } // -------------------------------------------------------------------- + + /** + * Encode from Legacy + * + * Takes an encoded string from the original Encryption class algorithms and + * 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 + * @param string + * @param int (mcrypt mode constant) + * @param string + * @return string + */ + function encode_from_legacy($string, $legacy_mode = MCRYPT_MODE_ECB, $key = '') + { + if ($this->_mcrypt_exists === FALSE) + { + 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 + $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; + } + + $dec = $this->_xor_decode($dec, $key); + // set the mcrypt mode back to what it should be, typically MCRYPT_MODE_CBC + $this->set_mode(MCRYPT_MODE_CBC); + + // and re-encode + return base64_encode($this->mcrypt_encode($dec, $key)); + } + + // -------------------------------------------------------------------- + /** * XOR Encode * @@ -412,7 +475,7 @@ class CI_Encrypt { { if ($this->_mcrypt_mode == '') { - $this->_mcrypt_mode = MCRYPT_MODE_ECB; + $this->_mcrypt_mode = MCRYPT_MODE_CBC; } return $this->_mcrypt_mode; -- cgit v1.2.3-24-g4f1b From d1606358ba51261150bc2f99bb9cb2b9117718e7 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 1 Sep 2010 11:16:07 -0500 Subject: fixes issue #109 where cc and bcc recipients were not reset when using the clear() method in the Email lib --- system/libraries/Email.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 09d1b8fb9..af48757bb 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -146,6 +146,8 @@ class CI_Email { $this->_header_str = ""; $this->_replyto_flag = FALSE; $this->_recipients = array(); + $this->_cc_array = array(); + $this->_bcc_array = array(); $this->_headers = array(); $this->_debug_msg = array(); -- cgit v1.2.3-24-g4f1b From eaa71ba1c19538af5416dceec288aa37cad2b7e6 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 2 Sep 2010 10:32:07 -0500 Subject: Added a new config item to the Session class (sess_expire_on_close) to allow sessions to auto-expire when the browser window is closed. --- system/libraries/Session.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Session.php b/system/libraries/Session.php index f413c0d1b..fc3ee0542 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -30,6 +30,7 @@ class CI_Session { var $sess_use_database = FALSE; var $sess_table_name = ''; var $sess_expiration = 7200; + var $sess_expire_on_close = FALSE; var $sess_match_ip = FALSE; var $sess_match_useragent = TRUE; var $sess_cookie_name = 'ci_session'; @@ -655,12 +656,14 @@ 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, $cookie_data, - $this->sess_expiration + time(), + $expire, $this->cookie_path, $this->cookie_domain, 0 -- cgit v1.2.3-24-g4f1b From 092103e4d6a4a2bcd14274055f774e4eb01ecaa3 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 2 Sep 2010 11:11:58 -0500 Subject: fixed a spot where the encryption mode was still a hard coded constant instead of the fetched variable --- system/libraries/Encrypt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 8beff75d6..b27847a55 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -216,7 +216,7 @@ class CI_Encrypt { $dec = $this->_xor_decode($dec, $key); // set the mcrypt mode back to what it should be, typically MCRYPT_MODE_CBC - $this->set_mode(MCRYPT_MODE_CBC); + $this->set_mode($current_mode); // and re-encode return base64_encode($this->mcrypt_encode($dec, $key)); -- cgit v1.2.3-24-g4f1b From c2950704d0cf8b7ae4d71900259b1c8ef3584c68 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 14 Sep 2010 17:52:26 -0500 Subject: Updates to output profiler html validation. http://bitbucket.org/ellislab/codeigniter/issue/111/profiler-output-does-not-validate --- system/libraries/Profiler.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 0900a300d..6bc3c8799 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -128,7 +128,7 @@ class CI_Profiler { foreach ($profile as $key => $val) { $key = ucwords(str_replace(array('_', '-'), ' ', $key)); - $output .= "".$key."  ".$val."\n"; + $output .= "".$key."  ".$val."\n"; } $output .= "\n"; @@ -165,8 +165,8 @@ class CI_Profiler { $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; $output .= "\n"; - $output .= "\n\n\n"; - $output .="\n"; + $output .= "\n\n
".$this->CI->lang->line('profiler_no_db')."
\n"; + $output .="\n"; $output .= "
".$this->CI->lang->line('profiler_no_db')."
\n"; $output .= ""; @@ -187,11 +187,11 @@ class CI_Profiler { $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_database').':  '.$db->database.'   '.$this->CI->lang->line('profiler_queries').': '.count($this->CI->db->queries).'   '; $output .= "\n"; - $output .= "\n\n\n"; + $output .= "\n\n
\n"; if (count($db->queries) == 0) { - $output .= "\n"; + $output .= "\n"; } else { @@ -206,7 +206,7 @@ class CI_Profiler { $val = str_replace($bold, ''.$bold.'', $val); } - $output .= "\n"; + $output .= "\n"; } } -- cgit v1.2.3-24-g4f1b From 3424bf77ce638a2fd8e64ea76e874d3b9ead7414 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 14 Sep 2010 17:53:10 -0500 Subject: Fixed http://bitbucket.org/ellislab/codeigniter/issue/38/slight-bug-with-profilerphp Slight tweak to SQL query display in output profiler. --- system/libraries/Profiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 6bc3c8799..db179976b 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -177,7 +177,7 @@ class CI_Profiler { $this->CI->load->helper('text'); // Key words we want bolded - $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', '(', ')'); + $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"; -- cgit v1.2.3-24-g4f1b From c206754bfe399f9cee4df92a3ea037a297dbb945 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 1 Oct 2010 07:19:57 -0500 Subject: tweak to typography. Better aesthetic to placement of paragraph tags --- system/libraries/Typography.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index 0f0a8b7a2..f058769ec 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -202,7 +202,7 @@ class CI_Typography { // If the user submitted their own paragraph tags within the text // we will retain them instead of using our tags. - '/(*?]>)

/' => '$1', // *?]>)

/' => '$1', // )+#' => '

', @@ -219,8 +219,17 @@ class CI_Typography { '/\{@DQ\}/' => '"', '/\{@SQ\}/' => "'", '/\{@DD\}/' => '--', - '/\{@NBS\}/' => ' ' + '/\{@NBS\}/' => ' ', + // An unintended consequence of the _format_newlines function is that + // some of the newlines get truncated, resulting in

tags + // starting immediately after tags on the same line. + // This forces a newline after such occurrences, which looks much nicer. + "/>

\n/" => ">\n

", + + // Similarly, there might be cases where a closing will follow + // a closing

tag, so we'll correct it by adding a newline in between + "#

"

\n'.$str.'

'; + // We trim off the right-side new line so that the closing

tag + // will be positioned immediately following the string, matching + // the behavior of the opening

tag + $str = '

'.rtrim($str).'

'; } // Remove empty paragraphs if they are on the first line, as this -- cgit v1.2.3-24-g4f1b From 3934a4a803ee2069ac7622e4c2565fb5fee11ce9 Mon Sep 17 00:00:00 2001 From: fesplugas Date: Mon, 4 Oct 2010 09:07:49 +0200 Subject: Fixed link --- system/libraries/Javascript.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php index efaaab4bf..c149bb111 100644 --- a/system/libraries/Javascript.php +++ b/system/libraries/Javascript.php @@ -22,7 +22,7 @@ * @subpackage Libraries * @category Javascript * @author ExpressionEngine Dev Team - * @link http://codeigniter.com/user_guide/general/errors.html + * @link http://codeigniter.com/user_guide/libraries/javascript.html */ class CI_Javascript { -- cgit v1.2.3-24-g4f1b From dd6719738936be31cdaa1758ca86d5eb14dcab3d Mon Sep 17 00:00:00 2001 From: Barry Mieny Date: Mon, 4 Oct 2010 16:33:58 +0200 Subject: Cleanup of stray spaces and tabs --- system/libraries/Calendar.php | 156 ++++++------ system/libraries/Cart.php | 140 +++++------ system/libraries/Driver.php | 44 ++-- system/libraries/Email.php | 124 +++++----- system/libraries/Encrypt.php | 30 +-- system/libraries/Form_validation.php | 436 ++++++++++++++++----------------- system/libraries/Ftp.php | 14 +- system/libraries/Image_lib.php | 42 ++-- system/libraries/Javascript.php | 172 ++++++------- system/libraries/Log.php | 34 +-- system/libraries/Pagination.php | 20 +- system/libraries/Parser.php | 26 +- system/libraries/Profiler.php | 184 +++++++------- system/libraries/Security.php | 142 +++++------ system/libraries/Session.php | 24 +- system/libraries/Sha1.php | 22 +- system/libraries/Table.php | 156 ++++++------ system/libraries/Trackback.php | 246 +++++++++---------- system/libraries/Typography.php | 140 +++++------ system/libraries/Unit_test.php | 110 ++++----- system/libraries/Upload.php | 298 +++++++++++----------- system/libraries/User_agent.php | 166 ++++++------- system/libraries/Xmlrpc.php | 326 ++++++++++++------------ system/libraries/Xmlrpcs.php | 152 ++++++------ system/libraries/Zip.php | 56 ++--- system/libraries/javascript/Jquery.php | 28 +-- 26 files changed, 1644 insertions(+), 1644 deletions(-) (limited to 'system/libraries') 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' => '
".$this->CI->lang->line('profiler_no_queries')."
".$this->CI->lang->line('profiler_no_queries')."
".$time."  ".$val."
".$time."  ".$val."
', - 'heading_row_start' => '', + 'table_open' => '
', + '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' => '', + 'heading_next_cell' => '', + 'heading_row_end' => '', + 'week_row_start' => '', + 'week_day_cell' => '', + 'week_row_end' => '', + 'cal_row_start' => '', + 'cal_cell_start' => '', 'cal_row_end' => '', 'table_close' => '
<<{heading}>>
{week_day}
', + 'heading_title_cell' => '{heading}>>
{week_day}
', 'cal_cell_start_today' => '', 'cal_cell_content' => '{day}', 'cal_cell_content_today' => '{day}', @@ -428,9 +428,9 @@ class CI_Calendar { 'cal_cell_end_today' => '
' - ); + ); } - + // -------------------------------------------------------------------- /** @@ -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 .= "
".$this->_header_str."\n".htmlspecialchars($this->_subject)."\n".htmlspecialchars($this->_finalbody).'
'; return $msg; } - + // -------------------------------------------------------------------- /** @@ -1932,7 +1932,7 @@ class CI_Email { $this->_debug_msg[] = str_replace('%s', $val, $line)."
"; } } - + // -------------------------------------------------------------------- /** 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 = '

'; var $_error_suffix = '

'; 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 = '

', $suffix = '

') { $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(''), 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 efaaab4bf..b4f33e309 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 + * Outputs an closing * * @access private - * @param string + * @param string * @return string */ function _close_script($extra = "\n") { return "$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.'anchor_class.'href="'.$this->first_url.'">'.$this->prev_link.''.$this->prev_tag_close; + $output .= $this->prev_tag_open.'anchor_class.'href="'.$this->first_url.'">'.$this->prev_link.''.$this->prev_tag_close; } else { $i = ($i == 0) ? '' : $this->prefix.$i.$this->suffix; $output .= $this->prev_tag_open.'anchor_class.'href="'.$this->base_url.$i.'">'.$this->prev_link.''.$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.'anchor_class.'href="'.$this->first_url.'">'.$loop.''.$this->num_tag_close; @@ -242,7 +242,7 @@ class CI_Pagination { else { $n = ($n == '') ? '' : $this->prefix.$n.$this->suffix; - + $output .= $this->num_tag_open.'anchor_class.'href="'.$this->base_url.$n.'">'.$loop.''.$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 .= '
'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_benchmarks').'  '; - $output .= "\n"; + $output .= "\n"; $output .= "\n\n\n"; - + foreach ($profile as $key => $val) { $key = ucwords(str_replace(array('_', '-'), ' ', $key)); $output .= "\n"; } - + $output .= "
".$key."  ".$val."
\n"; $output .= "
"; - - 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 .= '
'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; - $output .= "\n"; + $output .= "\n"; $output .= "\n\n\n"; $output .="\n"; $output .= "
".$this->CI->lang->line('profiler_no_db')."
\n"; $output .= "
"; - + 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 .= '
'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_database').':  '.$db->database.'   '.$this->CI->lang->line('profiler_queries').': '.count($this->CI->db->queries).'   '; - $output .= "\n"; + $output .= "\n"; $output .= "\n\n\n"; - + if (count($db->queries) == 0) { $output .= "\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, ''.$bold.'', $val); + $val = str_replace($bold, ''.$bold.'', $val); } - + $output .= "\n"; } } - + $output .= "
".$this->CI->lang->line('profiler_no_queries')."
".$time."  ".$val."
\n"; $output .= "
"; - + } - + return $output; } - + // -------------------------------------------------------------------- /** @@ -226,15 +226,15 @@ class CI_Profiler { * * @access private * @return string - */ + */ function _compile_get() - { + { $output = "\n\n"; $output .= '
'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_get_data').'  '; $output .= "\n"; - + if (count($_GET) == 0) { $output .= "
".$this->CI->lang->line('profiler_no_get')."
"; @@ -242,14 +242,14 @@ class CI_Profiler { else { $output .= "\n\n\n"; - + foreach ($_GET as $key => $val) { if ( ! is_numeric($key)) { $key = "'".$key."'"; } - + $output .= "\n"; } - + $output .= "
$_GET[".$key."]   "; if (is_array($val)) { @@ -261,30 +261,30 @@ class CI_Profiler { } $output .= "
\n"; } $output .= "
"; - return $output; + return $output; } - + // -------------------------------------------------------------------- - + /** * Compile $_POST Data * * @access private * @return string - */ + */ function _compile_post() - { + { $output = "\n\n"; $output .= '
'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_post_data').'  '; $output .= "\n"; - + if (count($_POST) == 0) { $output .= "
".$this->CI->lang->line('profiler_no_post')."
"; @@ -292,14 +292,14 @@ class CI_Profiler { else { $output .= "\n\n\n"; - + foreach ($_POST as $key => $val) { if ( ! is_numeric($key)) { $key = "'".$key."'"; } - + $output .= "\n"; } - + $output .= "
$_POST[".$key."]   "; if (is_array($val)) { @@ -311,70 +311,70 @@ class CI_Profiler { } $output .= "
\n"; } $output .= "
"; - return $output; + return $output; } - + // -------------------------------------------------------------------- - + /** * Show query string * * @access private * @return string - */ + */ function _compile_uri_string() - { + { $output = "\n\n"; $output .= '
'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_uri_string').'  '; $output .= "\n"; - + if ($this->CI->uri->uri_string == '') { $output .= "
".$this->CI->lang->line('profiler_no_uri')."
"; } else { - $output .= "
".$this->CI->uri->uri_string."
"; + $output .= "
".$this->CI->uri->uri_string."
"; } - + $output .= "
"; - return $output; + return $output; } // -------------------------------------------------------------------- - + /** * Show the controller and function that were called * * @access private * @return string - */ + */ function _compile_controller_info() - { + { $output = "\n\n"; $output .= '
'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_controller_info').'  '; $output .= "\n"; - - $output .= "
".$this->CI->router->fetch_class()."/".$this->CI->router->fetch_method()."
"; - + $output .= "
".$this->CI->router->fetch_class()."/".$this->CI->router->fetch_method()."
"; + + $output .= "
"; - return $output; + return $output; } // -------------------------------------------------------------------- - + /** * Compile memory usage * @@ -390,23 +390,23 @@ class CI_Profiler { $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_memory_usage').'  '; $output .= "\n"; - + if (function_exists('memory_get_usage') && ($usage = memory_get_usage()) != '') { $output .= "
".number_format($usage).' bytes
'; } else { - $output .= "
".$this->CI->lang->line('profiler_no_memory_usage')."
"; + $output .= "
".$this->CI->lang->line('profiler_no_memory_usage')."
"; } - + $output .= ""; return $output; } // -------------------------------------------------------------------- - + /** * Compile header information * @@ -463,7 +463,7 @@ class CI_Profiler { { $val = print_r($val, TRUE); } - + $output .= "".$config."  ".htmlspecialchars($val)."\n"; } @@ -474,18 +474,18 @@ class CI_Profiler { } // -------------------------------------------------------------------- - + /** * Run the Profiler * * @access private * @return string - */ + */ function run() { $output = "
"; $fields_displayed = 0; - + foreach ($this->_available_sections as $section) { if ($this->_compile_{$section} !== FALSE) @@ -500,7 +500,7 @@ class CI_Profiler { { $output .= '

'.$this->CI->lang->line('profiler_no_profiles').'

'; } - + $output .= '
'; return $output; diff --git a/system/libraries/Security.php b/system/libraries/Security.php index 9a1590b5c..2db8ee9b3 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("/]*?)(>|$)#si", array($this, '_js_link_removal'), $str); } - + if (preg_match("/]*?)(\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|', '<', '\\'), 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 * @@ -705,16 +705,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 fc3ee0542..342c301e3 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('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('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_open' => '
', + 'thead_open' => '', 'thead_close' => '', - - 'heading_row_start' => '', - 'heading_row_end' => '', + + 'heading_row_start' => '', + 'heading_row_end' => '', 'heading_cell_start' => '', 'tbody_open' => '', 'tbody_close' => '', - - 'row_start' => '', - 'row_end' => '', + + 'row_start' => '', + 'row_end' => '', 'cell_start' => '', - 'row_alt_start' => '', - 'row_alt_end' => '', + 'row_alt_start' => '', + 'row_alt_end' => '', 'cell_alt_start' => '', - 'table_close' => '
', 'heading_cell_end' => '
', 'cell_end' => '
', 'cell_alt_end' => '
' - ); + 'table_close' => '' + ); } - + } 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 "\n\n1\n".$message."\n"; exit; } - + // -------------------------------------------------------------------- - + /** * Send Trackback Success Message * @@ -194,29 +194,29 @@ class CI_Trackback { * * @access public * @return void - */ + */ function send_success() { echo "\n\n0\n"; 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, '0') === FALSE) { $message = 'An unknown error was encountered'; - + if (preg_match("/(.*?)<\/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 = '

', $close = '

') - { + { $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

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

and
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
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
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

 tags if they exist.  It's cheaper to do this separately since most content will
 		// not contain 
 tags, and it keeps the PCRE patterns below simpler and faster
 		if (strpos($str, '.*?
#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] = - // [1] = Content... - // [2] = - // Etc... - // } + // + // [array] + // { + // [0] = + // [1] = Content... + // [2] = + // 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
 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 

and
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", '

$1

<$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 '

{@HC1}' then replace

{@HC1}

with the comment, else replace only {@HC1} with the comment $str = preg_replace('#(?(?=

\{@HC'.$i.'\})

\{@HC'.$i.'\}(\s*

)|\{@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. '/(*?]>)

/' => '$1', // )+#' => '

', '/(

\W*

)+/' => '

', - + // Clean up stray paragraph tags that appear before block level elements '#

<('.$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

tags - // starting immediately after tags on the same line. + // starting immediately after tags on the same line. // This forces a newline after such occurrences, which looks much nicer. "/>

\n/" => ">\n

", - + // Similarly, there might be cases where a closing will follow // a closing

tag, so we'll correct it by adding a newline in between "#

"

\n

#'] = '

 

'; } - + 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", "

\n\n

", $str); - + // Convert single spaces to
tags $str = preg_replace("/([^\n])(\n)([^\n])/", "\\1
\\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>(.*)/", "\\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".''; $this->_template .= '{rows}'; $this->_template .= "\n".'
'; - + $this->_template_rows = "\n\t".''; $this->_template_rows .= "\n\t\t".'{item}'; $this->_template_rows .= "\n\t\t".'{result}'; - $this->_template_rows .= "\n\t".''; + $this->_template_rows .= "\n\t".''; } - + // -------------------------------------------------------------------- /** @@ -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 // 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 = '

', $close = '

') { $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 = "\n"; @@ -500,7 +500,7 @@ class XML_RPC_Response $result .= "\n"; 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 = "\r\n\r\n"; $this->payload .= '' . $this->method_name . "\r\n"; $this->payload .= "\r\n"; - + for($i=0; $iparams); $i++) { // $p = XML_RPC_Values $p = $this->params[$i]; $this->payload .= "\r\n".$p->serialize_class()."\r\n"; } - + $this->payload .= "\r\n\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 "
";
 			echo "---DATA---\n" . htmlspecialchars($data) . "\n---END DATA---\n\n";
 			echo "
"; } - + //------------------------------------- // 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 "
";
-			
+
 			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---
"; } - + //------------------------------------- // 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 to nothing to prevent errors later if no 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 'XML_RPC_Values: scalar can have only one value
'; return 0; } - + if ($typeof != 1) { echo 'XML_RPC_Values: not a scalar type (${typeof})
'; @@ -1392,12 +1392,12 @@ class XML_RPC_Values extends CI_Xmlrpc { $ar = $o->me; reset($ar); - + list($typ, $val) = each($ar); $rs = "\n".$this->serializedata($typ, $val)."\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 = '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 "
";
 				echo "---PLIST---\n" . $plist . "\n---PLIST END---\n\n";
 				echo "
"; } - + $r = $this->_execute($m); } - + //------------------------------------- // SET DEBUGGING MESSAGE - //------------------------------------- - + //------------------------------------- + if ($this->debug === TRUE) { $this->debug_msg = "\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; $iparams)+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 * -- cgit v1.2.3-24-g4f1b From 71eee841e278ba5d08f836c047ef3c2e38fa34e1 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 5 Oct 2010 09:40:43 -0500 Subject: fixed bug where sess_expire_on_close was not being set from a config file, fixes #173 --- system/libraries/Session.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Session.php b/system/libraries/Session.php index fc3ee0542..7394e5897 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -61,7 +61,7 @@ class CI_Session { // Set all the session preferences, which can either be set // manually via the $params array above or via the config file - foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key) + foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', 'sess_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key) { $this->$key = (isset($params[$key])) ? $params[$key] : $this->CI->config->item($key); } -- cgit v1.2.3-24-g4f1b From 2ef375969b77c5fdf84118d4a7a8e0bc97d9d2f6 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 6 Oct 2010 17:51:59 -0500 Subject: modified the security helper to assist in preventing directory traversal when using sanitize_filename() for user input --- system/libraries/Security.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Security.php b/system/libraries/Security.php index 9a1590b5c..3c1e9cfba 100644 --- a/system/libraries/Security.php +++ b/system/libraries/Security.php @@ -680,11 +680,10 @@ class CI_Security { * @param string * @return string */ - function sanitize_filename($str) + function sanitize_filename($str, $relative_path = FALSE) { $bad = array( "../", - "./", "", "<", @@ -701,7 +700,6 @@ class CI_Security { '=', ';', '?', - '/', "%20", "%22", "%3c", // < @@ -717,6 +715,12 @@ class CI_Security { "%3b", // ; "%3d" // = ); + + if ( ! $relative_path) + { + $bad[] = './'; + $bad[] = '/'; + } return stripslashes(str_replace($bad, '', $str)); } -- cgit v1.2.3-24-g4f1b From 485d74123d57c69d93d1c4fcd0deef7c873f4b68 Mon Sep 17 00:00:00 2001 From: Brandon Jones Date: Tue, 9 Nov 2010 16:38:17 -0500 Subject: Altered our mail() params to be inline with PHP documentation, fixes mailing on some hosts --- system/libraries/Email.php | 120 +++++++++++++++++++++------------------------ 1 file changed, 56 insertions(+), 64 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 6c0309b0d..043e14bc4 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -981,6 +981,7 @@ class CI_Email { $this->_write_headers(); $hdr = ($this->_get_protocol() == 'mail') ? $this->newline : ''; + $body = ''; switch ($this->_get_content_type()) { @@ -993,13 +994,12 @@ class CI_Email { { $this->_header_str .= $hdr; $this->_finalbody = $this->_body; - - return; } - - $hdr .= $this->newline . $this->newline . $this->_body; - - $this->_finalbody = $hdr; + else + { + $this->_finalbody = $hdr . $this->newline . $this->newline . $this->_body; + } + return; break; @@ -1013,93 +1013,81 @@ class CI_Email { else { $hdr .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline . $this->newline; - $hdr .= $this->_get_mime_message() . $this->newline . $this->newline; - $hdr .= "--" . $this->_alt_boundary . $this->newline; - $hdr .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline; - $hdr .= "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline; - $hdr .= $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline; + $body .= $this->_get_mime_message() . $this->newline . $this->newline; + $body .= "--" . $this->_alt_boundary . $this->newline; - $hdr .= "Content-Type: text/html; charset=" . $this->charset . $this->newline; - $hdr .= "Content-Transfer-Encoding: quoted-printable"; - } - - $this->_body = $this->_prep_quoted_printable($this->_body); + $body .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline; + $body .= "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline; + $body .= $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline; + $body .= "Content-Type: text/html; charset=" . $this->charset . $this->newline; + $body .= "Content-Transfer-Encoding: quoted-printable" . $this->newline . $this->newline; + } + + $this->_finalbody = $body . $this->_prep_quoted_printable($this->_body) . $this->newline . $this->newline; + + if ($this->_get_protocol() == 'mail') { $this->_header_str .= $hdr; - $this->_finalbody = $this->_body . $this->newline . $this->newline; - - if ($this->send_multipart !== FALSE) - { - $this->_finalbody .= "--" . $this->_alt_boundary . "--"; - } - - return; + } + else + { + $this->_finalbody = $hdr . $this->_finalbody; } - $hdr .= $this->newline . $this->newline; - $hdr .= $this->_body . $this->newline . $this->newline; if ($this->send_multipart !== FALSE) { - $hdr .= "--" . $this->_alt_boundary . "--"; + $this->_finalbody .= "--" . $this->_alt_boundary . "--"; } - $this->_finalbody = $hdr; return; break; case 'plain-attach' : $hdr .= "Content-Type: multipart/".$this->multipart."; boundary=\"" . $this->_atc_boundary."\"" . $this->newline . $this->newline; - $hdr .= $this->_get_mime_message() . $this->newline . $this->newline; - $hdr .= "--" . $this->_atc_boundary . $this->newline; - - $hdr .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline; - $hdr .= "Content-Transfer-Encoding: " . $this->_get_encoding(); if ($this->_get_protocol() == 'mail') { $this->_header_str .= $hdr; + } + + $body .= $this->_get_mime_message() . $this->newline . $this->newline; + $body .= "--" . $this->_atc_boundary . $this->newline; - $body = $this->_body . $this->newline . $this->newline; - } + $body .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline; + $body .= "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline; - $hdr .= $this->newline . $this->newline; - $hdr .= $this->_body . $this->newline . $this->newline; + $body .= $this->_body . $this->newline . $this->newline; break; case 'html-attach' : $hdr .= "Content-Type: multipart/".$this->multipart."; boundary=\"" . $this->_atc_boundary."\"" . $this->newline . $this->newline; - $hdr .= $this->_get_mime_message() . $this->newline . $this->newline; - $hdr .= "--" . $this->_atc_boundary . $this->newline; - - $hdr .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline .$this->newline; - $hdr .= "--" . $this->_alt_boundary . $this->newline; - - $hdr .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline; - $hdr .= "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline; - $hdr .= $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline; - - $hdr .= "Content-Type: text/html; charset=" . $this->charset . $this->newline; - $hdr .= "Content-Transfer-Encoding: quoted-printable"; - - $this->_body = $this->_prep_quoted_printable($this->_body); - + if ($this->_get_protocol() == 'mail') { $this->_header_str .= $hdr; - - $body = $this->_body . $this->newline . $this->newline; - $body .= "--" . $this->_alt_boundary . "--" . $this->newline . $this->newline; } - $hdr .= $this->newline . $this->newline; - $hdr .= $this->_body . $this->newline . $this->newline; - $hdr .= "--" . $this->_alt_boundary . "--" . $this->newline . $this->newline; + $body .= $this->_get_mime_message() . $this->newline . $this->newline; + $body .= "--" . $this->_atc_boundary . $this->newline; + + $body .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline .$this->newline; + $body .= "--" . $this->_alt_boundary . $this->newline; + + $body .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline; + $body .= "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline; + $body .= $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline; + + $body .= "Content-Type: text/html; charset=" . $this->charset . $this->newline; + $body .= "Content-Transfer-Encoding: quoted-printable" . $this->newline . $this->newline; + + $body .= $this->_prep_quoted_printable($this->_body) . $this->newline . $this->newline; + $body .= "--" . $this->_alt_boundary . "--" . $this->newline . $this->newline; break; } @@ -1139,15 +1127,18 @@ class CI_Email { fclose($fp); } + $body .= implode($this->newline, $attachment).$this->newline."--".$this->_atc_boundary."--"; + + if ($this->_get_protocol() == 'mail') { - $this->_finalbody = $body . implode($this->newline, $attachment).$this->newline."--".$this->_atc_boundary."--"; - - return; + $this->_finalbody = $body; } - - $this->_finalbody = $hdr.implode($this->newline, $attachment).$this->newline."--".$this->_atc_boundary."--"; - + else + { + $this->_finalbody = $hdr . $body; + } + return; } @@ -1518,6 +1509,7 @@ class CI_Email { { // most documentation of sendmail using the "-f" flag lacks a space after it, however // we've encountered servers that seem to require it to be in place. + if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From']))) { return FALSE; -- cgit v1.2.3-24-g4f1b From 741de1c1319dd13de75348863cca591713dd46ce Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 10 Nov 2010 14:52:57 -0600 Subject: Updating PHP requirements in files 5.1.6 --- system/libraries/Calendar.php | 2 +- system/libraries/Cart.php | 2 +- system/libraries/Driver.php | 2 +- system/libraries/Email.php | 2 +- system/libraries/Encrypt.php | 2 +- system/libraries/Form_validation.php | 2 +- system/libraries/Ftp.php | 2 +- system/libraries/Image_lib.php | 2 +- system/libraries/Javascript.php | 2 +- system/libraries/Log.php | 2 +- system/libraries/Pagination.php | 2 +- system/libraries/Parser.php | 2 +- system/libraries/Profiler.php | 2 +- system/libraries/Security.php | 2 +- system/libraries/Session.php | 2 +- system/libraries/Sha1.php | 2 +- system/libraries/Table.php | 2 +- system/libraries/Trackback.php | 2 +- system/libraries/Typography.php | 2 +- system/libraries/Unit_test.php | 2 +- system/libraries/Upload.php | 2 +- system/libraries/User_agent.php | 2 +- system/libraries/Xmlrpc.php | 2 +- system/libraries/Xmlrpcs.php | 2 +- system/libraries/Zip.php | 2 +- 25 files changed, 25 insertions(+), 25 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 924333faa..752ce254b 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index f3969ef2c..f2121bcac 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index 1261b4c72..2eb9c1e5e 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author EllisLab Dev Team diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 043e14bc4..fbf494d32 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index b95dd999c..f64c10c5d 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 566655b12..cab6f34fd 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index fa2d3770b..4cf95ee0e 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 99225600f..c9c8ced0f 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php index 30b62e1c2..8b7efd2c4 100644 --- a/system/libraries/Javascript.php +++ b/system/libraries/Javascript.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 99ed126f4..d4a687191 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index b3175f997..e5a59ed76 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index b969ce4d4..f7320c5a0 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 796db2d6b..0b73abd27 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Security.php b/system/libraries/Security.php index fa5317ea3..0fa1428be 100644 --- a/system/libraries/Security.php +++ b/system/libraries/Security.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 1e606de9c..e7842d847 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index ff7e72033..d9f0e3952 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 2fc1b634d..82d0a3e9d 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index a8be8a877..c2350947a 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index d8b295e7b..e08708562 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 9a90cb47c..2f6067b5e 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index c83d0aeaa..2e3d75832 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 00cbf6967..a780ec231 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 54ee70771..44cdffecd 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 56fd655df..14e10d22c 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index da3e5eb63..aa5cf13b0 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team -- cgit v1.2.3-24-g4f1b From 5ac559479a621eb35ff11ab86c529910aed8c052 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 10 Nov 2010 14:59:47 -0600 Subject: Changing method visibility in the Profiler class --- system/libraries/Profiler.php | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 0b73abd27..4441a9fbe 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -34,7 +34,7 @@ class CI_Profiler { var $CI; - var $_available_sections = array( + protected $_available_sections = array( 'benchmarks', 'get', 'memory_usage', @@ -46,7 +46,7 @@ class CI_Profiler { 'config' ); - function CI_Profiler($config = array()) + public function __construct($config = array()) { $this->CI =& get_instance(); $this->CI->load->language('profiler'); @@ -70,11 +70,10 @@ class CI_Profiler { * * Sets the private _compile_* properties to enable/disable Profiler sections * - * @access public * @param mixed * @return void */ - function set_sections($config) + public function set_sections($config) { foreach ($config as $method => $enable) { @@ -94,11 +93,10 @@ class CI_Profiler { * matches any two points that are named identically (ending in "_start" * and "_end" respectively). It then compiles the execution times for * all points and returns it as an array - * @PHP4 - all methods should be declared private - * @access private + * * @return array */ - function _compile_benchmarks() + protected function _compile_benchmarks() { $profile = array(); foreach ($this->CI->benchmark->marker as $key => $val) @@ -142,10 +140,9 @@ class CI_Profiler { /** * Compile Queries * - * @access private * @return string */ - function _compile_queries() + protected function _compile_queries() { $dbs = array(); @@ -224,10 +221,9 @@ class CI_Profiler { /** * Compile $_GET Data * - * @access private * @return string */ - function _compile_get() + protected function _compile_get() { $output = "\n\n"; $output .= '
'; @@ -274,10 +270,9 @@ class CI_Profiler { /** * Compile $_POST Data * - * @access private * @return string */ - function _compile_post() + protected function _compile_post() { $output = "\n\n"; $output .= '
'; @@ -324,10 +319,9 @@ class CI_Profiler { /** * Show query string * - * @access private * @return string */ - function _compile_uri_string() + protected function _compile_uri_string() { $output = "\n\n"; $output .= '
'; @@ -354,10 +348,9 @@ class CI_Profiler { /** * Show the controller and function that were called * - * @access private * @return string */ - function _compile_controller_info() + protected function _compile_controller_info() { $output = "\n\n"; $output .= '
'; @@ -380,10 +373,9 @@ class CI_Profiler { * * Display total used memory * - * @access public * @return string */ - function _compile_memory_usage() + protected function _compile_memory_usage() { $output = "\n\n"; $output .= '
'; @@ -412,10 +404,9 @@ class CI_Profiler { * * Lists HTTP headers * - * @access public * @return string */ - function _compile_http_headers() + protected function _compile_http_headers() { $output = "\n\n"; $output .= '
'; @@ -444,10 +435,9 @@ class CI_Profiler { * * Lists developer config variables * - * @access public * @return string */ - function _compile_config() + protected function _compile_config() { $output = "\n\n"; $output .= '
'; @@ -478,10 +468,9 @@ class CI_Profiler { /** * Run the Profiler * - * @access private * @return string */ - function run() + public function run() { $output = "
"; $fields_displayed = 0; -- cgit v1.2.3-24-g4f1b From c0af6c044570e0561afdea109f4101dba04e2510 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Wed, 10 Nov 2010 16:05:35 -0500 Subject: removing a few php 4 workarounds from the image lib. --- system/libraries/Image_lib.php | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index c9c8ced0f..dec5f34f6 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -712,14 +712,6 @@ class CI_Image_lib { */ function image_rotate_gd() { - // Is Image Rotation Supported? - // this function is only supported as of PHP 4.3 - if ( ! function_exists('imagerotate')) - { - $this->set_error('imglib_rotate_unsupported'); - return FALSE; - } - // Create the image handle if ( ! ($src_img = $this->image_create_gd())) { @@ -1215,11 +1207,6 @@ class CI_Image_lib { return FALSE; } - if (phpversion() == '4.4.1') - { - @touch($this->full_dst_path); // PHP 4.4.1 bug #35060 - workaround - } - if ( ! @imagejpeg($resource, $this->full_dst_path, $this->quality)) { $this->set_error('imglib_save_failed'); -- cgit v1.2.3-24-g4f1b From 58fdee85181b05c7303b1d2a5a26cb2f4e00f03f Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 10 Nov 2010 15:07:09 -0600 Subject: setting var/function visibility in the UPload class --- system/libraries/Upload.php | 134 ++++++++++++++++++-------------------------- 1 file changed, 54 insertions(+), 80 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 2e3d75832..4ccbdde90 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -26,40 +26,40 @@ */ class CI_Upload { - var $max_size = 0; - var $max_width = 0; - var $max_height = 0; - var $max_filename = 0; - var $allowed_types = ""; - var $file_temp = ""; - var $file_name = ""; - var $orig_name = ""; - var $file_type = ""; - var $file_size = ""; - var $file_ext = ""; - var $upload_path = ""; - var $overwrite = FALSE; - var $encrypt_name = FALSE; - var $is_image = FALSE; - var $image_width = ''; - var $image_height = ''; - var $image_type = ''; - var $image_size_str = ''; - var $error_msg = array(); - var $mimes = array(); - var $remove_spaces = TRUE; - var $xss_clean = FALSE; - var $temp_prefix = "temp_file_"; - var $client_name = ''; - - var $_file_name_override = ''; //@PHP4 (should be private) + public $max_size = 0; + public $max_width = 0; + public $max_height = 0; + public $max_filename = 0; + public $allowed_types = ""; + public $file_temp = ""; + public $file_name = ""; + public $orig_name = ""; + public $file_type = ""; + public $file_size = ""; + public $file_ext = ""; + public $upload_path = ""; + public $overwrite = FALSE; + public $encrypt_name = FALSE; + public $is_image = FALSE; + public $image_width = ''; + public $image_height = ''; + public $image_type = ''; + public $image_size_str = ''; + public $error_msg = array(); + public $mimes = array(); + public $remove_spaces = TRUE; + public $xss_clean = FALSE; + public $temp_prefix = "temp_file_"; + public $client_name = ''; + + protected $_file_name_override = ''; /** * Constructor * * @access public */ - function CI_Upload($props = array()) + public function __construct($props = array()) { if (count($props) > 0) { @@ -74,12 +74,10 @@ class CI_Upload { /** * Initialize preferences * - * @access public * @param array * @return void */ - - function initialize($config = array()) + public function initialize($config = array()) { $defaults = array( 'max_size' => 0, @@ -140,10 +138,9 @@ class CI_Upload { /** * Perform the file upload * - * @access public * @return bool */ - function do_upload($field = 'userfile') + public function do_upload($field = 'userfile') { // Is $_FILES[$field] set? If not, no reason to continue. if ( ! isset($_FILES[$field])) @@ -328,10 +325,9 @@ class CI_Upload { * 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() + public function data() { return array ( 'file_name' => $this->file_name, @@ -356,11 +352,10 @@ class CI_Upload { /** * Set Upload Path * - * @access public * @param string * @return void */ - function set_upload_path($path) + public function set_upload_path($path) { // Make sure it has a trailing slash $this->upload_path = rtrim($path, '/').'/'; @@ -375,12 +370,11 @@ class CI_Upload { * existence of a file with the same name. If found, it will append a * number to the end of the filename to avoid overwriting a pre-existing file. * - * @access public * @param string * @param string * @return string */ - function set_filename($path, $filename) + public function set_filename($path, $filename) { if ($this->encrypt_name == TRUE) { @@ -421,11 +415,10 @@ class CI_Upload { /** * Set Maximum File Size * - * @access public * @param integer * @return void */ - function set_max_filesize($n) + public function set_max_filesize($n) { $this->max_size = ((int) $n < 0) ? 0: (int) $n; } @@ -435,11 +428,10 @@ class CI_Upload { /** * Set Maximum File Name Length * - * @access public * @param integer * @return void */ - function set_max_filename($n) + public function set_max_filename($n) { $this->max_filename = ((int) $n < 0) ? 0: (int) $n; } @@ -449,11 +441,10 @@ class CI_Upload { /** * Set Maximum Image Width * - * @access public * @param integer * @return void */ - function set_max_width($n) + public function set_max_width($n) { $this->max_width = ((int) $n < 0) ? 0: (int) $n; } @@ -463,11 +454,10 @@ class CI_Upload { /** * Set Maximum Image Height * - * @access public * @param integer * @return void */ - function set_max_height($n) + public function set_max_height($n) { $this->max_height = ((int) $n < 0) ? 0: (int) $n; } @@ -477,11 +467,10 @@ class CI_Upload { /** * Set Allowed File Types * - * @access public * @param string * @return void */ - function set_allowed_types($types) + public function set_allowed_types($types) { if ( ! is_array($types) && $types == '*') { @@ -498,11 +487,10 @@ class CI_Upload { * * Uses GD to determine the width/height/type of image * - * @access public * @param string * @return void */ - function set_image_properties($path = '') + public function set_image_properties($path = '') { if ( ! $this->is_image()) { @@ -531,11 +519,10 @@ class CI_Upload { * Enables the XSS flag so that the file that was uploaded * will be run through the XSS filter. * - * @access public * @param bool * @return void */ - function set_xss_clean($flag = FALSE) + public function set_xss_clean($flag = FALSE) { $this->xss_clean = ($flag == TRUE) ? TRUE : FALSE; } @@ -545,10 +532,9 @@ class CI_Upload { /** * Validate the image * - * @access public * @return bool */ - function is_image() + public function is_image() { // IE will sometimes return odd mime-types during upload, so here we just standardize all // jpegs or pngs to the same file type. @@ -580,10 +566,9 @@ class CI_Upload { /** * Verify that the filetype is allowed * - * @access public * @return bool */ - function is_allowed_filetype($ignore_mime = FALSE) + public function is_allowed_filetype($ignore_mime = FALSE) { if ($this->allowed_types == '*') { @@ -641,10 +626,9 @@ class CI_Upload { /** * Verify that the file is within the allowed size * - * @access public * @return bool */ - function is_allowed_filesize() + public function is_allowed_filesize() { if ($this->max_size != 0 AND $this->file_size > $this->max_size) { @@ -661,10 +645,9 @@ class CI_Upload { /** * Verify that the image is within the allowed width/height * - * @access public * @return bool */ - function is_allowed_dimensions() + public function is_allowed_dimensions() { if ( ! $this->is_image()) { @@ -699,10 +682,9 @@ class CI_Upload { * Verifies that it is a valid upload path with proper permissions. * * - * @access public * @return bool */ - function validate_upload_path() + public function validate_upload_path() { if ($this->upload_path == '') { @@ -736,11 +718,10 @@ class CI_Upload { /** * Extract the file extension * - * @access public * @param string * @return string */ - function get_extension($filename) + public function get_extension($filename) { $x = explode('.', $filename); return '.'.end($x); @@ -751,11 +732,10 @@ class CI_Upload { /** * Clean the file name for security * - * @access public * @param string * @return string */ - function clean_file_name($filename) + public function clean_file_name($filename) { $bad = array( "' => '-->', - ' '<![CDATA[' - ); - /* never allowed, regex replacement */ - public $never_allowed_regex = array( - "javascript\s*:" => '[removed]', - "expression\s*(\(|&\#40;)" => '[removed]', // CSS and IE - "vbscript\s*:" => '[removed]', // IE, surprise! - "Redirect\s+302" => '[removed]' - ); + protected $_never_allowed_str = array( + 'document.cookie' => '[removed]', + 'document.write' => '[removed]', + '.parentNode' => '[removed]', + '.innerHTML' => '[removed]', + 'window.location' => '[removed]', + '-moz-binding' => '[removed]', + '' => '-->', + ' '<![CDATA[' + ); + /* never allowed, regex replacement */ + protected $_never_allowed_regex = array( + "javascript\s*:" => '[removed]', + "expression\s*(\(|&\#40;)" => '[removed]', // CSS and IE + "vbscript\s*:" => '[removed]', // IE, surprise! + "Redirect\s+302" => '[removed]' + ); + + /** + * Constructor + */ public function __construct() { - $this->csrf_token_name = (config_item('csrf_token_name')) ? config_item('csrf_token_name') : 'csrf_token_name'; - $this->csrf_cookie_name = (config_item('csrf_cookie_name')) ? config_item('csrf_cookie_name') : 'csrf_cookie_name'; - $this->csrf_expire = (config_item('csrf_expire')) ? config_item('csrf_expire') : 7200; - // Append application specific cookie prefix to token name - $this->csrf_cookie_name = (config_item('cookie_prefix')) ? config_item('cookie_prefix').$this->csrf_token_name : $this->csrf_token_name; + $this->_csrf_cookie_name = (config_item('cookie_prefix')) ? config_item('cookie_prefix').$this->_csrf_token_name : $this->_csrf_token_name; // Set the CSRF hash $this->_csrf_set_hash(); @@ -72,8 +72,7 @@ class CI_Security { /** * Verify Cross Site Request Forgery Protection * - * @access public - * @return null + * @return object */ public function csrf_verify() { @@ -84,26 +83,30 @@ class CI_Security { } // Do the tokens exist in both the _POST and _COOKIE arrays? - if ( ! isset($_POST[$this->csrf_token_name]) OR ! isset($_COOKIE[$this->csrf_cookie_name])) + if ( ! isset($_POST[$this->_csrf_token_name]) OR + ! isset($_COOKIE[$this->_csrf_cookie_name])) { $this->csrf_show_error(); } // Do the tokens match? - if ($_POST[$this->csrf_token_name] != $_COOKIE[$this->csrf_cookie_name]) + if ($_POST[$this->_csrf_token_name] != $_COOKIE[$this->_csrf_cookie_name]) { $this->csrf_show_error(); } - // We kill this since we're done and we don't want to polute the _POST array - unset($_POST[$this->csrf_token_name]); + // 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]); + unset($_COOKIE[$this->_csrf_cookie_name]); $this->_csrf_set_hash(); $this->csrf_set_cookie(); log_message('debug', "CSRF token verified "); + + return $this; } // -------------------------------------------------------------------- @@ -111,57 +114,68 @@ class CI_Security { /** * Set Cross Site Request Forgery Protection Cookie * - * @access public - * @return null + * @return object */ public function csrf_set_cookie() { - $expire = time() + $this->csrf_expire; + $expire = time() + $this->_csrf_expire; $secure_cookie = (config_item('cookie_secure') === TRUE) ? 1 : 0; - setcookie($this->csrf_cookie_name, $this->csrf_hash, $expire, config_item('cookie_path'), config_item('cookie_domain'), $secure_cookie); + if ($secure_cookie) + { + $req = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : FALSE; + + if ( ! $req OR $req == 'off') + { + return FALSE; + } + } + + setcookie($this->_csrf_cookie_name, $this->_csrf_hash, $expire, config_item('cookie_path'), config_item('cookie_domain'), $secure_cookie); log_message('debug', "CRSF cookie Set"); + + return $this; } // -------------------------------------------------------------------- /** - * Set Cross Site Request Forgery Protection Cookie + * Show CSRF Error * - * @access private - * @return null + * @return void */ - private function _csrf_set_hash() + public function csrf_show_error() { - if ($this->csrf_hash == '') - { - // If the cookie exists we will use it's value. We don't necessarily want to regenerate it with - // each page load since a page could contain embedded sub-pages causing this feature to fail - if (isset($_COOKIE[$this->csrf_cookie_name]) AND $_COOKIE[$this->csrf_cookie_name] != '') - { - $this->csrf_hash = $_COOKIE[$this->csrf_cookie_name]; - } - else - { - $this->csrf_hash = md5(uniqid(rand(), TRUE)); - } - } + show_error('The action you have requested is not allowed.'); + } - return $this->csrf_hash; + // -------------------------------------------------------------------- + + /** + * Get CSRF Hash + * + * Getter Method + * + * @return string self::_csrf_hash + */ + public function get_csrf_hash() + { + return $this->_csrf_hash; } // -------------------------------------------------------------------- /** - * Show CSRF Error + * Get CSRF Token Name * - * @access public - * @return null + * Getter Method + * + * @return string self::csrf_token_name */ - public function csrf_show_error() + public function get_csrf_token_name() { - show_error('The action you have requested is not allowed.'); + return $this->_csrf_token_name; } // -------------------------------------------------------------------- @@ -188,7 +202,6 @@ class CI_Security { * harvested from examining vulnerabilities in other programs: * http://ha.ckers.org/xss.html * - * @access public * @param mixed string or array * @return string */ @@ -213,35 +226,8 @@ class CI_Security { */ $str = remove_invisible_characters($str); - /* - * Protect GET variables in URLs - */ - - // 901119URL5918AMP18930PROTECT8198 - - $str = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)|i', $this->xss_hash()."\\1=\\2", $str); - - /* - * Validate standard character entities - * - * Add a semicolon if missing. We do this to enable - * the conversion of entities to ASCII later. - * - */ - $str = preg_replace('#(&\#?[0-9a-z]{2,})([\x00-\x20])*;?#i', "\\1;\\2", $str); - - /* - * Validate UTF16 two byte encoding (x00) - * - * Just as above, adds a semicolon if missing. - * - */ - $str = preg_replace('#(&\#x?)([0-9A-F]+);?#i',"\\1\\2;",$str); - - /* - * Un-Protect GET variables in URLs - */ - $str = str_replace($this->xss_hash(), '&', $str); + // Validate Entities in URLs + $str = $this->_validate_entities($str); /* * URL Decode @@ -265,7 +251,7 @@ class CI_Security { */ $str = preg_replace_callback("/[a-z]+=([\'\"]).*?\\1/si", array($this, '_convert_attribute'), $str); - + $str = preg_replace_callback("/<\w+.*?(?=>|<|$)/si", array($this, '_decode_entity'), $str); /* @@ -278,9 +264,8 @@ class CI_Security { * * This prevents strings like this: ja vascript * NOTE: we deal with spaces between characters later. - * NOTE: preg_replace was found to be amazingly slow here on large blocks of data, - * so we use str_replace. - * + * NOTE: preg_replace was found to be amazingly slow here on + * large blocks of data, so we use str_replace. */ if (strpos($str, "\t") !== FALSE) @@ -293,34 +278,23 @@ class CI_Security { */ $converted_string = $str; - /* - * Not Allowed Under Any Conditions - */ - - foreach ($this->never_allowed_str as $key => $val) - { - $str = str_replace($key, $val, $str); - } - - foreach ($this->never_allowed_regex as $key => $val) - { - $str = preg_replace("#".$key."#i", $val, $str); - } + // Remove Strings that are never allowed + $str = $this->_do_never_allowed($str); /* * Makes PHP tags safe * - * Note: XML tags are inadvertently replaced too: + * Note: XML tags are inadvertently replaced too: * - * #si", '[removed]', $str); } } - while ($original != $str); + while($original != $str); unset($original); - /* - * Remove JavaScript Event Handlers - * - * Note: This code is a little blunt. It removes - * the event handler and anything up to the closing >, - * but it's unlikely to be a problem. - * - */ - $event_handlers = array('[^a-z_\-]on\w*','xmlns'); - - if ($is_image === TRUE) - { - /* - * 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); + // Remove evil attributes such as style, onclick and xmlns + $str = $this->_remove_evil_attributes($str, $is_image); /* * Sanitize naughty HTML elements @@ -407,7 +367,6 @@ class CI_Security { * * So this: * Becomes: <blink> - * */ $naughty = 'alert|applet|audio|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|isindex|layer|link|meta|object|plaintext|style|script|textarea|title|video|xml|xss'; $str = preg_replace_callback('#<(/*\s*)('.$naughty.')([^><]*)([><]*)#is', array($this, '_sanitize_naughty_html'), $str); @@ -423,45 +382,28 @@ class CI_Security { * * For example: eval('some code') * Becomes: eval('some code') - * */ $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 - * - * This adds a bit of extra precaution in case - * something got through the above filters - * - */ - foreach ($this->never_allowed_str as $key => $val) - { - $str = str_replace($key, $val, $str); - } - foreach ($this->never_allowed_regex as $key => $val) - { - $str = preg_replace("#".$key."#i", $val, $str); - } + // Final clean up + // This adds a bit of extra precaution in case + // something got through the above filters + $str = $this->_do_never_allowed($str); /* - * Images are Handled in a Special Way - * - Essentially, we want to know that after all of the character conversion is done whether - * any unwanted, likely XSS, code was found. If not, we return TRUE, as the image is clean. - * However, if the string post-conversion does not matched the string post-removal of XSS, - * then it fails, as there was unwanted XSS code found and removed/changed during processing. + * Images are Handled in a Special Way + * - Essentially, we want to know that after all of the character + * conversion is done whether any unwanted, likely XSS, code was found. + * If not, we return TRUE, as the image is clean. + * However, if the string post-conversion does not matched the + * string post-removal of XSS, then it fails, as there was unwanted XSS + * code found and removed/changed during processing. */ if ($is_image === TRUE) { - if ($str == $converted_string) - { - return TRUE; - } - else - { - return FALSE; - } + return ($str == $converted_string) ? TRUE: FALSE; } log_message('debug', "XSS Filtering completed"); @@ -473,41 +415,190 @@ class CI_Security { /** * Random Hash for protecting URLs * - * @access public * @return string */ public function xss_hash() { - if ($this->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)); + $this->_xss_hash = md5(time() + mt_rand(0, 1999999999)); } - return $this->xss_hash; + return $this->_xss_hash; } // -------------------------------------------------------------------- + /** + * HTML Entities Decode + * + * This function is a replacement for html_entity_decode() + * + * In some versions of PHP the native function does not work + * when UTF-8 is the specified character set, so this gives us + * a work-around. More info here: + * http://bugs.php.net/bug.php?id=25670 + * + * NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the + * character set, and the PHP developers said they were not back porting the + * fix to versions other than PHP 5.x. + * + * @param string + * @param string + * @return string + */ + public 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')) + { + $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 + * + * @param string + * @return string + */ + public function sanitize_filename($str, $relative_path = FALSE) + { + $bad = array( + "../", + "", + "<", + ">", + "'", + '"', + '&', + '$', + '#', + '{', + '}', + '[', + ']', + '=', + ';', + '?', + "%20", + "%22", + "%3c", // < + "%253c", // < + "%3e", // > + "%0e", // > + "%28", // ( + "%29", // ) + "%2528", // ( + "%26", // & + "%24", // $ + "%3f", // ? + "%3b", // ; + "%3d" // = + ); + + if ( ! $relative_path) + { + $bad[] = './'; + $bad[] = '/'; + } + + $str = remove_invisible_characters($str, FALSE); + return stripslashes(str_replace($bad, '', $str)); + } + + // ---------------------------------------------------------------- + /** * Compact Exploded Words * * Callback function for xss_clean() to remove whitespace from * things like j a v a s c r i p t * - * @access private * @param type * @return type */ - private function _compact_exploded_words($matches) + protected function _compact_exploded_words($matches) { return preg_replace('/\s+/s', '', $matches[1]).$matches[2]; } + // -------------------------------------------------------------------- + + /* + * Remove Evil HTML Attributes (like evenhandlers and style) + * + * It removes the evil attribute and either: + * - Everything up until a space + * For example, everything between the pipes: + * + * - Everything inside the quotes + * For example, everything between the pipes: + * + * + * @param string $str The string to check + * @param boolean $is_image TRUE if this is an image + * @return string The string with the evil attributes removed + */ + protected function _remove_evil_attributes($str, $is_image) + { + // All javascript event handlers (e.g. onload, onclick, onmouseover), style, and xmlns + $evil_attributes = array('on\w*', 'style', 'xmlns'); + + if ($is_image === TRUE) + { + /* + * Adobe Photoshop puts XML metadata into JFIF images, + * including namespacing, so we have to allow this for images. + */ + unset($evil_attributes[array_search('xmlns', $evil_attributes)]); + } + + do { + $str = preg_replace( + "#<(/?[^><]+?)([^A-Za-z\-])(".implode('|', $evil_attributes).")(\s*=\s*)([\"][^>]*?[\"]|[\'][^>]*?[\']|[^>]*?)([\s><])([><]*)#i", + "<$1$6", + $str, -1, $count + ); + } while ($count); + + return $str; + } + // -------------------------------------------------------------------- /** @@ -515,17 +606,17 @@ class CI_Security { * * Callback function for xss_clean() to remove naughty HTML elements * - * @access private * @param array * @return string */ - private function _sanitize_naughty_html($matches) + protected function _sanitize_naughty_html($matches) { // 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]); + $str .= str_replace(array('>', '<'), array('>', '<'), + $matches[4]); return $str; } @@ -540,16 +631,18 @@ class CI_Security { * and prevents PREG_BACKTRACK_LIMIT_ERROR from being triggered in * PHP 5.2+ on link-heavy strings * - * @access private * @param array * @return string */ - private function _js_link_removal($match) + protected function _js_link_removal($match) { $attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1])); - return str_replace($match[1], preg_replace("#href=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|_filter_attributes(str_replace(array('<', '>'), '', $match[1])); - return str_replace($match[1], preg_replace("#src=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|', '<', '\\'), array('>', '<', '\\\\'), $match[0]); } @@ -591,11 +683,10 @@ class CI_Security { * * Filters tag attributes for consistency and safety * - * @access private * @param string * @return string */ - private function _filter_attributes($str) + protected function _filter_attributes($str) { $out = ''; @@ -617,118 +708,109 @@ class CI_Security { * * Used as a callback for XSS Clean * - * @access private * @param array * @return string */ - private function _decode_entity($match) + protected function _decode_entity($match) { return $this->entity_decode($match[0], strtoupper(config_item('charset'))); } // -------------------------------------------------------------------- - + /** - * HTML Entities Decode - * - * This function is a replacement for html_entity_decode() - * - * In some versions of PHP the native function does not work - * when UTF-8 is the specified character set, so this gives us - * a work-around. More info here: - * http://bugs.php.net/bug.php?id=25670 + * Validate URL entities * - * NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the - * character set, and the PHP developers said they were not back porting the - * fix to versions other than PHP 5.x. + * Called by xss_clean() * - * @access public - * @param string - * @param string - * @return string + * @param string + * @return string */ - public function entity_decode($str, $charset='UTF-8') + protected function _validate_entities($str) { - if (stristr($str, '&') === FALSE) return $str; + /* + * Protect GET variables in URLs + */ + + // 901119URL5918AMP18930PROTECT8198 + + $str = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)|i', $this->xss_hash()."\\1=\\2", $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. + /* + * Validate standard character entities + * + * Add a semicolon if missing. We do this to enable + * the conversion of entities to ASCII later. + * + */ + $str = preg_replace('#(&\#?[0-9a-z]{2,})([\x00-\x20])*;?#i', "\\1;\\2", $str); - 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); - } + /* + * Validate UTF16 two byte encoding (x00) + * + * Just as above, adds a semicolon if missing. + * + */ + $str = preg_replace('#(&\#x?)([0-9A-F]+);?#i',"\\1\\2;",$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); + /* + * Un-Protect GET variables in URLs + */ + $str = str_replace($this->xss_hash(), '&', $str); + + return $str; + } - // Literal Entities - Slightly slow so we do another check - if (stristr($str, '&') === FALSE) + // ---------------------------------------------------------------------- + + /** + * Do Never Allowed + * + * A utility function for xss_clean() + * + * @param string + * @return string + */ + protected function _do_never_allowed($str) + { + foreach ($this->_never_allowed_str as $key => $val) { - $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES))); + $str = str_replace($key, $val, $str); } + foreach ($this->_never_allowed_regex as $key => $val) + { + $str = preg_replace("#".$key."#i", $val, $str); + } + return $str; } // -------------------------------------------------------------------- /** - * Filename Security + * Set Cross Site Request Forgery Protection Cookie * - * @access public - * @param string * @return string */ - public function sanitize_filename($str, $relative_path = FALSE) + protected function _csrf_set_hash() { - $bad = array( - "../", - "", - "<", - ">", - "'", - '"', - '&', - '$', - '#', - '{', - '}', - '[', - ']', - '=', - ';', - '?', - "%20", - "%22", - "%3c", // < - "%253c", // < - "%3e", // > - "%0e", // > - "%28", // ( - "%29", // ) - "%2528", // ( - "%26", // & - "%24", // $ - "%3f", // ? - "%3b", // ; - "%3d" // = - ); - - if ( ! $relative_path) + if ($this->_csrf_hash == '') { - $bad[] = './'; - $bad[] = '/'; + // If the cookie exists we will use it's value. + // We don't necessarily want to regenerate it with + // each page load since a page could contain embedded + // sub-pages causing this feature to fail + if (isset($_COOKIE[$this->_csrf_cookie_name]) && + $_COOKIE[$this->_csrf_cookie_name] != '') + { + return $this->_csrf_hash = $_COOKIE[$this->_csrf_cookie_name]; + } + + return $this->_csrf_hash = md5(uniqid(rand(), TRUE)); } - return stripslashes(str_replace($bad, '', $str)); + return $this->_csrf_hash; } } -- cgit v1.2.3-24-g4f1b From 14a0ac63a9dfb72e4681c37f7727cd48882152bd Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Tue, 5 Apr 2011 14:55:56 -0400 Subject: Moving security to core. --- system/libraries/Security.php | 820 ------------------------------------------ 1 file changed, 820 deletions(-) delete mode 100644 system/libraries/Security.php (limited to 'system/libraries') diff --git a/system/libraries/Security.php b/system/libraries/Security.php deleted file mode 100644 index ceef9779c..000000000 --- a/system/libraries/Security.php +++ /dev/null @@ -1,820 +0,0 @@ - '[removed]', - 'document.write' => '[removed]', - '.parentNode' => '[removed]', - '.innerHTML' => '[removed]', - 'window.location' => '[removed]', - '-moz-binding' => '[removed]', - '' => '-->', - ' '<![CDATA[' - ); - - /* never allowed, regex replacement */ - protected $_never_allowed_regex = array( - "javascript\s*:" => '[removed]', - "expression\s*(\(|&\#40;)" => '[removed]', // CSS and IE - "vbscript\s*:" => '[removed]', // IE, surprise! - "Redirect\s+302" => '[removed]' - ); - - /** - * Constructor - */ - public function __construct() - { - // Append application specific cookie prefix to token name - $this->_csrf_cookie_name = (config_item('cookie_prefix')) ? config_item('cookie_prefix').$this->_csrf_token_name : $this->_csrf_token_name; - - // Set the CSRF hash - $this->_csrf_set_hash(); - - log_message('debug', "Security Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Verify Cross Site Request Forgery Protection - * - * @return object - */ - public function csrf_verify() - { - // If no POST data exists we will set the CSRF cookie - if (count($_POST) == 0) - { - return $this->csrf_set_cookie(); - } - - // Do the tokens exist in both the _POST and _COOKIE arrays? - if ( ! isset($_POST[$this->_csrf_token_name]) OR - ! isset($_COOKIE[$this->_csrf_cookie_name])) - { - $this->csrf_show_error(); - } - - // Do the tokens match? - if ($_POST[$this->_csrf_token_name] != $_COOKIE[$this->_csrf_cookie_name]) - { - $this->csrf_show_error(); - } - - // 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(); - $this->csrf_set_cookie(); - - log_message('debug', "CSRF token verified "); - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Set Cross Site Request Forgery Protection Cookie - * - * @return object - */ - public function csrf_set_cookie() - { - $expire = time() + $this->_csrf_expire; - $secure_cookie = (config_item('cookie_secure') === TRUE) ? 1 : 0; - - if ($secure_cookie) - { - $req = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : FALSE; - - if ( ! $req OR $req == 'off') - { - return FALSE; - } - } - - setcookie($this->_csrf_cookie_name, $this->_csrf_hash, $expire, config_item('cookie_path'), config_item('cookie_domain'), $secure_cookie); - - log_message('debug', "CRSF cookie Set"); - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Show CSRF Error - * - * @return void - */ - public function csrf_show_error() - { - show_error('The action you have requested is not allowed.'); - } - - // -------------------------------------------------------------------- - - /** - * Get CSRF Hash - * - * Getter Method - * - * @return string self::_csrf_hash - */ - public function get_csrf_hash() - { - return $this->_csrf_hash; - } - - // -------------------------------------------------------------------- - - /** - * Get CSRF Token Name - * - * Getter Method - * - * @return string self::csrf_token_name - */ - public function get_csrf_token_name() - { - return $this->_csrf_token_name; - } - - // -------------------------------------------------------------------- - - /** - * XSS Clean - * - * Sanitizes data so that Cross Site Scripting Hacks can be - * prevented. This function does a fair amount of work but - * it is extremely thorough, designed to prevent even the - * most obscure XSS attempts. Nothing is ever 100% foolproof, - * of course, but I haven't been able to get anything passed - * the filter. - * - * Note: This function should only be used to deal with data - * upon submission. It's not something that should - * be used for general runtime processing. - * - * This function was based in part on some code and ideas I - * got from Bitflux: http://channel.bitflux.ch/wiki/XSS_Prevention - * - * To help develop this script I used this great list of - * vulnerabilities along with a few other hacks I've - * harvested from examining vulnerabilities in other programs: - * http://ha.ckers.org/xss.html - * - * @param mixed string or array - * @return string - */ - public function xss_clean($str, $is_image = FALSE) - { - /* - * Is the string an array? - * - */ - if (is_array($str)) - { - while (list($key) = each($str)) - { - $str[$key] = $this->xss_clean($str[$key]); - } - - return $str; - } - - /* - * Remove Invisible Characters - */ - $str = remove_invisible_characters($str); - - // Validate Entities in URLs - $str = $this->_validate_entities($str); - - /* - * URL Decode - * - * Just in case stuff like this is submitted: - * - * Google - * - * Note: Use rawurldecode() so it does not remove plus signs - * - */ - $str = rawurldecode($str); - - /* - * Convert character entities to ASCII - * - * This permits our tests below to work reliably. - * We only convert entities that are within tags since - * these are the ones that will pose security problems. - * - */ - - $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 - * - * This prevents strings like this: ja vascript - * NOTE: we deal with spaces between characters later. - * NOTE: preg_replace was found to be amazingly slow here on - * large blocks of data, so we use str_replace. - */ - - if (strpos($str, "\t") !== FALSE) - { - $str = str_replace("\t", ' ', $str); - } - - /* - * Capture converted string for later comparison - */ - $converted_string = $str; - - // Remove Strings that are never allowed - $str = $this->_do_never_allowed($str); - - /* - * Makes PHP tags safe - * - * Note: XML tags are inadvertently replaced too: - * - * '), array('<?', '?>'), $str); - } - - /* - * Compact any exploded words - * - * This corrects words like: j a v a s c r i p t - * These words are compacted back to their correct state. - */ - $words = array( - 'javascript', 'expression', 'vbscript', 'script', - 'applet', 'alert', 'document', 'write', 'cookie', 'window' - ); - - foreach ($words as $word) - { - $temp = ''; - - for ($i = 0, $wordlen = strlen($word); $i < $wordlen; $i++) - { - $temp .= substr($word, $i, 1)."\s*"; - } - - // We only want to do this when it is followed by a non-word character - // 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 to these simplified non-capturing - * preg_match(), especially if the pattern exists in the string - */ - do - { - $original = $str; - - if (preg_match("/]*?)(>|$)#si", array($this, '_js_link_removal'), $str); - } - - if (preg_match("/]*?)(\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); - } - } - while($original != $str); - - unset($original); - - // Remove evil attributes such as style, onclick and xmlns - $str = $this->_remove_evil_attributes($str, $is_image); - - /* - * Sanitize naughty HTML elements - * - * If a tag containing any of the words in the list - * below is found, the tag gets converted to entities. - * - * So this: - * Becomes: <blink> - */ - $naughty = 'alert|applet|audio|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|isindex|layer|link|meta|object|plaintext|style|script|textarea|title|video|xml|xss'; - $str = preg_replace_callback('#<(/*\s*)('.$naughty.')([^><]*)([><]*)#is', array($this, '_sanitize_naughty_html'), $str); - - /* - * Sanitize naughty scripting elements - * - * Similar to above, only instead of looking for - * tags it looks for PHP and JavaScript commands - * that are disallowed. Rather than removing the - * code, it simply converts the parenthesis to entities - * rendering the code un-executable. - * - * For example: eval('some code') - * Becomes: eval('some code') - */ - $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 - // This adds a bit of extra precaution in case - // something got through the above filters - $str = $this->_do_never_allowed($str); - - /* - * Images are Handled in a Special Way - * - Essentially, we want to know that after all of the character - * conversion is done whether any unwanted, likely XSS, code was found. - * If not, we return TRUE, as the image is clean. - * However, if the string post-conversion does not matched the - * string post-removal of XSS, then it fails, as there was unwanted XSS - * code found and removed/changed during processing. - */ - - if ($is_image === TRUE) - { - return ($str == $converted_string) ? TRUE: FALSE; - } - - log_message('debug', "XSS Filtering completed"); - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Random Hash for protecting URLs - * - * @return string - */ - public 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; - } - - // -------------------------------------------------------------------- - - /** - * HTML Entities Decode - * - * This function is a replacement for html_entity_decode() - * - * In some versions of PHP the native function does not work - * when UTF-8 is the specified character set, so this gives us - * a work-around. More info here: - * http://bugs.php.net/bug.php?id=25670 - * - * NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the - * character set, and the PHP developers said they were not back porting the - * fix to versions other than PHP 5.x. - * - * @param string - * @param string - * @return string - */ - public 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')) - { - $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 - * - * @param string - * @return string - */ - public function sanitize_filename($str, $relative_path = FALSE) - { - $bad = array( - "../", - "", - "<", - ">", - "'", - '"', - '&', - '$', - '#', - '{', - '}', - '[', - ']', - '=', - ';', - '?', - "%20", - "%22", - "%3c", // < - "%253c", // < - "%3e", // > - "%0e", // > - "%28", // ( - "%29", // ) - "%2528", // ( - "%26", // & - "%24", // $ - "%3f", // ? - "%3b", // ; - "%3d" // = - ); - - if ( ! $relative_path) - { - $bad[] = './'; - $bad[] = '/'; - } - - $str = remove_invisible_characters($str, FALSE); - return stripslashes(str_replace($bad, '', $str)); - } - - // ---------------------------------------------------------------- - - /** - * Compact Exploded Words - * - * Callback function for xss_clean() to remove whitespace from - * things like j a v a s c r i p t - * - * @param type - * @return type - */ - protected function _compact_exploded_words($matches) - { - return preg_replace('/\s+/s', '', $matches[1]).$matches[2]; - } - - // -------------------------------------------------------------------- - - /* - * Remove Evil HTML Attributes (like evenhandlers and style) - * - * It removes the evil attribute and either: - * - Everything up until a space - * For example, everything between the pipes: - * - * - Everything inside the quotes - * For example, everything between the pipes: - * - * - * @param string $str The string to check - * @param boolean $is_image TRUE if this is an image - * @return string The string with the evil attributes removed - */ - protected function _remove_evil_attributes($str, $is_image) - { - // All javascript event handlers (e.g. onload, onclick, onmouseover), style, and xmlns - $evil_attributes = array('on\w*', 'style', 'xmlns'); - - if ($is_image === TRUE) - { - /* - * Adobe Photoshop puts XML metadata into JFIF images, - * including namespacing, so we have to allow this for images. - */ - unset($evil_attributes[array_search('xmlns', $evil_attributes)]); - } - - do { - $str = preg_replace( - "#<(/?[^><]+?)([^A-Za-z\-])(".implode('|', $evil_attributes).")(\s*=\s*)([\"][^>]*?[\"]|[\'][^>]*?[\']|[^>]*?)([\s><])([><]*)#i", - "<$1$6", - $str, -1, $count - ); - } while ($count); - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Sanitize Naughty HTML - * - * Callback function for xss_clean() to remove naughty HTML elements - * - * @param array - * @return string - */ - protected function _sanitize_naughty_html($matches) - { - // 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 - * - * Callback function for xss_clean() to sanitize links - * This limits the PCRE backtracks, making it more performance friendly - * and prevents PREG_BACKTRACK_LIMIT_ERROR from being triggered in - * PHP 5.2+ on link-heavy strings - * - * @param array - * @return string - */ - protected function _js_link_removal($match) - { - $attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1])); - - return str_replace($match[1], preg_replace("#href=.*?(alert\(|alert&\#40;|javascript\:|livescript\:|mocha\:|charset\=|window\.|document\.|\.cookie|_filter_attributes(str_replace(array('<', '>'), '', $match[1])); - - return str_replace($match[1], preg_replace("#src=.*?(alert\(|alert&\#40;|javascript\:|livescript\:|mocha\:|charset\=|window\.|document\.|\.cookie|', '<', '\\'), array('>', '<', '\\\\'), $match[0]); - } - - // -------------------------------------------------------------------- - - /** - * Filter Attributes - * - * Filters tag attributes for consistency and safety - * - * @param string - * @return string - */ - protected function _filter_attributes($str) - { - $out = ''; - - if (preg_match_all('#\s*[a-z\-]+\s*=\s*(\042|\047)([^\\1]*?)\\1#is', $str, $matches)) - { - foreach ($matches[0] as $match) - { - $out .= preg_replace("#/\*.*?\*/#s", '', $match); - } - } - - return $out; - } - - // -------------------------------------------------------------------- - - /** - * HTML Entity Decode Callback - * - * Used as a callback for XSS Clean - * - * @param array - * @return string - */ - protected function _decode_entity($match) - { - return $this->entity_decode($match[0], strtoupper(config_item('charset'))); - } - - // -------------------------------------------------------------------- - - /** - * Validate URL entities - * - * Called by xss_clean() - * - * @param string - * @return string - */ - protected function _validate_entities($str) - { - /* - * Protect GET variables in URLs - */ - - // 901119URL5918AMP18930PROTECT8198 - - $str = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)|i', $this->xss_hash()."\\1=\\2", $str); - - /* - * Validate standard character entities - * - * Add a semicolon if missing. We do this to enable - * the conversion of entities to ASCII later. - * - */ - $str = preg_replace('#(&\#?[0-9a-z]{2,})([\x00-\x20])*;?#i', "\\1;\\2", $str); - - /* - * Validate UTF16 two byte encoding (x00) - * - * Just as above, adds a semicolon if missing. - * - */ - $str = preg_replace('#(&\#x?)([0-9A-F]+);?#i',"\\1\\2;",$str); - - /* - * Un-Protect GET variables in URLs - */ - $str = str_replace($this->xss_hash(), '&', $str); - - return $str; - } - - // ---------------------------------------------------------------------- - - /** - * Do Never Allowed - * - * A utility function for xss_clean() - * - * @param string - * @return string - */ - protected function _do_never_allowed($str) - { - foreach ($this->_never_allowed_str as $key => $val) - { - $str = str_replace($key, $val, $str); - } - - foreach ($this->_never_allowed_regex as $key => $val) - { - $str = preg_replace("#".$key."#i", $val, $str); - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Set Cross Site Request Forgery Protection Cookie - * - * @return string - */ - protected function _csrf_set_hash() - { - if ($this->_csrf_hash == '') - { - // If the cookie exists we will use it's value. - // We don't necessarily want to regenerate it with - // each page load since a page could contain embedded - // sub-pages causing this feature to fail - if (isset($_COOKIE[$this->_csrf_cookie_name]) && - $_COOKIE[$this->_csrf_cookie_name] != '') - { - return $this->_csrf_hash = $_COOKIE[$this->_csrf_cookie_name]; - } - - return $this->_csrf_hash = md5(uniqid(rand(), TRUE)); - } - - return $this->_csrf_hash; - } - -} -// END Security Class - -/* End of file Security.php */ -/* Location: ./system/libraries/Security.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 6984aaf27f53b91ab1eafcdccd5fb871dfcd5f18 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Tue, 5 Apr 2011 14:58:04 -0400 Subject: Removing security loading calls. --- system/libraries/Form_validation.php | 5 ----- system/libraries/Upload.php | 6 ------ system/libraries/Xmlrpc.php | 14 ++------------ 3 files changed, 2 insertions(+), 23 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index adfd17db1..cfc02eda9 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -1336,11 +1336,6 @@ class CI_Form_validation { */ function xss_clean($str) { - if ( ! isset($this->CI->security)) - { - $this->CI->load->library('security'); - } - return $this->CI->security->xss_clean($str); } diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 5816a5558..b62e0d73c 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -875,12 +875,6 @@ class CI_Upload { } $CI =& get_instance(); - - if ( ! isset($CI->security)) - { - $CI->load->library('security'); - } - return $CI->security->xss_clean($data, TRUE); } diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index a24bca9b6..5da6ea6ae 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -504,12 +504,7 @@ class XML_RPC_Response function decode($array=FALSE) { $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)) @@ -1121,12 +1116,7 @@ class XML_RPC_Message extends CI_Xmlrpc function output_parameters($array=FALSE) { $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)) -- cgit v1.2.3-24-g4f1b From f1bd6fa78a3235ade2365a43bb5124ff72807c96 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Tue, 5 Apr 2011 15:04:28 -0400 Subject: Fixed a bug in the Javascript Library where improperly escaped characters could result in arbitrary javascript execution. --- system/libraries/Javascript.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php index 167859abd..34e0d7001 100644 --- a/system/libraries/Javascript.php +++ b/system/libraries/Javascript.php @@ -855,7 +855,7 @@ class CI_Javascript { } elseif (is_string($result) OR $is_key) { - return '"'.str_replace(array('\\', "\t", "\n", "\r", '"'), array('\\\\', '\\t', '\\n', "\\r", '\"'), $result).'"'; + return '"'.str_replace(array('\\', "\t", "\n", "\r", '"', '/'), array('\\\\', '\\t', '\\n', "\\r", '\"', '\/'), $result).'"'; } elseif (is_scalar($result)) { -- cgit v1.2.3-24-g4f1b From 05fa61144667c85b0463f7e8baa6af00aa195dc6 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 6 Apr 2011 22:57:43 +0100 Subject: Made Environment Support optional. Comment out or delete the constant to stop environment checks. --- system/libraries/Upload.php | 2 +- system/libraries/User_agent.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 5816a5558..3cd2e4fc1 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -951,7 +951,7 @@ class CI_Upload { if (count($this->mimes) == 0) { - if (is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT)) + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT)) { include(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT); } diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 11af21491..04cda7312 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -84,7 +84,7 @@ class CI_User_agent { */ private function _load_agent_file() { - if (is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents'.EXT)) + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents'.EXT)) { include(APPPATH.'config/'.ENVIRONMENT.'/user_agents'.EXT); } -- cgit v1.2.3-24-g4f1b From 48bac74ea9fcb8eecdf97597647f1ed492d97b43 Mon Sep 17 00:00:00 2001 From: patwork Date: Fri, 8 Apr 2011 13:46:47 +0200 Subject: Fix: codeigniter-reactor/193 incorrect driver filepaths --- system/libraries/Driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index d1838f2c1..b942f539f 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -45,7 +45,7 @@ class CI_Driver_Library { $child_class = $this->lib_name.'_'.$child; // Remove the CI_ prefix and lowercase - $lib_name = strtolower(preg_replace('/^CI_/', '', $this->lib_name)); + $lib_name = ucfirst(strtolower(preg_replace('/^CI_/', '', $this->lib_name))); $driver_name = strtolower(preg_replace('/^CI_/', '', $child_class)); if (in_array($driver_name, array_map('strtolower', $this->valid_drivers))) @@ -226,4 +226,4 @@ class CI_Driver { // END CI_Driver CLASS /* End of file Driver.php */ -/* Location: ./system/libraries/Driver.php */ \ No newline at end of file +/* Location: ./system/libraries/Driver.php */ -- cgit v1.2.3-24-g4f1b From b07079827b084213463bdf576894faab172213f2 Mon Sep 17 00:00:00 2001 From: patwork Date: Fri, 8 Apr 2011 15:10:05 +0200 Subject: Deals with language errors after codeigniter-reactor commit r2307:c43c6dea56fb --- system/libraries/Email.php | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 6c21f114d..cd89f8f3d 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -722,7 +722,7 @@ class CI_Email { { if ( ! is_array($email)) { - $this->_set_error_message('email_must_be_array'); + $this->_set_error_message('lang:email_must_be_array'); return FALSE; } @@ -730,7 +730,7 @@ class CI_Email { { if ( ! $this->valid_email($val)) { - $this->_set_error_message('email_invalid_address', $val); + $this->_set_error_message('lang:email_invalid_address', $val); return FALSE; } } @@ -1131,7 +1131,7 @@ class CI_Email { if ( ! file_exists($filename)) { - $this->_set_error_message('email_attachment_missing', $filename); + $this->_set_error_message('lang:email_attachment_missing', $filename); return FALSE; } @@ -1146,7 +1146,7 @@ class CI_Email { if ( ! $fp = fopen($filename, FOPEN_READ)) { - $this->_set_error_message('email_attachment_unreadable', $filename); + $this->_set_error_message('lang:email_attachment_unreadable', $filename); return FALSE; } @@ -1353,7 +1353,7 @@ class CI_Email { ( ! isset($this->_bcc_array) AND ! isset($this->_headers['Bcc'])) AND ( ! isset($this->_headers['Cc']))) { - $this->_set_error_message('email_no_recipients'); + $this->_set_error_message('lang:email_no_recipients'); return FALSE; } @@ -1484,7 +1484,7 @@ class CI_Email { if ( ! $this->_send_with_mail()) { - $this->_set_error_message('email_send_failure_phpmail'); + $this->_set_error_message('lang:email_send_failure_phpmail'); return FALSE; } break; @@ -1492,7 +1492,7 @@ class CI_Email { if ( ! $this->_send_with_sendmail()) { - $this->_set_error_message('email_send_failure_sendmail'); + $this->_set_error_message('lang:email_send_failure_sendmail'); return FALSE; } break; @@ -1500,14 +1500,14 @@ class CI_Email { if ( ! $this->_send_with_smtp()) { - $this->_set_error_message('email_send_failure_smtp'); + $this->_set_error_message('lang:email_send_failure_smtp'); return FALSE; } break; } - $this->_set_error_message('email_sent', $this->_get_protocol()); + $this->_set_error_message('lang:email_sent', $this->_get_protocol()); return TRUE; } @@ -1578,8 +1578,8 @@ class CI_Email { if ($status != 0) { - $this->_set_error_message('email_exit_status', $status); - $this->_set_error_message('email_no_socket'); + $this->_set_error_message('lang:email_exit_status', $status); + $this->_set_error_message('lang:email_no_socket'); return FALSE; } @@ -1598,7 +1598,7 @@ class CI_Email { { if ($this->smtp_host == '') { - $this->_set_error_message('email_no_hostname'); + $this->_set_error_message('lang:email_no_hostname'); return FALSE; } @@ -1647,7 +1647,7 @@ class CI_Email { if (strncmp($reply, '250', 3) != 0) { - $this->_set_error_message('email_smtp_error', $reply); + $this->_set_error_message('lang:email_smtp_error', $reply); return FALSE; } @@ -1674,7 +1674,7 @@ class CI_Email { if ( ! is_resource($this->_smtp_connect)) { - $this->_set_error_message('email_smtp_error', $errno." ".$errstr); + $this->_set_error_message('lang:email_smtp_error', $errno." ".$errstr); return FALSE; } @@ -1737,7 +1737,7 @@ class CI_Email { if (substr($reply, 0, 3) != $resp) { - $this->_set_error_message('email_smtp_error', $reply); + $this->_set_error_message('lang:email_smtp_error', $reply); return FALSE; } @@ -1766,7 +1766,7 @@ class CI_Email { if ($this->smtp_user == "" AND $this->smtp_pass == "") { - $this->_set_error_message('email_no_smtp_unpw'); + $this->_set_error_message('lang:email_no_smtp_unpw'); return FALSE; } @@ -1776,7 +1776,7 @@ class CI_Email { if (strncmp($reply, '334', 3) != 0) { - $this->_set_error_message('email_failed_smtp_login', $reply); + $this->_set_error_message('lang:email_failed_smtp_login', $reply); return FALSE; } @@ -1786,7 +1786,7 @@ class CI_Email { if (strncmp($reply, '334', 3) != 0) { - $this->_set_error_message('email_smtp_auth_un', $reply); + $this->_set_error_message('lang:email_smtp_auth_un', $reply); return FALSE; } @@ -1796,7 +1796,7 @@ class CI_Email { if (strncmp($reply, '235', 3) != 0) { - $this->_set_error_message('email_smtp_auth_pw', $reply); + $this->_set_error_message('lang:email_smtp_auth_pw', $reply); return FALSE; } @@ -1815,7 +1815,7 @@ class CI_Email { { if ( ! fwrite($this->_smtp_connect, $data . $this->newline)) { - $this->_set_error_message('email_smtp_data_failure', $data); + $this->_set_error_message('lang:email_smtp_data_failure', $data); return FALSE; } else @@ -1942,7 +1942,7 @@ class CI_Email { $CI =& get_instance(); $CI->lang->load('email'); - if (FALSE === ($line = $CI->lang->line($msg))) + if (substr($msg, 0, 5) != 'lang:' || FALSE === ($line = $CI->lang->line(substr($msg, 5)))) { $this->_debug_msg[] = str_replace('%s', $val, $msg)."
"; } @@ -2059,4 +2059,4 @@ class CI_Email { // END CI_Email class /* End of file Email.php */ -/* Location: ./system/libraries/Email.php */ \ No newline at end of file +/* Location: ./system/libraries/Email.php */ -- cgit v1.2.3-24-g4f1b From 02404a1f59e4f3ae8231d87d8be5b23488ea86d2 Mon Sep 17 00:00:00 2001 From: patwork Date: Fri, 8 Apr 2011 15:45:46 +0200 Subject: Fix: codeigniter-reactor/127 Form_validation rule error logging --- system/libraries/Form_validation.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index cfc02eda9..6f79a554a 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -628,6 +628,10 @@ class CI_Form_validation { $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; } } + else + { + log_message('debug', "Unable to find validation rule: ".$rule); + } continue; } @@ -1357,4 +1361,4 @@ class CI_Form_validation { // END Form Validation Class /* End of file Form_validation.php */ -/* Location: ./system/libraries/Form_validation.php */ \ No newline at end of file +/* Location: ./system/libraries/Form_validation.php */ -- cgit v1.2.3-24-g4f1b From bffb7769c6f31b7a47355d4eb66f5ac1d85c2a2e Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Mon, 18 Apr 2011 00:03:31 -0400 Subject: Changed path in footer comment of cache dummy. --- system/libraries/Cache/drivers/Cache_dummy.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Cache/drivers/Cache_dummy.php b/system/libraries/Cache/drivers/Cache_dummy.php index de47acb43..f96a68e27 100644 --- a/system/libraries/Cache/drivers/Cache_dummy.php +++ b/system/libraries/Cache/drivers/Cache_dummy.php @@ -10,29 +10,29 @@ * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 2.0 - * @filesource + * @filesource */ // ------------------------------------------------------------------------ /** - * CodeIgniter Dummy Caching Class + * CodeIgniter Dummy Caching Class * * @package CodeIgniter * @subpackage Libraries * @category Core * @author ExpressionEngine Dev Team - * @link + * @link */ class CI_Cache_dummy extends CI_Driver { /** - * Get + * Get * * Since this is the dummy class, it's always going to return FALSE. * - * @param string + * @param string * @return Boolean FALSE */ public function get($id) @@ -40,8 +40,8 @@ class CI_Cache_dummy extends CI_Driver { return FALSE; } - // ------------------------------------------------------------------------ - + // ------------------------------------------------------------------------ + /** * Cache Save * @@ -55,7 +55,7 @@ class CI_Cache_dummy extends CI_Driver { { return TRUE; } - + // ------------------------------------------------------------------------ /** @@ -112,7 +112,7 @@ class CI_Cache_dummy extends CI_Driver { /** * Is this caching driver supported on the system? * Of course this one is. - * + * * @return TRUE; */ public function is_supported() @@ -121,9 +121,9 @@ class CI_Cache_dummy extends CI_Driver { } // ------------------------------------------------------------------------ - + } // End Class -/* End of file Cache_apc.php */ -/* Location: ./system/libraries/Cache/drivers/Cache_apc.php */ \ No newline at end of file +/* End of file Cache_dummy.php */ +/* Location: ./system/libraries/Cache/drivers/Cache_dummy.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 62df13125bd9ab22ff0c7f2565a42a6de13ed7e4 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Mon, 18 Apr 2011 11:18:02 -0500 Subject: Added Session Class userdata to the output profiler. Additionally, added a show/hide toggle on HTTP Headers, Session Data and Config Variables. --- system/libraries/Profiler.php | 45 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 8a1f18ced..d1828b984 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -32,7 +32,7 @@ */ class CI_Profiler { - var $CI; + private $CI; protected $_available_sections = array( 'benchmarks', @@ -43,6 +43,7 @@ class CI_Profiler { 'controller_info', 'queries', 'http_headers', + 'session_data', 'config' ); @@ -410,10 +411,10 @@ class CI_Profiler { $output = "\n\n"; $output .= '
'; $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_headers').'  '; + $output .= '  '.$this->CI->lang->line('profiler_headers').'  ('.$this->CI->lang->line('profiler_section_show').')'; $output .= "\n"; - $output .= "\n\n\n"; + $output .= "\n\n
\n"; foreach (array('HTTP_ACCEPT', 'HTTP_USER_AGENT', 'HTTP_CONNECTION', 'SERVER_PORT', 'SERVER_NAME', 'REMOTE_ADDR', 'SERVER_SOFTWARE', 'HTTP_ACCEPT_LANGUAGE', 'SCRIPT_NAME', 'REQUEST_METHOD',' HTTP_HOST', 'REMOTE_HOST', 'CONTENT_TYPE', 'SERVER_PROTOCOL', 'QUERY_STRING', 'HTTP_ACCEPT_ENCODING', 'HTTP_X_FORWARDED_FOR') as $header) { @@ -441,10 +442,10 @@ class CI_Profiler { $output = "\n\n"; $output .= '
'; $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_config').'  '; + $output .= '  '.$this->CI->lang->line('profiler_config').'  ('.$this->CI->lang->line('profiler_section_show').')'; $output .= "\n"; - $output .= "\n\n
\n"; + $output .= "\n\n
\n"; foreach ($this->CI->config->config as $config=>$val) { @@ -464,6 +465,39 @@ class CI_Profiler { // -------------------------------------------------------------------- + /** + * Compile session userdata + * + * @return string + */ + private function _compile_session_data() + { + if ( ! isset($this->CI->session)) + { + return; + } + + $output = '
'; + $output .= '  '.$this->CI->lang->line('profiler_session_data').'  ('.$this->CI->lang->line('profiler_section_show').')'; + $output .= "
"; + + foreach ($this->CI->session->all_userdata() as $key => $val) + { + if (is_array($val)) + { + $val = print_r($val, TRUE); + } + + $output .= "\n"; + } + + $output .= ''; + $output .= "
"; + return $output; + } + + // -------------------------------------------------------------------- + /** * Run the Profiler * @@ -493,7 +527,6 @@ class CI_Profiler { return $output; } - } // END CI_Profiler class -- cgit v1.2.3-24-g4f1b From 3403366d0f457c1dd449076b4177d1aff5cb176c Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Mon, 18 Apr 2011 11:18:09 -0500 Subject: changeset: 2202:06a75a1bd622 tag: tip user: Greg Aker date: Mon Apr 18 11:10:37 2011 -0500 summary: Tweak to session class all_userdata() to just return the userdata array. Also documented previously undocumented all_userdata() method. --- system/libraries/Session.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 182294059..32317c2e6 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -435,11 +435,11 @@ class CI_Session { * Fetch all session data * * @access public - * @return mixed + * @return array */ function all_userdata() { - return ( ! isset($this->userdata)) ? FALSE : $this->userdata; + return $this->userdata; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From e6e6e64ab078205153513af24dd4163157efb148 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Mon, 18 Apr 2011 15:54:13 -0500 Subject: changeset: 2204:37301a84c8be tag: tip user: Greg Aker date: Mon Apr 18 15:51:28 2011 -0500 summary: Adding toggle show/hide on database queries in the output profiler. Added a profiler config item to set a threshold of when to hide the queries by default. Additionally, fixed a bug I created earlier today by marking the $CI class var in CI_Profiler as private. --- system/libraries/Profiler.php | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index d1828b984..b73ddaf0d 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -32,8 +32,6 @@ */ class CI_Profiler { - private $CI; - protected $_available_sections = array( 'benchmarks', 'get', @@ -46,12 +44,24 @@ class CI_Profiler { 'session_data', 'config' ); + + protected $_query_toggle_count = 25; + + protected $CI; + // -------------------------------------------------------------------- + public function __construct($config = array()) { $this->CI =& get_instance(); $this->CI->load->language('profiler'); + if (isset($config['query_toggle_count'])) + { + $this->_query_toggle_count = (int) $config['query_toggle_count']; + unset($config['query_toggle_count']); + } + // default all sections to display foreach ($this->_available_sections as $section) { @@ -163,7 +173,7 @@ class CI_Profiler { $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; $output .= "\n"; - $output .= "\n\n\n"; + $output .= "\n\n
\n"; $output .="\n"; $output .= "
".$this->CI->lang->line('profiler_no_db')."
\n"; $output .= "
"; @@ -178,14 +188,27 @@ 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"; - + + $count = 0; + foreach ($dbs as $db) { + $count++; + + $hide_queries = (count($db->queries) > $this->_query_toggle_count) ? ' display:none' : ''; + + $show_hide_js = '('.$this->CI->lang->line('profiler_section_hide').')'; + + if ($hide_queries != '') + { + $show_hide_js = '('.$this->CI->lang->line('profiler_section_show').')'; + } + $output .= '
'; $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_database').':  '.$db->database.'   '.$this->CI->lang->line('profiler_queries').': '.count($db->queries).'   '; + $output .= '  '.$this->CI->lang->line('profiler_database').':  '.$db->database.'   '.$this->CI->lang->line('profiler_queries').': '.count($db->queries).'  '.$show_hide_js.''; $output .= "\n"; - $output .= "\n\n\n"; + $output .= "\n\n
\n"; if (count($db->queries) == 0) { -- cgit v1.2.3-24-g4f1b From 3a746655e92ec59ee7e731c3535673a9aedc5d3e Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 19 Apr 2011 10:59:47 -0500 Subject: Removing internal references to the EXT constant. Additionally, marked the constant as deprecated. Use ".php" instead. Also adding upgrade notes from 2.0.2 to 2.0.3. --- system/libraries/Calendar.php | 2 +- system/libraries/Driver.php | 2 +- system/libraries/Encrypt.php | 2 +- system/libraries/Log.php | 2 +- system/libraries/Upload.php | 8 ++++---- system/libraries/User_agent.php | 8 ++++---- 6 files changed, 12 insertions(+), 12 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 72d228e73..df0fd6eeb 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -47,7 +47,7 @@ class CI_Calendar { { $this->CI =& get_instance(); - if ( ! in_array('calendar_lang'.EXT, $this->CI->lang->is_loaded, TRUE)) + if ( ! in_array('calendar_lang.php', $this->CI->lang->is_loaded, TRUE)) { $this->CI->lang->load('calendar'); } diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index b942f539f..d1925c0ec 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -59,7 +59,7 @@ class CI_Driver_Library { // loves me some nesting! foreach (array(ucfirst($driver_name), $driver_name) as $class) { - $filepath = $path.'libraries/'.$lib_name.'/drivers/'.$class.EXT; + $filepath = $path.'libraries/'.$lib_name.'/drivers/'.$class.'.php'; if (file_exists($filepath)) { diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index e5f65878a..b30a8cf0b 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -524,7 +524,7 @@ class CI_Encrypt { { if ( ! function_exists('mhash')) { - require_once(BASEPATH.'libraries/Sha1'.EXT); + require_once(BASEPATH.'libraries/Sha1.php'); $SH = new CI_SHA; return $SH->generate($str); } diff --git a/system/libraries/Log.php b/system/libraries/Log.php index fb2c5a49b..9f1db76ba 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -83,7 +83,7 @@ class CI_Log { return FALSE; } - $filepath = $this->_log_path.'log-'.date('Y-m-d').EXT; + $filepath = $this->_log_path.'log-'.date('Y-m-d').'.php'; $message = ''; if ( ! file_exists($filepath)) diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index e80049fa4..3177424c4 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -945,13 +945,13 @@ class CI_Upload { if (count($this->mimes) == 0) { - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT)) + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) { - include(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT); + include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'); } - elseif (is_file(APPPATH.'config/mimes'.EXT)) + elseif (is_file(APPPATH.'config/mimes.php')) { - include(APPPATH.'config//mimes'.EXT); + include(APPPATH.'config//mimes.php'); } else { diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 04cda7312..016102a2a 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -84,13 +84,13 @@ class CI_User_agent { */ private function _load_agent_file() { - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents'.EXT)) + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php')) { - include(APPPATH.'config/'.ENVIRONMENT.'/user_agents'.EXT); + include(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php'); } - elseif (is_file(APPPATH.'config/user_agents'.EXT)) + elseif (is_file(APPPATH.'config/user_agents.php')) { - include(APPPATH.'config/user_agents'.EXT); + include(APPPATH.'config/user_agents.php'); } else { -- cgit v1.2.3-24-g4f1b From 50671cf8d67c805692fec49eda33d21227a21ec2 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 20 Apr 2011 11:36:45 -0500 Subject: Altered Session to use a longer match against the user_agent string. See upgrade notes if using database sessions.sess_match_useragent == TRUE AND trim($session['user_agent']) != trim(substr($this->CI->input->user_agent(), 0, 50))) + if ($this->sess_match_useragent == TRUE AND trim($session['user_agent']) != trim(substr($this->CI->input->user_agent(), 0, 120))) { $this->sess_destroy(); return FALSE; @@ -316,7 +316,7 @@ class CI_Session { $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), + 'user_agent' => substr($this->CI->input->user_agent(), 0, 120), 'last_activity' => $this->now ); -- cgit v1.2.3-24-g4f1b From c0b133c02e057b6506726b794ba4582bf18ed663 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 22 Apr 2011 19:58:43 +0900 Subject: default value of $total_rows in Pagination class should be number. And fix User Guide Pagination Class's Example which uses string to number variable. --- system/libraries/Pagination.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 1113f862f..cc62e660b 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -30,7 +30,7 @@ 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 $total_rows = 0; // 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 -- cgit v1.2.3-24-g4f1b From c24f49b54f47229aa89781c0cc06c3d9fa947937 Mon Sep 17 00:00:00 2001 From: Razican Date: Mon, 25 Apr 2011 13:43:57 +0200 Subject: Fixed #60. --- system/libraries/Profiler.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index b73ddaf0d..082a5ee1d 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -44,13 +44,13 @@ class CI_Profiler { 'session_data', 'config' ); - + protected $_query_toggle_count = 25; - - protected $CI; + + protected $CI; // -------------------------------------------------------------------- - + public function __construct($config = array()) { $this->CI =& get_instance(); @@ -188,22 +188,22 @@ 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"; - + $count = 0; - + foreach ($dbs as $db) { $count++; - + $hide_queries = (count($db->queries) > $this->_query_toggle_count) ? ' display:none' : ''; - + $show_hide_js = '('.$this->CI->lang->line('profiler_section_hide').')'; - + if ($hide_queries != '') { $show_hide_js = '('.$this->CI->lang->line('profiler_section_show').')'; } - + $output .= '
'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_database').':  '.$db->database.'   '.$this->CI->lang->line('profiler_queries').': '.count($db->queries).'  '.$show_hide_js.''; @@ -412,7 +412,7 @@ class CI_Profiler { } else { - $output .= "
".$this->CI->lang->line('profiler_no_memory_usage')."
"; + $output .= "
".$this->CI->lang->line('profiler_no_memory')."
"; } $output .= "
"; -- cgit v1.2.3-24-g4f1b From 114ab0988e20ac6be39ad363ff897a1a3b85e565 Mon Sep 17 00:00:00 2001 From: Razican Date: Mon, 25 Apr 2011 17:26:45 +0200 Subject: Fixed double-space typo. --- system/libraries/Cache/Cache.php | 30 ++-- system/libraries/Cache/drivers/Cache_apc.php | 24 +-- system/libraries/Cache/drivers/Cache_file.php | 40 ++--- system/libraries/Calendar.php | 18 +-- system/libraries/Cart.php | 22 +-- system/libraries/Driver.php | 2 +- system/libraries/Email.php | 46 +++--- system/libraries/Encrypt.php | 2 +- system/libraries/Form_validation.php | 32 ++-- system/libraries/Ftp.php | 8 +- system/libraries/Image_lib.php | 118 +++++++------- system/libraries/Javascript.php | 12 +- system/libraries/Log.php | 8 +- system/libraries/Pagination.php | 18 +-- system/libraries/Parser.php | 18 +-- system/libraries/Profiler.php | 26 +-- system/libraries/Session.php | 30 ++-- system/libraries/Sha1.php | 8 +- system/libraries/Table.php | 12 +- system/libraries/Trackback.php | 16 +- system/libraries/Typography.php | 36 ++--- system/libraries/Unit_test.php | 2 +- system/libraries/Upload.php | 28 ++-- system/libraries/User_agent.php | 2 +- system/libraries/Xmlrpc.php | 90 +++++------ system/libraries/Xmlrpcs.php | 44 +++--- system/libraries/Zip.php | 12 +- system/libraries/javascript/Jquery.php | 218 +++++++++++++------------- 28 files changed, 461 insertions(+), 461 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 61e7aa761..938c80857 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -10,22 +10,22 @@ * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 2.0 - * @filesource + * @filesource */ // ------------------------------------------------------------------------ /** - * CodeIgniter Caching Class + * CodeIgniter Caching Class * * @package CodeIgniter * @subpackage Libraries * @category Core * @author ExpressionEngine Dev Team - * @link + * @link */ class CI_Cache extends CI_Driver_Library { - + protected $valid_drivers = array( 'cache_apc', 'cache_file', 'cache_memcached', 'cache_dummy' ); @@ -33,7 +33,7 @@ class CI_Cache extends CI_Driver_Library { protected $_cache_path = NULL; // Path of cache files (if file-based cache) protected $_adapter = 'dummy'; protected $_backup_driver; - + // ------------------------------------------------------------------------ /** @@ -52,16 +52,16 @@ class CI_Cache extends CI_Driver_Library { // ------------------------------------------------------------------------ /** - * Get + * Get * - * Look for a value in the cache. If it exists, return the data + * Look for a value in the cache. If it exists, return the data * if not, return FALSE * - * @param string + * @param string * @return mixed value that is stored/FALSE on failure */ public function get($id) - { + { return $this->{$this->_adapter}->get($id); } @@ -112,7 +112,7 @@ class CI_Cache extends CI_Driver_Library { * Cache Info * * @param string user/filehits - * @return mixed array on success, false on failure + * @return mixed array on success, false on failure */ public function cache_info($type = 'user') { @@ -120,7 +120,7 @@ class CI_Cache extends CI_Driver_Library { } // ------------------------------------------------------------------------ - + /** * Get Cache Metadata * @@ -131,7 +131,7 @@ class CI_Cache extends CI_Driver_Library { { return $this->{$this->_adapter}->get_metadata($id); } - + // ------------------------------------------------------------------------ /** @@ -139,11 +139,11 @@ class CI_Cache extends CI_Driver_Library { * * Initialize class properties based on the configuration array. * - * @param array + * @param array * @return void */ private function _initialize($config) - { + { $default_config = array( 'adapter', 'memcached' @@ -207,7 +207,7 @@ class CI_Cache extends CI_Driver_Library { return $obj; } - + // ------------------------------------------------------------------------ } // End Class diff --git a/system/libraries/Cache/drivers/Cache_apc.php b/system/libraries/Cache/drivers/Cache_apc.php index de75719c4..ea129eded 100644 --- a/system/libraries/Cache/drivers/Cache_apc.php +++ b/system/libraries/Cache/drivers/Cache_apc.php @@ -10,30 +10,30 @@ * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 2.0 - * @filesource + * @filesource */ // ------------------------------------------------------------------------ /** - * CodeIgniter APC Caching Class + * CodeIgniter APC Caching Class * * @package CodeIgniter * @subpackage Libraries * @category Core * @author ExpressionEngine Dev Team - * @link + * @link */ class CI_Cache_apc extends CI_Driver { /** - * Get + * Get * - * Look for a value in the cache. If it exists, return the data + * Look for a value in the cache. If it exists, return the data * if not, return FALSE * - * @param string + * @param string * @return mixed value that is stored/FALSE on failure */ public function get($id) @@ -43,8 +43,8 @@ class CI_Cache_apc extends CI_Driver { return (is_array($data)) ? $data[0] : FALSE; } - // ------------------------------------------------------------------------ - + // ------------------------------------------------------------------------ + /** * Cache Save * @@ -58,7 +58,7 @@ class CI_Cache_apc extends CI_Driver { { return apc_store($id, array($data, time(), $ttl), $ttl); } - + // ------------------------------------------------------------------------ /** @@ -90,7 +90,7 @@ class CI_Cache_apc extends CI_Driver { * Cache Info * * @param string user/filehits - * @return mixed array on success, false on failure + * @return mixed array on success, false on failure */ public function cache_info($type = NULL) { @@ -137,13 +137,13 @@ class CI_Cache_apc extends CI_Driver { log_message('error', 'The APC PHP extension must be loaded to use APC Cache.'); return FALSE; } - + return TRUE; } // ------------------------------------------------------------------------ - + } // End Class diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php index 13e2d1af6..39dcd15c2 100644 --- a/system/libraries/Cache/drivers/Cache_file.php +++ b/system/libraries/Cache/drivers/Cache_file.php @@ -10,19 +10,19 @@ * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 2.0 - * @filesource + * @filesource */ // ------------------------------------------------------------------------ /** - * CodeIgniter Memcached Caching Class + * CodeIgniter Memcached Caching Class * * @package CodeIgniter * @subpackage Libraries * @category Core * @author ExpressionEngine Dev Team - * @link + * @link */ class CI_Cache_file extends CI_Driver { @@ -36,9 +36,9 @@ class CI_Cache_file extends CI_Driver { { $CI =& get_instance(); $CI->load->helper('file'); - + $path = $CI->config->item('cache_path'); - + $this->_cache_path = ($path == '') ? APPPATH.'cache/' : $path; } @@ -56,16 +56,16 @@ class CI_Cache_file extends CI_Driver { { return FALSE; } - + $data = read_file($this->_cache_path.$id); $data = unserialize($data); - - if (time() > $data['time'] + $data['ttl']) + + if (time() > $data['time'] + $data['ttl']) { unlink($this->_cache_path.$id); return FALSE; } - + return $data['data']; } @@ -76,22 +76,22 @@ class CI_Cache_file extends CI_Driver { * * @param string unique key * @param mixed data to store - * @param int length of time (in seconds) the cache is valid + * @param int length of time (in seconds) the cache is valid * - Default is 60 seconds * @return boolean true on success/false on failure */ public function save($id, $data, $ttl = 60) - { + { $contents = array( 'time' => time(), - 'ttl' => $ttl, + 'ttl' => $ttl, 'data' => $data ); - + if (write_file($this->_cache_path.$id, serialize($contents))) { @chmod($this->_cache_path.$id, 0777); - return TRUE; + return TRUE; } return FALSE; @@ -116,7 +116,7 @@ class CI_Cache_file extends CI_Driver { * Clean the Cache * * @return boolean false on failure/true on success - */ + */ public function clean() { return delete_files($this->_cache_path); @@ -151,10 +151,10 @@ class CI_Cache_file extends CI_Driver { { return FALSE; } - - $data = read_file($this->_cache_path.$id); + + $data = read_file($this->_cache_path.$id); $data = unserialize($data); - + if (is_array($data)) { $data = $data['data']; @@ -170,7 +170,7 @@ class CI_Cache_file extends CI_Driver { 'mtime' => $mtime ); } - + return FALSE; } @@ -180,7 +180,7 @@ class CI_Cache_file extends CI_Driver { * Is supported * * In the file driver, check to see that the cache directory is indeed writable - * + * * @return boolean */ public function is_supported() diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index df0fd6eeb..7dcbaab47 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -1,4 +1,4 @@ -local_time); + $year = date("Y", $this->local_time); if ($month == '') $month = date("m", $this->local_time); @@ -128,7 +128,7 @@ class CI_Calendar { // Set the starting day number $local_date = mktime(12, 0, 0, $month, 1, $year); $date = getdate($local_date); - $day = $start_day + 1 - $date["wday"]; + $day = $start_day + 1 - $date["wday"]; while ($day > 1) { @@ -157,8 +157,8 @@ class CI_Calendar { // "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); + // 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']); @@ -233,7 +233,7 @@ class CI_Calendar { $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++; } @@ -287,7 +287,7 @@ class CI_Calendar { * Get Day Names * * Returns an array of day names (Sunday, Monday, etc.) based - * on the type. Options: long, short, abrev + * on the type. Options: long, short, abrev * * @access public * @param string @@ -404,7 +404,7 @@ class CI_Calendar { */ function default_template() { - return array ( + return array ( 'table_open' => '
', 'heading_row_start' => '', 'heading_previous_cell' => '', @@ -451,7 +451,7 @@ class CI_Calendar { $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) + 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)) { diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 7f65b48b9..fbccfb3d9 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -1,4 +1,4 @@ -CI =& get_instance(); - // Are any config settings being passed manually? If so, set them + // Are any config settings being passed manually? If so, set them $config = array(); if (count($params) > 0) { @@ -148,7 +148,7 @@ class CI_Cart { // -------------------------------------------------------------------- - // Does the $items array contain an id, quantity, price, and name? These are required + // 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'])) { log_message('error', 'The cart array must contain a product ID, quantity, price, and name.'); @@ -157,7 +157,7 @@ class CI_Cart { // -------------------------------------------------------------------- - // Prep the quantity. It can only be a number. Duh... + // Prep the quantity. It can only be a number. Duh... $items['qty'] = trim(preg_replace('/([^0-9])/i', '', $items['qty'])); // Trim any leading zeros $items['qty'] = trim(preg_replace('/(^[0]+)/i', '', $items['qty'])); @@ -175,7 +175,7 @@ class CI_Cart { // Note: These can be user-specified by setting the $this->product_id_rules variable. if ( ! preg_match("/^[".$this->product_id_rules."]+$/i", $items['id'])) { - log_message('error', 'Invalid product ID. The product ID can only contain alpha-numeric characters, dashes, and underscores'); + log_message('error', 'Invalid product ID. The product ID can only contain alpha-numeric characters, dashes, and underscores'); return FALSE; } @@ -191,7 +191,7 @@ class CI_Cart { // -------------------------------------------------------------------- - // Prep the price. Remove anything that isn't a number or decimal point. + // Prep the price. Remove anything that isn't a number or decimal point. $items['price'] = trim(preg_replace('/([^0-9\.])/i', '', $items['price'])); // Trim any leading zeros $items['price'] = trim(preg_replace('/(^[0]+)/i', '', $items['price'])); @@ -210,7 +210,7 @@ class CI_Cart { // 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 + // 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. @@ -271,7 +271,7 @@ class CI_Cart { } // You can either update a single product using a one-dimensional array, - // or multiple products using a multi-dimensional one. The way we + // 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 $save_cart = FALSE; @@ -344,7 +344,7 @@ class CI_Cart { return FALSE; } - // Is the quantity zero? If so we will remove the item from the cart. + // Is the quantity zero? If so we will remove the item from the cart. // If the quantity is greater than zero we are updating if ($items['qty'] == 0) { @@ -392,7 +392,7 @@ class CI_Cart { $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 + // 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'); diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index d1925c0ec..b90b5aba6 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -1,4 +1,4 @@ -_attach_name[] = $filename; $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename)))); - $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters + $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters return $this; } @@ -600,7 +600,7 @@ class CI_Email { $from = str_replace(">", "", $from); $from = str_replace("<", "", $from); - return "<".uniqid('').strstr($from, '@').">"; + return "<".uniqid('').strstr($from, '@').">"; } // -------------------------------------------------------------------- @@ -660,15 +660,15 @@ class CI_Email { */ private function _get_content_type() { - if ($this->mailtype == 'html' && count($this->_attach_name) == 0) + if ($this->mailtype == 'html' && count($this->_attach_name) == 0) { return 'html'; } - elseif ($this->mailtype == 'html' && count($this->_attach_name) > 0) + elseif ($this->mailtype == 'html' && count($this->_attach_name) > 0) { return 'html-attach'; } - elseif ($this->mailtype == 'text' && count($this->_attach_name) > 0) + elseif ($this->mailtype == 'text' && count($this->_attach_name) > 0) { return 'plain-attach'; } @@ -881,7 +881,7 @@ class CI_Email { // Use PHP's native public function to do the initial wordwrap. // We set the cut flag to FALSE so that any individual words that are - // too long get left alone. In the next step we'll deal with them. + // 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 @@ -999,7 +999,7 @@ class CI_Email { */ private function _build_message() { - if ($this->wordwrap === TRUE AND $this->mailtype != 'html') + if ($this->wordwrap === TRUE AND $this->mailtype != 'html') { $this->_body = $this->word_wrap($this->_body); } @@ -1135,7 +1135,7 @@ class CI_Email { return FALSE; } - $h = "--".$this->_atc_boundary.$this->newline; + $h = "--".$this->_atc_boundary.$this->newline; $h .= "Content-type: ".$ctype."; "; $h .= "name=\"".$basename."\"".$this->newline; $h .= "Content-Disposition: ".$this->_attach_disp[$i].";".$this->newline; @@ -1237,7 +1237,7 @@ class CI_Email { // encode = signs if ($ascii == '61') { - $char = $escape.strtoupper(sprintf('%02s', dechex($ascii))); // =3D + $char = $escape.strtoupper(sprintf('%02s', dechex($ascii))); // =3D } // If we're at the character limit, add the line to the output, @@ -1267,7 +1267,7 @@ class CI_Email { /** * Prep Q Encoding * - * Performs "Q Encoding" on a string for use in email headers. It's related + * Performs "Q Encoding" on a string for use in email headers. It's related * but not identical to quoted-printable, so it has its own method * * @access public @@ -1349,7 +1349,7 @@ class CI_Email { $this->reply_to($this->_headers['From']); } - if (( ! isset($this->_recipients) AND ! isset($this->_headers['To'])) AND + if (( ! isset($this->_recipients) AND ! isset($this->_headers['To'])) AND ( ! isset($this->_bcc_array) AND ! isset($this->_headers['Bcc'])) AND ( ! isset($this->_headers['Cc']))) { @@ -1359,7 +1359,7 @@ class CI_Email { $this->_build_headers(); - if ($this->bcc_batch_mode AND count($this->_bcc_array) > 0) + if ($this->bcc_batch_mode AND count($this->_bcc_array) > 0) { if (count($this->_bcc_array) > $this->bcc_batch_size) return $this->batch_bcc_send(); @@ -1380,7 +1380,7 @@ class CI_Email { // -------------------------------------------------------------------- /** - * Batch Bcc Send. Sends groups of BCCs in batches + * Batch Bcc Send. Sends groups of BCCs in batches * * @access public * @return bool @@ -1752,7 +1752,7 @@ class CI_Email { // -------------------------------------------------------------------- /** - * SMTP Authenticate + * SMTP Authenticate * * @access private * @return bool @@ -1764,7 +1764,7 @@ class CI_Email { return TRUE; } - if ($this->smtp_user == "" AND $this->smtp_pass == "") + if ($this->smtp_user == "" AND $this->smtp_pass == "") { $this->_set_error_message('lang:email_no_smtp_unpw'); return FALSE; diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index b30a8cf0b..2f7db6623 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -1,4 +1,4 @@ -_field_data) == 0) { - // No validation rules? We're done... + // No validation rules? We're done... if (count($this->_config_rules) == 0) { return FALSE; @@ -648,7 +648,7 @@ class CI_Form_validation { } } - // Did the rule test negatively? If so, grab the error. + // Did the rule test negatively? If so, grab the error. if ($result === FALSE) { if ( ! isset($this->_error_messages[$rule])) @@ -664,7 +664,7 @@ class CI_Form_validation { } // Is the parameter we are inserting into the error message the name - // of another field? If so we need to grab its "field label" + // 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']); @@ -704,7 +704,7 @@ class CI_Form_validation { // Grab the variable $line = substr($fieldname, 5); - // Were we able to translate the field name? If not we use $line + // Were we able to translate the field name? If not we use $line if (FALSE === ($fieldname = $this->CI->lang->line($line))) { return $line; @@ -735,7 +735,7 @@ class CI_Form_validation { } // If the data is an array output them one at a time. - // E.g: form_input('name[]', set_value('name[]'); + // E.g: form_input('name[]', set_value('name[]'); if (is_array($this->_field_data[$field]['postdata'])) { return array_shift($this->_field_data[$field]['postdata']); @@ -914,7 +914,7 @@ class CI_Form_validation { return FALSE; } - return TRUE; + return TRUE; } // -------------------------------------------------------------------- @@ -1207,7 +1207,7 @@ class CI_Form_validation { // -------------------------------------------------------------------- /** - * Is a Natural number (0,1,2,3, etc.) + * Is a Natural number (0,1,2,3, etc.) * * @access public * @param string @@ -1221,7 +1221,7 @@ class CI_Form_validation { // -------------------------------------------------------------------- /** - * Is a Natural number, but not a zero (1,2,3, etc.) + * Is a Natural number, but not a zero (1,2,3, etc.) * * @access public * @param string @@ -1354,7 +1354,7 @@ class CI_Form_validation { */ function encode_php_tags($str) { - return str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); + return str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); } } diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index d7a8b3b02..859cc9c30 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -1,4 +1,4 @@ -list_files($filepath); @@ -513,7 +513,7 @@ class CI_FTP { * Read a directory and recreate it remotely * * This function recursively reads a folder and everything it contains (including - * sub-folders) and creates a mirror via FTP based on it. Whatever the directory structure + * sub-folders) and creates a mirror via FTP based on it. Whatever the directory structure * of the original file path will be recreated on the server. * * @access public diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 8902f524d..099a238dd 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1,4 +1,4 @@ -source_image == '') { $this->set_error('imglib_source_image_required'); - return FALSE; + return FALSE; } /* * Is getimagesize() Available? * * We use it to determine the image properties (width/height). - * Note: We need to figure out how to determine image + * Note: We need to figure out how to determine image * properties using ImageMagick and NetPBM * */ @@ -189,7 +189,7 @@ class CI_Image_lib { // Set the Image Properties if ( ! $this->get_image_properties($this->source_folder.$this->source_image)) { - return FALSE; + return FALSE; } /* @@ -197,7 +197,7 @@ class CI_Image_lib { * * If the user has set a "new_image" name it means * we are making a copy of the source image. If not - * it means we are altering the original. We'll + * it means we are altering the original. We'll * set the destination filename and path accordingly. * */ @@ -267,7 +267,7 @@ class CI_Image_lib { * * When creating thumbs or copies, the target width/height * might not be in correct proportion with the source - * image's width/height. We'll recalculate it here. + * image's width/height. We'll recalculate it here. * */ if ($this->maintain_ratio === TRUE && ($this->width != '' AND $this->height != '')) @@ -399,7 +399,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 @@ -469,8 +469,8 @@ class CI_Image_lib { // Let's set up our values based on the action if ($action == 'crop') { - // Reassign the source width/height if cropping - $this->orig_width = $this->width; + // Reassign the source width/height if cropping + $this->orig_width = $this->width; $this->orig_height = $this->height; // GD 2.0 has a cropping bug so we'll test for it @@ -487,19 +487,19 @@ class CI_Image_lib { $this->y_axis = 0; } - // Create the image handle + // Create the image handle if ( ! ($src_img = $this->image_create_gd())) { 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. + // 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') AND $v2_override == FALSE) if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor')) { $create = 'imagecreatetruecolor'; @@ -521,7 +521,7 @@ class CI_Image_lib { $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 + // Show the image if ($this->dynamic_output == TRUE) { $this->image_display_gd($dst_img); @@ -535,7 +535,7 @@ class CI_Image_lib { } } - // Kill the file handles + // Kill the file handles imagedestroy($dst_img); imagedestroy($src_img); @@ -558,7 +558,7 @@ class CI_Image_lib { */ function image_process_imagemagick($action = 'resize') { - // Do we have a vaild library path? + // Do we have a vaild library path? if ($this->library_path == '') { $this->set_error('imglib_libpath_invalid'); @@ -593,7 +593,7 @@ class CI_Image_lib { $cmd .= " ".$angle." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; } - else // Resize + else // Resize { $cmd .= " -resize ".$this->width."x".$this->height." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; } @@ -634,7 +634,7 @@ class CI_Image_lib { return FALSE; } - // Build the resizing command + // Build the resizing command switch ($this->image_type) { case 1 : @@ -684,7 +684,7 @@ class CI_Image_lib { @exec($cmd, $output, $retval); - // Did it work? + // Did it work? if ($retval > 0) { $this->set_error('imglib_image_process_failed'); @@ -711,7 +711,7 @@ class CI_Image_lib { */ function image_rotate_gd() { - // Create the image handle + // Create the image handle if ( ! ($src_img = $this->image_create_gd())) { return FALSE; @@ -724,10 +724,10 @@ class CI_Image_lib { $white = imagecolorallocate($src_img, 255, 255, 255); - // Rotate it! + // Rotate it! $dst_img = imagerotate($src_img, $this->rotation_angle, $white); - // Save the Image + // Save the Image if ($this->dynamic_output == TRUE) { $this->image_display_gd($dst_img); @@ -741,7 +741,7 @@ class CI_Image_lib { } } - // Kill the file handles + // Kill the file handles imagedestroy($dst_img); imagedestroy($src_img); @@ -769,14 +769,14 @@ class CI_Image_lib { return FALSE; } - $width = $this->orig_width; + $width = $this->orig_width; $height = $this->orig_height; if ($this->rotation_angle == 'hor') { for ($i = 0; $i < $height; $i++) { - $left = 0; + $left = 0; $right = $width-1; while ($left < $right) @@ -813,7 +813,7 @@ class CI_Image_lib { } } - // Show the image + // Show the image if ($this->dynamic_output == TRUE) { $this->image_display_gd($src_img); @@ -827,7 +827,7 @@ class CI_Image_lib { } } - // Kill the file handles + // Kill the file handles imagedestroy($src_img); // Set the file to 777 @@ -876,24 +876,24 @@ class CI_Image_lib { return FALSE; } - // Fetch source image properties + // Fetch source image properties $this->get_image_properties(); - // Fetch watermark image properties + // Fetch watermark image properties $props = $this->get_image_properties($this->wm_overlay_path, TRUE); $wm_img_type = $props['image_type']; $wm_width = $props['width']; $wm_height = $props['height']; - // Create two image resources - $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type); + // Create two image resources + $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type); $src_img = $this->image_create_gd($this->full_src_path); // Reverse the offset if necessary // When the image is positioned at the bottom // we don't want the vertical offset to push it - // further down. We want the reverse, so we'll - // invert the offset. Same with the horizontal + // further down. We want the reverse, so we'll + // invert the offset. Same with the horizontal // offset when the image is at the right $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); @@ -905,11 +905,11 @@ class CI_Image_lib { if ($this->wm_hor_alignment == 'R') $this->wm_hor_offset = $this->wm_hor_offset * -1; - // Set the base x and y axis values + // Set the base x and y axis values $x_axis = $this->wm_hor_offset + $this->wm_padding; $y_axis = $this->wm_vrt_offset + $this->wm_padding; - // Set the vertical position + // Set the vertical position switch ($this->wm_vrt_alignment) { case 'T': @@ -920,7 +920,7 @@ class CI_Image_lib { break; } - // Set the horizontal position + // Set the horizontal position switch ($this->wm_hor_alignment) { case 'L': @@ -931,7 +931,7 @@ class CI_Image_lib { break; } - // Build the finalized image + // Build the finalized image if ($wm_img_type == 3 AND function_exists('imagealphablending')) { @imagealphablending($src_img, TRUE); @@ -954,7 +954,7 @@ class CI_Image_lib { imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity); } - // Output the image + // Output the image if ($this->dynamic_output == TRUE) { $this->image_display_gd($src_img); @@ -994,7 +994,7 @@ class CI_Image_lib { return FALSE; } - // Fetch source image properties + // Fetch source image properties $this->get_image_properties(); // Set RGB values for text and shadow @@ -1015,8 +1015,8 @@ class CI_Image_lib { // Reverse the vertical offset // When the image is positioned at the bottom // we don't want the vertical offset to push it - // further down. We want the reverse, so we'll - // invert the offset. Note: The horizontal + // further down. We want the reverse, so we'll + // invert the offset. Note: The horizontal // offset flips itself automatically if ($this->wm_vrt_alignment == 'B') @@ -1033,13 +1033,13 @@ class CI_Image_lib { if ($this->wm_font_size == '') $this->wm_font_size = '17'; - $fontwidth = $this->wm_font_size-($this->wm_font_size/4); + $fontwidth = $this->wm_font_size-($this->wm_font_size/4); $fontheight = $this->wm_font_size; $this->wm_vrt_offset += $this->wm_font_size; } else { - $fontwidth = imagefontwidth($this->wm_font_size); + $fontwidth = imagefontwidth($this->wm_font_size); $fontheight = imagefontheight($this->wm_font_size); } @@ -1080,11 +1080,11 @@ class CI_Image_lib { case "C": if ($this->wm_use_drop_shadow) $x_shad += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2); - $x_axis += floor(($this->orig_width -$fontwidth*strlen($this->wm_text))/2); + $x_axis += floor(($this->orig_width -$fontwidth*strlen($this->wm_text))/2); break; } - // Add the text to the source image + // Add the text to the source image if ($this->wm_use_truetype) { if ($this->wm_use_drop_shadow) @@ -1098,7 +1098,7 @@ class CI_Image_lib { imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); } - // Output the final image + // Output the final image if ($this->dynamic_output == TRUE) { $this->image_display_gd($src_img); @@ -1366,7 +1366,7 @@ class CI_Image_lib { * Size calculator * * This function takes a known width x height and - * recalculates it to a new size. Only one + * recalculates it to a new size. Only one * new variable needs to be known * * $props = array( @@ -1374,7 +1374,7 @@ class CI_Image_lib { * 'height' => $height, * 'new_width' => 40, * 'new_height' => '' - * ); + * ); * * @access public * @param array @@ -1418,10 +1418,10 @@ class CI_Image_lib { * Explode source_image * * This is a helper function that extracts the extension - * from the source_image. This function lets us deal with - * source_images with multiple periods, like: my.cool.jpg + * from the source_image. This function lets us deal with + * source_images with multiple periods, like: my.cool.jpg * It returns an associative array with two elements: - * $array['ext'] = '.jpg'; + * $array['ext'] = '.jpg'; * $array['name'] = 'my.cool'; * * @access public diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php index 34e0d7001..9e42a4385 100644 --- a/system/libraries/Javascript.php +++ b/system/libraries/Javascript.php @@ -1,4 +1,4 @@ -js =& $this->CI->$js_library_driver; - log_message('debug', "Javascript Class Initialized and loaded. Driver used: $js_library_driver"); + log_message('debug', "Javascript Class Initialized and loaded. Driver used: $js_library_driver"); } - // -------------------------------------------------------------------- + // -------------------------------------------------------------------- // Event Code // -------------------------------------------------------------------- @@ -378,7 +378,7 @@ class CI_Javascript { return $this->js->_unload($element, $js); } - // -------------------------------------------------------------------- + // -------------------------------------------------------------------- // Effects // -------------------------------------------------------------------- @@ -685,7 +685,7 @@ class CI_Javascript { return $str; } - + // -------------------------------------------------------------------- /** @@ -855,7 +855,7 @@ class CI_Javascript { } elseif (is_string($result) OR $is_key) { - return '"'.str_replace(array('\\', "\t", "\n", "\r", '"', '/'), array('\\\\', '\\t', '\\n', "\\r", '\"', '\/'), $result).'"'; + return '"'.str_replace(array('\\', "\t", "\n", "\r", '"', '/'), array('\\\\', '\\t', '\\n', "\\r", '\"', '\/'), $result).'"'; } elseif (is_scalar($result)) { diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 9f1db76ba..2505fc678 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -1,4 +1,4 @@ - '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4'); + protected $_levels = array('ERROR' => '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4'); /** * Constructor @@ -84,11 +84,11 @@ class CI_Log { } $filepath = $this->_log_path.'log-'.date('Y-m-d').'.php'; - $message = ''; + $message = ''; if ( ! file_exists($filepath)) { - $message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; + $message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; } if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE)) diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index cc62e660b..d9c22d501 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -1,4 +1,4 @@ -cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1; - $end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages; + $end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages; - // Is pagination being used over GET or POST? If get, add a per_page query + // Is pagination being used over GET or POST? If get, add a per_page query // string. If post, add a trailing slash to the base URL if needed if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) { @@ -194,14 +194,14 @@ class CI_Pagination { $output = ''; // Render the "First" link - if ($this->first_link !== FALSE AND $this->cur_page > ($this->num_links + 1)) + if ($this->first_link !== FALSE AND $this->cur_page > ($this->num_links + 1)) { $first_url = ($this->first_url == '') ? $this->base_url : $this->first_url; $output .= $this->first_tag_open.'anchor_class.'href="'.$first_url.'">'.$this->first_link.''.$this->first_tag_close; } // Render the "previous" link - if ($this->prev_link !== FALSE AND $this->cur_page != 1) + if ($this->prev_link !== FALSE AND $this->cur_page != 1) { $i = $uri_page_number - $this->per_page; @@ -263,7 +263,7 @@ class CI_Pagination { $output .= $this->last_tag_open.'anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->last_link.''.$this->last_tag_close; } - // Kill double slashes. Note: Sometimes we can end up with a double slash + // Kill double slashes. Note: Sometimes we can end up with a double slash // in the penultimate link so we'll kill all double slashes. $output = preg_replace("#([^:])//+#", "\\1/", $output); diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index d223da020..f48f2a7e5 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -1,4 +1,4 @@ -'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_benchmarks').'  '; @@ -168,7 +168,7 @@ class CI_Profiler { if (count($dbs) == 0) { - $output = "\n\n"; + $output = "\n\n"; $output .= '
'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; @@ -187,7 +187,7 @@ class CI_Profiler { // Key words we want bolded $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"; + $output = "\n\n"; $count = 0; @@ -249,7 +249,7 @@ class CI_Profiler { */ protected function _compile_get() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_get_data').'  '; @@ -298,7 +298,7 @@ class CI_Profiler { */ protected function _compile_post() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_post_data').'  '; @@ -347,7 +347,7 @@ class CI_Profiler { */ protected function _compile_uri_string() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_uri_string').'  '; @@ -376,7 +376,7 @@ class CI_Profiler { */ protected function _compile_controller_info() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_controller_info').'  '; @@ -400,7 +400,7 @@ class CI_Profiler { */ protected function _compile_memory_usage() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_memory_usage').'  '; @@ -431,7 +431,7 @@ class CI_Profiler { */ protected function _compile_http_headers() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_headers').'  ('.$this->CI->lang->line('profiler_section_show').')'; @@ -462,7 +462,7 @@ class CI_Profiler { */ protected function _compile_config() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_config').'  ('.$this->CI->lang->line('profiler_section_show').')'; diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 2c8a80163..76525dbb8 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -1,4 +1,4 @@ -CI->load->library('encrypt'); } - // Are we using a database? If so, load it + // Are we using a database? If so, load it if ($this->sess_use_database === TRUE AND $this->sess_table_name != '') { $this->CI->load->database(); } - // Set the "now" time. Can either be GMT or server time, based on the - // config prefs. We use this to set the "last activity" time + // Set the "now" time. Can either be GMT or server time, based on the + // config prefs. We use this to set the "last activity" time $this->now = $this->_get_time(); // Set the session length. If the session expiration is @@ -97,12 +97,12 @@ 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; // Run the Session routine. If a session doesn't exist we'll - // create a new one. If it does, we'll update it. + // create a new one. If it does, we'll update it. if ( ! $this->sess_read()) { $this->sess_create(); @@ -137,7 +137,7 @@ class CI_Session { // Fetch the cookie $session = $this->CI->input->cookie($this->sess_cookie_name); - // No cookie? Goodbye cruel world!... + // No cookie? Goodbye cruel world!... if ($session === FALSE) { log_message('debug', 'A session cookie was not found.'); @@ -155,8 +155,8 @@ class CI_Session { $hash = substr($session, strlen($session)-32); // get last 32 chars $session = substr($session, 0, strlen($session)-32); - // Does the md5 hash match? This is to prevent manipulation of session data in userspace - if ($hash !== md5($session.$this->encryption_key)) + // Does the md5 hash match? This is to prevent manipulation of session data in userspace + if ($hash !== md5($session.$this->encryption_key)) { log_message('error', 'The session cookie data did not match what was expected. This could be a possible hacking attempt.'); $this->sess_destroy(); @@ -212,14 +212,14 @@ class CI_Session { $query = $this->CI->db->get($this->sess_table_name); - // No result? Kill it! + // No result? Kill it! if ($query->num_rows() == 0) { $this->sess_destroy(); return FALSE; } - // Is there custom data? If so, add it to the main session array + // Is there custom data? If so, add it to the main session array $row = $query->row(); if (isset($row->user_data) AND $row->user_data != '') { @@ -252,7 +252,7 @@ class CI_Session { */ function sess_write() { - // Are we saving custom data to the DB? If not, all we do is update the cookie + // Are we saving custom data to the DB? If not, all we do is update the cookie if ($this->sess_use_database === FALSE) { $this->_set_cookie(); @@ -272,7 +272,7 @@ class CI_Session { $cookie_userdata[$val] = $this->userdata[$val]; } - // Did we find any custom data? If not, we turn the empty array into a string + // Did we find any custom data? If not, we turn the empty array into a string // since there's no reason to serialize and store an empty array in the DB if (count($custom_userdata) === 0) { @@ -288,7 +288,7 @@ class CI_Session { $this->CI->db->where('session_id', $this->userdata['session_id']); $this->CI->db->update($this->sess_table_name, array('last_activity' => $this->userdata['last_activity'], 'user_data' => $custom_userdata)); - // Write the cookie. Notice that we manually pass the cookie data array to the + // Write the cookie. Notice that we manually pass the cookie data array to the // _set_cookie() function. Normally that function will store $this->userdata, but // in this case that array contains custom data, which we do not want in the cookie. $this->_set_cookie($cookie_userdata); @@ -535,7 +535,7 @@ class CI_Session { */ function keep_flashdata($key) { - // 'old' flashdata gets removed. Here we mark all + // 'old' flashdata gets removed. Here we mark all // flashdata as 'new' to preserve it from _flashdata_sweep() // Note the function will return FALSE if the $key // provided cannot be found diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index 1a657572b..04e07d1c1 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -1,4 +1,4 @@ -heading) == 0 AND count($this->rows) == 0) { return 'Undefined table data'; @@ -376,7 +376,7 @@ class CI_Table { // -------------------------------------------------------------------- /** - * Clears the table arrays. Useful if multiple tables are being generated + * Clears the table arrays. Useful if multiple tables are being generated * * @access public * @return void @@ -495,7 +495,7 @@ class CI_Table { */ function _default_template() { - return array ( + return array ( 'table_open' => '
<<
', 'thead_open' => '', diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index b0a767822..b0f8a9098 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -1,4 +1,4 @@ -","\"", "'", "-"), array("&", "<", ">", """, "'", "-"), diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index 734cec104..3ceb0b52b 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -1,4 +1,4 @@ - tags if they exist. It's cheaper to do this separately since most content will + // match and yank
 tags if they exist. It's cheaper to do this separately since most content will
 		// not contain 
 tags, and it keeps the PCRE patterns below simpler and faster
 		if (strpos($str, 'inline_elements.")([ >])#i", "{@TAG}\\1\\2\\3", $str);
 
-		// Split the string at every tag.  This expression creates an array with this prototype:
+		// Split the string at every tag. This expression creates an array with this prototype:
 		//
 		//	[array]
 		//	{
@@ -126,7 +126,7 @@ class CI_Typography {
 		//	}
 		$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;
@@ -143,7 +143,7 @@ class CI_Typography {
 			{
 				if (preg_match("#".$this->skip_elements."#", $match[2]))
 				{
-					$process =  ($match[1] == '/') ? TRUE : FALSE;
+					$process = ($match[1] == '/') ? TRUE : FALSE;
 				}
 
 				if ($match[1] == '')
@@ -161,17 +161,17 @@ class CI_Typography {
 				continue;
 			}
 
-			//  Force a newline to make sure end tags get processed by _format_newlines()
+			// Force a newline to make sure end tags get processed by _format_newlines()
 			if ($current_chunk == $total_chunks)
 			{
 				$chunk .= "\n";
 			}
 
-			//  Convert Newlines into 

and
tags + // Convert Newlines into

and
tags $str .= $this->_format_newlines($chunk); } - // No opening block level tag? Add it if needed. + // 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", '

$1

<$2', $str); @@ -204,14 +204,14 @@ class CI_Typography { '#

<('.$this->block_elements.')#' => '<$1', // Clean up stray non-breaking spaces preceeding block elements - '#( \s*)+<('.$this->block_elements.')#' => ' <$2', + '#( \s*)+<('.$this->block_elements.')#' => ' <$2', // Replace the temporary markers we added earlier '/\{@TAG\}/' => '<', '/\{@DQ\}/' => '"', '/\{@SQ\}/' => "'", '/\{@DD\}/' => '--', - '/\{@NBS\}/' => ' ', + '/\{@NBS\}/' => ' ', // An unintended consequence of the _format_newlines function is that // some of the newlines get truncated, resulting in

tags @@ -296,7 +296,7 @@ class CI_Typography { '/(\w)\.{3}/' => '$1…', // double space after sentences - '/(\W) /' => '$1  ', + '/(\W) /' => '$1  ', // ampersands, if not a character entity '/&(?!#?[a-zA-Z0-9]{2,};)/' => '&' @@ -324,7 +324,7 @@ class CI_Typography { return $str; } - if (strpos($str, "\n") === FALSE && ! in_array($this->last_block_element, $this->inner_block_required)) + if (strpos($str, "\n") === FALSE && ! in_array($this->last_block_element, $this->inner_block_required)) { return $str; } @@ -341,7 +341,7 @@ class CI_Typography { // We trim off the right-side new line so that the closing

tag // will be positioned immediately following the string, matching // the behavior of the opening

tag - $str = '

'.rtrim($str).'

'; + $str = '

'.rtrim($str).'

'; } // Remove empty paragraphs if they are on the first line, as this @@ -367,7 +367,7 @@ class CI_Typography { */ function _protect_characters($match) { - return str_replace(array("'",'"','--',' '), array('{@SQ}', '{@DQ}', '{@DD}', '{@NBS}'), $match[0]); + return str_replace(array("'",'"','--',' '), array('{@SQ}', '{@DQ}', '{@DD}', '{@NBS}'), $match[0]); } // -------------------------------------------------------------------- diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 5bd7e801a..c9012f646 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -1,4 +1,4 @@ -set_error('upload_stopped_by_extension'); break; - default : $this->set_error('upload_no_file_selected'); + default : $this->set_error('upload_no_file_selected'); break; } @@ -290,7 +290,7 @@ class CI_Upload { /* * Run the file through the XSS hacking filter * This helps prevent malicious code from being - * embedded within a file. Scripts can easily + * embedded within a file. Scripts can easily * be disguised as images or other file types. */ if ($this->xss_clean) @@ -305,8 +305,8 @@ class CI_Upload { /* * Move the file to the final destination * To deal with different server configurations - * we'll attempt to use copy() first. If that fails - * we'll use move_uploaded_file(). One of the two should + * we'll attempt to use copy() first. If that fails + * we'll use move_uploaded_file(). One of the two should * reliably work in most environments */ if ( ! @copy($this->file_temp, $this->upload_path.$this->file_name)) @@ -321,7 +321,7 @@ class CI_Upload { /* * Set the finalized image dimensions * This sets the image width/height (assuming the - * file was an image). We use this information + * file was an image). We use this information * in the "data" function. */ $this->set_image_properties($this->upload_path.$this->file_name); @@ -518,7 +518,7 @@ class CI_Upload { $this->image_width = $D['0']; $this->image_height = $D['1']; $this->image_type = ( ! isset($types[$D['2']])) ? 'unknown' : $types[$D['2']]; - $this->image_size_str = $D['3']; // string containing height and width + $this->image_size_str = $D['3']; // string containing height and width } } } @@ -551,7 +551,7 @@ class CI_Upload { // IE will sometimes return odd mime-types during upload, so here we just standardize all // jpegs or pngs to the same file type. - $png_mimes = array('image/x-png'); + $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)) @@ -642,7 +642,7 @@ class CI_Upload { */ public function is_allowed_filesize() { - if ($this->max_size != 0 AND $this->file_size > $this->max_size) + if ($this->max_size != 0 AND $this->file_size > $this->max_size) { return FALSE; } @@ -721,7 +721,7 @@ class CI_Upload { return FALSE; } - $this->upload_path = preg_replace("/(.+?)\/*$/", "\\1/", $this->upload_path); + $this->upload_path = preg_replace("/(.+?)\/*$/", "\\1/", $this->upload_path); return TRUE; } @@ -834,7 +834,7 @@ class CI_Upload { $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 + // 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, '.', ''); @@ -844,8 +844,8 @@ class CI_Upload { // If the file being uploaded is an image, then we should have no problem with XSS attacks (in theory), but // 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 + // 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 // attempted XSS attack. @@ -933,7 +933,7 @@ class CI_Upload { /** * List of Mime Types * - * This is a list of mime types. We use it to validate + * This is a list of mime types. We use it to validate * the "allowed types" set by the developer * * @param string diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 016102a2a..543d1d5a3 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -1,4 +1,4 @@ -xmlrpcerr['unknown_method'] = '1'; $this->xmlrpcstr['unknown_method'] = 'This is not a known method for this XML-RPC Server'; $this->xmlrpcerr['invalid_return'] = '2'; - $this->xmlrpcstr['invalid_return'] = 'The XML data received was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.'; + $this->xmlrpcstr['invalid_return'] = 'The XML data received was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.'; $this->xmlrpcerr['incorrect_params'] = '3'; $this->xmlrpcstr['incorrect_params'] = 'Incorrect parameters were passed to method'; $this->xmlrpcerr['introspect_unknown'] = '4'; @@ -129,7 +129,7 @@ class CI_Xmlrpc { //------------------------------------- - // Initialize Prefs + // Initialize Prefs //------------------------------------- function initialize($config = array()) @@ -148,7 +148,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Take URL and parse it + // Take URL and parse it //------------------------------------- function server($url, $port=80) @@ -172,7 +172,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Set Timeout + // Set Timeout //------------------------------------- function timeout($seconds=5) @@ -185,7 +185,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Set Methods + // Set Methods //------------------------------------- function method($function) @@ -195,7 +195,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Take Array of Data and Create Objects + // Take Array of Data and Create Objects //------------------------------------- function request($incoming) @@ -216,7 +216,7 @@ class CI_Xmlrpc { //------------------------------------- - // Set Debug + // Set Debug //------------------------------------- function set_debug($flag = TRUE) @@ -225,7 +225,7 @@ class CI_Xmlrpc { } //------------------------------------- - // Values Parsing + // Values Parsing //------------------------------------- function values_parsing($value, $return = FALSE) @@ -268,7 +268,7 @@ class CI_Xmlrpc { //------------------------------------- - // Sends XML-RPC Request + // Sends XML-RPC Request //------------------------------------- function send_request() @@ -294,7 +294,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Returns Error + // Returns Error //------------------------------------- function display_error() @@ -304,7 +304,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Returns Remote Server Response + // Returns Remote Server Response //------------------------------------- function display_response() @@ -314,7 +314,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Sends an Error Message for Server Request + // Sends an Error Message for Server Request //------------------------------------- function send_error_message($number, $message) @@ -325,7 +325,7 @@ class CI_Xmlrpc { //------------------------------------- - // Send Response for Server Request + // Send Response for Server Request //------------------------------------- function send_response($response) @@ -399,7 +399,7 @@ class XML_RPC_Client extends CI_Xmlrpc } $r = "\r\n"; - $op = "POST {$this->path} HTTP/1.0$r"; + $op = "POST {$this->path} HTTP/1.0$r"; $op .= "Host: {$this->server}$r"; $op .= "Content-Type: text/xml$r"; $op .= "User-Agent: {$this->xmlrpcName}$r"; @@ -447,7 +447,7 @@ class XML_RPC_Response else if ( ! is_object($val)) { // programmer error, not an object - error_log("Invalid type '" . gettype($val) . "' (value: $val) passed to XML_RPC_Response. Defaulting to empty value."); + error_log("Invalid type '" . gettype($val) . "' (value: $val) passed to XML_RPC_Response. Defaulting to empty value."); $this->val = new XML_RPC_Values(); } else @@ -504,7 +504,7 @@ class XML_RPC_Response function decode($array=FALSE) { $CI =& get_instance(); - + if ($array !== FALSE && is_array($array)) { while (list($key) = each($array)) @@ -541,7 +541,7 @@ class XML_RPC_Response //------------------------------------- - // XML-RPC Object to PHP Types + // XML-RPC Object to PHP Types //------------------------------------- function xmlrpc_decoder($xmlrpc_val) @@ -581,7 +581,7 @@ class XML_RPC_Response //------------------------------------- - // ISO-8601 time to server or UTC time + // ISO-8601 time to server or UTC time //------------------------------------- function iso8601_decode($time, $utc=0) @@ -630,7 +630,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // Create Payload to Send + // Create Payload to Send //------------------------------------- function createPayload() @@ -650,7 +650,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // Parse External XML-RPC Server's Response + // Parse External XML-RPC Server's Response //------------------------------------- function parseResponse($fp) @@ -663,7 +663,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // DISPLAY HTTP CONTENT for DEBUGGING + // DISPLAY HTTP CONTENT for DEBUGGING //------------------------------------- if ($this->debug === TRUE) @@ -674,7 +674,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // Check for data + // Check for data //------------------------------------- if ($data == "") @@ -686,7 +686,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- - // Check for HTTP 200 Response + // Check for HTTP 200 Response //------------------------------------- if (strncmp($data, 'HTTP', 4) == 0 && ! preg_match('/^HTTP\/[0-9\.]+ 200 /', $data)) @@ -697,7 +697,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // Create and Set Up XML Parser + // Create and Set Up XML Parser //------------------------------------- $parser = xml_parser_create($this->xmlrpc_defencoding); @@ -718,7 +718,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- - // GET HEADERS + // GET HEADERS //------------------------------------- $lines = explode("\r\n", $data); @@ -734,7 +734,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- - // PARSE XML DATA + // PARSE XML DATA //------------------------------------- if ( ! xml_parse($parser, $data, count($data))) @@ -750,7 +750,7 @@ class XML_RPC_Message extends CI_Xmlrpc xml_parser_free($parser); // --------------------------------------- - // Got Ourselves Some Badness, It Seems + // Got Ourselves Some Badness, It Seems // --------------------------------------- if ($this->xh[$parser]['isf'] > 1) @@ -772,7 +772,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // DISPLAY XML CONTENT for DEBUGGING + // DISPLAY XML CONTENT for DEBUGGING //------------------------------------- if ($this->debug === TRUE) @@ -797,7 +797,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // SEND RESPONSE + // SEND RESPONSE //------------------------------------- $v = $this->xh[$parser]['value']; @@ -826,21 +826,21 @@ class XML_RPC_Message extends CI_Xmlrpc } // ------------------------------------ - // Begin Return Message Parsing section + // Begin Return Message Parsing section // ------------------------------------ // quick explanation of components: - // ac - used to accumulate values - // isf - used to indicate a fault - // lv - used to indicate "looking for a value": implements + // ac - used to accumulate values + // isf - used to indicate a fault + // lv - used to indicate "looking for a value": implements // the logic to allow values with no types to be strings - // params - used to store parameters in method calls - // method - used to store method name + // params - used to store parameters in method calls + // method - used to store method name // stack - array with parent tree of the xml element, // used to validate the nesting of elements //------------------------------------- - // Start Element Handler + // Start Element Handler //------------------------------------- function open_tag($the_parser, $name, $attrs) @@ -942,7 +942,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- - // End Element Handler + // End Element Handler //------------------------------------- function closing_tag($the_parser, $name) @@ -951,7 +951,7 @@ class XML_RPC_Message extends CI_Xmlrpc // 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 + // 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']); @@ -1080,13 +1080,13 @@ class XML_RPC_Message extends CI_Xmlrpc // We're all good kids with nuthin' to do break; default: - // End of an Invalid Element. Taken care of during the opening tag though + // End of an Invalid Element. Taken care of during the opening tag though break; } } //------------------------------------- - // Parses Character Data + // Parses Character Data //------------------------------------- function character_data($the_parser, $data) @@ -1116,7 +1116,7 @@ class XML_RPC_Message extends CI_Xmlrpc function output_parameters($array=FALSE) { $CI =& get_instance(); - + if ($array !== FALSE && is_array($array)) { while (list($key) = each($array)) diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 9cd332147..88af60693 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -1,4 +1,4 @@ -parseRequest(); - $payload = 'xmlrpc_defencoding.'"?'.'>'."\n"; + $payload = 'xmlrpc_defencoding.'"?'.'>'."\n"; $payload .= $this->debug_msg; $payload .= $r->prepare_response(); @@ -156,7 +156,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc function add_to_map($methodname, $function, $sig, $doc) { $this->methods[$methodname] = array( - 'function' => $function, + 'function' => $function, 'signature' => $sig, 'docstring' => $doc ); @@ -176,7 +176,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc global $HTTP_RAW_POST_DATA; //------------------------------------- - // Get Data + // Get Data //------------------------------------- if ($data == '') @@ -185,7 +185,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } //------------------------------------- - // Set up XML Parser + // Set up XML Parser //------------------------------------- $parser = xml_parser_create($this->xmlrpc_defencoding); @@ -207,7 +207,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- - // PARSE + PROCESS XML DATA + // PARSE + PROCESS XML DATA //------------------------------------- if ( ! xml_parse($parser, $data, 1)) @@ -235,7 +235,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc { if ($this->debug === TRUE) { - $plist .= "$i - " . print_r(get_object_vars($parser_object->xh[$parser]['params'][$i]), TRUE). ";\n"; + $plist .= "$i - " . print_r(get_object_vars($parser_object->xh[$parser]['params'][$i]), TRUE). ";\n"; } $m->addParam($parser_object->xh[$parser]['params'][$i]); @@ -252,7 +252,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } //------------------------------------- - // SET DEBUGGING MESSAGE + // SET DEBUGGING MESSAGE //------------------------------------- if ($this->debug === TRUE) @@ -285,7 +285,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } //------------------------------------- - // Valid Method + // Valid Method //------------------------------------- if ( ! isset($this->methods[$methName]['function'])) @@ -294,7 +294,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } //------------------------------------- - // Check for Method (and Object) + // Check for Method (and Object) //------------------------------------- $method_parts = explode(".", $this->methods[$methName]['function']); @@ -320,7 +320,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } //------------------------------------- - // Checking Methods Signature + // Checking Methods Signature //------------------------------------- if (isset($this->methods[$methName]['signature'])) @@ -353,7 +353,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } //------------------------------------- - // Calls the Function + // Calls the Function //------------------------------------- if ($objectCall === TRUE) @@ -381,11 +381,11 @@ class CI_Xmlrpcs extends CI_Xmlrpc return call_user_func($this->methods[$methName]['function'], $m); } } - + // -------------------------------------------------------------------- /** - * Server Function: List Methods + * Server Function: List Methods * * @access public * @param mixed @@ -409,11 +409,11 @@ class CI_Xmlrpcs extends CI_Xmlrpc $v->addArray($output); return new XML_RPC_Response($v); } - + // -------------------------------------------------------------------- /** - * Server Function: Return Signature for Method + * Server Function: Return Signature for Method * * @access public * @param mixed @@ -458,7 +458,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc // -------------------------------------------------------------------- /** - * Server Function: Doc String for Method + * Server Function: Doc String for Method * * @access public * @param mixed @@ -480,11 +480,11 @@ class CI_Xmlrpcs extends CI_Xmlrpc return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); } } - + // -------------------------------------------------------------------- /** - * Server Function: Multi-call + * Server Function: Multi-call * * @access public * @param mixed @@ -528,7 +528,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc // -------------------------------------------------------------------- /** - * Multi-call Function: Error Handling + * Multi-call Function: Error Handling * * @access public * @param mixed @@ -536,7 +536,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc */ function multicall_error($err) { - $str = is_string($err) ? $this->xmlrpcstr["multicall_${err}"] : $err->faultString(); + $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'); @@ -548,7 +548,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc // -------------------------------------------------------------------- /** - * Multi-call Function: Processes method + * Multi-call Function: Processes method * * @access public * @param mixed diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 666327d5c..1ae3e7f25 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -1,4 +1,4 @@ -CI =& get_instance(); + $this->CI =& get_instance(); extract($params); if ($autoload === TRUE) { - $this->script(); + $this->script(); } - + log_message('debug', "Jquery Class Initialized"); } - - // -------------------------------------------------------------------- + + // -------------------------------------------------------------------- // Event Code - // -------------------------------------------------------------------- + // -------------------------------------------------------------------- /** * Blur @@ -65,9 +65,9 @@ class CI_Jquery extends CI_Javascript { { return $this->_add_event($element, $js, 'blur'); } - + // -------------------------------------------------------------------- - + /** * Change * @@ -82,9 +82,9 @@ class CI_Jquery extends CI_Javascript { { return $this->_add_event($element, $js, 'change'); } - + // -------------------------------------------------------------------- - + /** * Click * @@ -112,7 +112,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Double Click * @@ -129,7 +129,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Error * @@ -146,7 +146,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Focus * @@ -163,7 +163,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Hover * @@ -185,7 +185,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Keydown * @@ -202,7 +202,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Keyup * @@ -216,10 +216,10 @@ class CI_Jquery extends CI_Javascript { function _keyup($element = 'this', $js = '') { return $this->_add_event($element, $js, 'keyup'); - } + } // -------------------------------------------------------------------- - + /** * Load * @@ -233,10 +233,10 @@ class CI_Jquery extends CI_Javascript { function _load($element = 'this', $js = '') { return $this->_add_event($element, $js, 'load'); - } - + } + // -------------------------------------------------------------------- - + /** * Mousedown * @@ -253,7 +253,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Mouse Out * @@ -270,7 +270,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Mouse Over * @@ -321,7 +321,7 @@ class CI_Jquery extends CI_Javascript { { $array_js = array($array_js); } - + foreach ($array_js as $js) { $this->jquery_code_for_compile[] = "\t$js\n"; @@ -361,7 +361,7 @@ class CI_Jquery extends CI_Javascript { { return $this->_add_event($element, $js, 'scroll'); } - + // -------------------------------------------------------------------- /** @@ -379,10 +379,10 @@ class CI_Jquery extends CI_Javascript { return $this->_add_event($element, $js, 'unload'); } - // -------------------------------------------------------------------- + // -------------------------------------------------------------------- // Effects - // -------------------------------------------------------------------- - + // -------------------------------------------------------------------- + /** * Add Class * @@ -395,7 +395,7 @@ class CI_Jquery extends CI_Javascript { function _addClass($element = 'this', $class='') { $element = $this->_prep_element($element); - $str = "$({$element}).addClass(\"$class\");"; + $str = "$({$element}).addClass(\"$class\");"; return $str; } @@ -416,9 +416,9 @@ class CI_Jquery extends CI_Javascript { { $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + $animations = "\t\t\t"; - + foreach ($params as $param=>$value) { $animations .= $param.': \''.$value.'\', '; @@ -430,19 +430,19 @@ class CI_Jquery extends CI_Javascript { { $speed = ', '.$speed; } - + if ($extra != '') { $extra = ', '.$extra; } - - $str = "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");"; - + + $str = "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");"; + return $str; } // -------------------------------------------------------------------- - + /** * Fade In * @@ -456,21 +456,21 @@ class CI_Jquery extends CI_Javascript { */ function _fadeIn($element = 'this', $speed = '', $callback = '') { - $element = $this->_prep_element($element); + $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).fadeIn({$speed}{$callback});"; - + + $str = "$({$element}).fadeIn({$speed}{$callback});"; + return $str; } - + // -------------------------------------------------------------------- - + /** * Fade Out * @@ -486,14 +486,14 @@ class CI_Jquery extends CI_Javascript { { $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).fadeOut({$speed}{$callback});"; - + + $str = "$({$element}).fadeOut({$speed}{$callback});"; + return $str; } @@ -512,19 +512,19 @@ class CI_Jquery extends CI_Javascript { */ function _hide($element = 'this', $speed = '', $callback = '') { - $element = $this->_prep_element($element); + $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).hide({$speed}{$callback});"; + + $str = "$({$element}).hide({$speed}{$callback});"; return $str; } - + // -------------------------------------------------------------------- /** @@ -539,12 +539,12 @@ class CI_Jquery extends CI_Javascript { function _removeClass($element = 'this', $class='') { $element = $this->_prep_element($element); - $str = "$({$element}).removeClass(\"$class\");"; + $str = "$({$element}).removeClass(\"$class\");"; return $str; } // -------------------------------------------------------------------- - + /** * Slide Up * @@ -558,21 +558,21 @@ class CI_Jquery extends CI_Javascript { */ function _slideUp($element = 'this', $speed = '', $callback = '') { - $element = $this->_prep_element($element); + $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).slideUp({$speed}{$callback});"; - + + $str = "$({$element}).slideUp({$speed}{$callback});"; + return $str; } - + // -------------------------------------------------------------------- - + /** * Slide Down * @@ -588,19 +588,19 @@ class CI_Jquery extends CI_Javascript { { $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).slideDown({$speed}{$callback});"; - + + $str = "$({$element}).slideDown({$speed}{$callback});"; + return $str; } // -------------------------------------------------------------------- - + /** * Slide Toggle * @@ -616,19 +616,19 @@ class CI_Jquery extends CI_Javascript { { $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).slideToggle({$speed}{$callback});"; - + + $str = "$({$element}).slideToggle({$speed}{$callback});"; + return $str; } - + // -------------------------------------------------------------------- - + /** * Toggle * @@ -641,12 +641,12 @@ class CI_Jquery extends CI_Javascript { function _toggle($element = 'this') { $element = $this->_prep_element($element); - $str = "$({$element}).toggle();"; + $str = "$({$element}).toggle();"; return $str; } - + // -------------------------------------------------------------------- - + /** * Toggle Class * @@ -659,12 +659,12 @@ class CI_Jquery extends CI_Javascript { function _toggleClass($element = 'this', $class='') { $element = $this->_prep_element($element); - $str = "$({$element}).toggleClass(\"$class\");"; + $str = "$({$element}).toggleClass(\"$class\");"; return $str; } - + // -------------------------------------------------------------------- - + /** * Show * @@ -678,16 +678,16 @@ class CI_Jquery extends CI_Javascript { */ function _show($element = 'this', $speed = '', $callback = '') { - $element = $this->_prep_element($element); + $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).show({$speed}{$callback});"; - + + $str = "$({$element}).show({$speed}{$callback});"; + return $str; } @@ -696,7 +696,7 @@ class CI_Jquery extends CI_Javascript { /** * Updater * - * An Ajax call that populates the designated DOM node with + * An Ajax call that populates the designated DOM node with * returned content * * @access private @@ -705,13 +705,13 @@ class CI_Jquery extends CI_Javascript { * @param string optional parameters * @return string */ - + function _updater($container = 'this', $controller, $options = '') - { + { $container = $this->_prep_element($container); - + $controller = (strpos('://', $controller) === FALSE) ? $controller : $this->CI->config->site_url($controller); - + // ajaxStart and ajaxStop are better choices here... but this is a stop gap if ($this->CI->config->item('javascript_ajax_img') == '') { @@ -721,7 +721,7 @@ class CI_Jquery extends CI_Javascript { { $loading_notifier = 'CI->config->slash_item('base_url') . $this->CI->config->item('javascript_ajax_img') . '\' alt=\'Loading\' />'; } - + $updater = "$($container).empty();\n"; // anything that was in... get it out $updater .= "\t\t$($container).prepend(\"$loading_notifier\");\n"; // to replace with an image @@ -741,7 +741,7 @@ class CI_Jquery extends CI_Javascript { // -------------------------------------------------------------------- // Pre-written handy stuff // -------------------------------------------------------------------- - + /** * Zebra tables * @@ -753,8 +753,8 @@ class CI_Jquery extends CI_Javascript { function _zebraTables($class = '', $odd = 'odd', $hover = '') { $class = ($class != '') ? '.'.$class : ''; - - $zebra = "\t\$(\"table{$class} tbody tr:nth-child(even)\").addClass(\"{$odd}\");"; + + $zebra = "\t\$(\"table{$class} tbody tr:nth-child(even)\").addClass(\"{$odd}\");"; $this->jquery_code_for_compile[] = $zebra; @@ -771,7 +771,7 @@ class CI_Jquery extends CI_Javascript { // -------------------------------------------------------------------- // Plugins // -------------------------------------------------------------------- - + /** * Corner Plugin * @@ -793,7 +793,7 @@ class CI_Jquery extends CI_Javascript { return "$(" . $this->_prep_element($element) . ").corner(".$corner_style.");"; } - + // -------------------------------------------------------------------- /** @@ -805,7 +805,7 @@ class CI_Jquery extends CI_Javascript { * @return void */ function modal($src, $relative = FALSE) - { + { $this->jquery_code_for_load[] = $this->external($src, $relative); } @@ -897,7 +897,7 @@ class CI_Jquery extends CI_Javascript { { $this->jquery_code_for_compile[] = "\t$(" . $this->_prep_element($table) . ").tablesorter($options);\n"; } - + // -------------------------------------------------------------------- // Class functions // -------------------------------------------------------------------- @@ -912,7 +912,7 @@ class CI_Jquery extends CI_Javascript { * @param string The code to execute * @param string The event to pass * @return string - */ + */ function _add_event($element, $js, $event) { if (is_array($js)) @@ -953,15 +953,15 @@ class CI_Jquery extends CI_Javascript { $script = '$(document).ready(function() {' . "\n"; $script .= implode('', $this->jquery_code_for_compile); $script .= '});'; - + $output = ($script_tags === FALSE) ? $script : $this->inline($script); $this->CI->load->vars(array($view_var => $output)); } - + // -------------------------------------------------------------------- - + /** * Clear Compile * @@ -976,7 +976,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Document Ready * @@ -992,7 +992,7 @@ class CI_Jquery extends CI_Javascript { $js = array ($js); } - + foreach ($js as $script) { $this->jquery_code_for_compile[] = $script; @@ -1016,7 +1016,7 @@ class CI_Jquery extends CI_Javascript { $this->jquery_code_for_load[] = $library_src; return $library_src; } - + // -------------------------------------------------------------------- /** @@ -1036,10 +1036,10 @@ class CI_Jquery extends CI_Javascript { { $element = '"'.$element.'"'; } - + return $element; } - + // -------------------------------------------------------------------- /** @@ -1050,7 +1050,7 @@ class CI_Jquery extends CI_Javascript { * @access private * @param string * @return string - */ + */ function _validate_speed($speed) { if (in_array($speed, array('slow', 'normal', 'fast'))) @@ -1061,7 +1061,7 @@ class CI_Jquery extends CI_Javascript { { $speed = ''; } - + return $speed; } -- cgit v1.2.3-24-g4f1b From 28bda7fd05d5261e0da1702e789cfedc6ab423b4 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Mon, 25 Apr 2011 15:00:45 -0500 Subject: swapping out preg_replace() in the driver library where str_replace() works just fine. --- system/libraries/Driver.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index b90b5aba6..1e01fcc1f 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -43,11 +43,11 @@ class CI_Driver_Library { // The class will be prefixed with the parent lib $child_class = $this->lib_name.'_'.$child; - + // Remove the CI_ prefix and lowercase - $lib_name = ucfirst(strtolower(preg_replace('/^CI_/', '', $this->lib_name))); - $driver_name = strtolower(preg_replace('/^CI_/', '', $child_class)); - + $lib_name = ucfirst(strtolower(str_replace('CI_', '', $this->lib_name))); + $driver_name = strtolower(str_replace('CI_', '', $child_class)); + if (in_array($driver_name, array_map('strtolower', $this->valid_drivers))) { // check and see if the driver is in a separate file -- cgit v1.2.3-24-g4f1b From 4b9c62980599228f070b401c7673dce8085b0c61 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 1 Jul 2011 17:40:48 -0500 Subject: backed out 648b42a75739, which was a NON-trivial whitespace commit. It broke the Typography class's string replacements, for instance --- system/libraries/Cache/Cache.php | 30 ++-- system/libraries/Cache/drivers/Cache_apc.php | 24 +-- system/libraries/Cache/drivers/Cache_file.php | 40 ++--- system/libraries/Calendar.php | 18 +-- system/libraries/Cart.php | 22 +-- system/libraries/Driver.php | 2 +- system/libraries/Email.php | 46 +++--- system/libraries/Encrypt.php | 2 +- system/libraries/Form_validation.php | 32 ++-- system/libraries/Ftp.php | 8 +- system/libraries/Image_lib.php | 118 +++++++------- system/libraries/Javascript.php | 12 +- system/libraries/Log.php | 8 +- system/libraries/Pagination.php | 18 +-- system/libraries/Parser.php | 18 +-- system/libraries/Profiler.php | 26 +-- system/libraries/Session.php | 30 ++-- system/libraries/Sha1.php | 8 +- system/libraries/Table.php | 12 +- system/libraries/Trackback.php | 16 +- system/libraries/Typography.php | 36 ++--- system/libraries/Unit_test.php | 2 +- system/libraries/Upload.php | 28 ++-- system/libraries/User_agent.php | 2 +- system/libraries/Xmlrpc.php | 90 +++++------ system/libraries/Xmlrpcs.php | 44 +++--- system/libraries/Zip.php | 12 +- system/libraries/javascript/Jquery.php | 218 +++++++++++++------------- 28 files changed, 461 insertions(+), 461 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 938c80857..61e7aa761 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -10,22 +10,22 @@ * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 2.0 - * @filesource + * @filesource */ // ------------------------------------------------------------------------ /** - * CodeIgniter Caching Class + * CodeIgniter Caching Class * * @package CodeIgniter * @subpackage Libraries * @category Core * @author ExpressionEngine Dev Team - * @link + * @link */ class CI_Cache extends CI_Driver_Library { - + protected $valid_drivers = array( 'cache_apc', 'cache_file', 'cache_memcached', 'cache_dummy' ); @@ -33,7 +33,7 @@ class CI_Cache extends CI_Driver_Library { protected $_cache_path = NULL; // Path of cache files (if file-based cache) protected $_adapter = 'dummy'; protected $_backup_driver; - + // ------------------------------------------------------------------------ /** @@ -52,16 +52,16 @@ class CI_Cache extends CI_Driver_Library { // ------------------------------------------------------------------------ /** - * Get + * Get * - * Look for a value in the cache. If it exists, return the data + * Look for a value in the cache. If it exists, return the data * if not, return FALSE * - * @param string + * @param string * @return mixed value that is stored/FALSE on failure */ public function get($id) - { + { return $this->{$this->_adapter}->get($id); } @@ -112,7 +112,7 @@ class CI_Cache extends CI_Driver_Library { * Cache Info * * @param string user/filehits - * @return mixed array on success, false on failure + * @return mixed array on success, false on failure */ public function cache_info($type = 'user') { @@ -120,7 +120,7 @@ class CI_Cache extends CI_Driver_Library { } // ------------------------------------------------------------------------ - + /** * Get Cache Metadata * @@ -131,7 +131,7 @@ class CI_Cache extends CI_Driver_Library { { return $this->{$this->_adapter}->get_metadata($id); } - + // ------------------------------------------------------------------------ /** @@ -139,11 +139,11 @@ class CI_Cache extends CI_Driver_Library { * * Initialize class properties based on the configuration array. * - * @param array + * @param array * @return void */ private function _initialize($config) - { + { $default_config = array( 'adapter', 'memcached' @@ -207,7 +207,7 @@ class CI_Cache extends CI_Driver_Library { return $obj; } - + // ------------------------------------------------------------------------ } // End Class diff --git a/system/libraries/Cache/drivers/Cache_apc.php b/system/libraries/Cache/drivers/Cache_apc.php index ea129eded..de75719c4 100644 --- a/system/libraries/Cache/drivers/Cache_apc.php +++ b/system/libraries/Cache/drivers/Cache_apc.php @@ -10,30 +10,30 @@ * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 2.0 - * @filesource + * @filesource */ // ------------------------------------------------------------------------ /** - * CodeIgniter APC Caching Class + * CodeIgniter APC Caching Class * * @package CodeIgniter * @subpackage Libraries * @category Core * @author ExpressionEngine Dev Team - * @link + * @link */ class CI_Cache_apc extends CI_Driver { /** - * Get + * Get * - * Look for a value in the cache. If it exists, return the data + * Look for a value in the cache. If it exists, return the data * if not, return FALSE * - * @param string + * @param string * @return mixed value that is stored/FALSE on failure */ public function get($id) @@ -43,8 +43,8 @@ class CI_Cache_apc extends CI_Driver { return (is_array($data)) ? $data[0] : FALSE; } - // ------------------------------------------------------------------------ - + // ------------------------------------------------------------------------ + /** * Cache Save * @@ -58,7 +58,7 @@ class CI_Cache_apc extends CI_Driver { { return apc_store($id, array($data, time(), $ttl), $ttl); } - + // ------------------------------------------------------------------------ /** @@ -90,7 +90,7 @@ class CI_Cache_apc extends CI_Driver { * Cache Info * * @param string user/filehits - * @return mixed array on success, false on failure + * @return mixed array on success, false on failure */ public function cache_info($type = NULL) { @@ -137,13 +137,13 @@ class CI_Cache_apc extends CI_Driver { log_message('error', 'The APC PHP extension must be loaded to use APC Cache.'); return FALSE; } - + return TRUE; } // ------------------------------------------------------------------------ - + } // End Class diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php index 39dcd15c2..13e2d1af6 100644 --- a/system/libraries/Cache/drivers/Cache_file.php +++ b/system/libraries/Cache/drivers/Cache_file.php @@ -10,19 +10,19 @@ * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 2.0 - * @filesource + * @filesource */ // ------------------------------------------------------------------------ /** - * CodeIgniter Memcached Caching Class + * CodeIgniter Memcached Caching Class * * @package CodeIgniter * @subpackage Libraries * @category Core * @author ExpressionEngine Dev Team - * @link + * @link */ class CI_Cache_file extends CI_Driver { @@ -36,9 +36,9 @@ class CI_Cache_file extends CI_Driver { { $CI =& get_instance(); $CI->load->helper('file'); - + $path = $CI->config->item('cache_path'); - + $this->_cache_path = ($path == '') ? APPPATH.'cache/' : $path; } @@ -56,16 +56,16 @@ class CI_Cache_file extends CI_Driver { { return FALSE; } - + $data = read_file($this->_cache_path.$id); $data = unserialize($data); - - if (time() > $data['time'] + $data['ttl']) + + if (time() > $data['time'] + $data['ttl']) { unlink($this->_cache_path.$id); return FALSE; } - + return $data['data']; } @@ -76,22 +76,22 @@ class CI_Cache_file extends CI_Driver { * * @param string unique key * @param mixed data to store - * @param int length of time (in seconds) the cache is valid + * @param int length of time (in seconds) the cache is valid * - Default is 60 seconds * @return boolean true on success/false on failure */ public function save($id, $data, $ttl = 60) - { + { $contents = array( 'time' => time(), - 'ttl' => $ttl, + 'ttl' => $ttl, 'data' => $data ); - + if (write_file($this->_cache_path.$id, serialize($contents))) { @chmod($this->_cache_path.$id, 0777); - return TRUE; + return TRUE; } return FALSE; @@ -116,7 +116,7 @@ class CI_Cache_file extends CI_Driver { * Clean the Cache * * @return boolean false on failure/true on success - */ + */ public function clean() { return delete_files($this->_cache_path); @@ -151,10 +151,10 @@ class CI_Cache_file extends CI_Driver { { return FALSE; } - - $data = read_file($this->_cache_path.$id); + + $data = read_file($this->_cache_path.$id); $data = unserialize($data); - + if (is_array($data)) { $data = $data['data']; @@ -170,7 +170,7 @@ class CI_Cache_file extends CI_Driver { 'mtime' => $mtime ); } - + return FALSE; } @@ -180,7 +180,7 @@ class CI_Cache_file extends CI_Driver { * Is supported * * In the file driver, check to see that the cache directory is indeed writable - * + * * @return boolean */ public function is_supported() diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 7dcbaab47..df0fd6eeb 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -1,4 +1,4 @@ -local_time); + $year = date("Y", $this->local_time); if ($month == '') $month = date("m", $this->local_time); @@ -128,7 +128,7 @@ class CI_Calendar { // Set the starting day number $local_date = mktime(12, 0, 0, $month, 1, $year); $date = getdate($local_date); - $day = $start_day + 1 - $date["wday"]; + $day = $start_day + 1 - $date["wday"]; while ($day > 1) { @@ -157,8 +157,8 @@ class CI_Calendar { // "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); + // 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']); @@ -233,7 +233,7 @@ class CI_Calendar { $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++; } @@ -287,7 +287,7 @@ class CI_Calendar { * Get Day Names * * Returns an array of day names (Sunday, Monday, etc.) based - * on the type. Options: long, short, abrev + * on the type. Options: long, short, abrev * * @access public * @param string @@ -404,7 +404,7 @@ class CI_Calendar { */ function default_template() { - return array ( + return array ( 'table_open' => '
', 'heading_row_start' => '', 'heading_previous_cell' => '', @@ -451,7 +451,7 @@ class CI_Calendar { $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) + 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)) { diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index fbccfb3d9..7f65b48b9 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -1,4 +1,4 @@ -CI =& get_instance(); - // Are any config settings being passed manually? If so, set them + // Are any config settings being passed manually? If so, set them $config = array(); if (count($params) > 0) { @@ -148,7 +148,7 @@ class CI_Cart { // -------------------------------------------------------------------- - // Does the $items array contain an id, quantity, price, and name? These are required + // 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'])) { log_message('error', 'The cart array must contain a product ID, quantity, price, and name.'); @@ -157,7 +157,7 @@ class CI_Cart { // -------------------------------------------------------------------- - // Prep the quantity. It can only be a number. Duh... + // Prep the quantity. It can only be a number. Duh... $items['qty'] = trim(preg_replace('/([^0-9])/i', '', $items['qty'])); // Trim any leading zeros $items['qty'] = trim(preg_replace('/(^[0]+)/i', '', $items['qty'])); @@ -175,7 +175,7 @@ class CI_Cart { // Note: These can be user-specified by setting the $this->product_id_rules variable. if ( ! preg_match("/^[".$this->product_id_rules."]+$/i", $items['id'])) { - log_message('error', 'Invalid product ID. The product ID can only contain alpha-numeric characters, dashes, and underscores'); + log_message('error', 'Invalid product ID. The product ID can only contain alpha-numeric characters, dashes, and underscores'); return FALSE; } @@ -191,7 +191,7 @@ class CI_Cart { // -------------------------------------------------------------------- - // Prep the price. Remove anything that isn't a number or decimal point. + // Prep the price. Remove anything that isn't a number or decimal point. $items['price'] = trim(preg_replace('/([^0-9\.])/i', '', $items['price'])); // Trim any leading zeros $items['price'] = trim(preg_replace('/(^[0]+)/i', '', $items['price'])); @@ -210,7 +210,7 @@ class CI_Cart { // 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 + // 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. @@ -271,7 +271,7 @@ class CI_Cart { } // You can either update a single product using a one-dimensional array, - // or multiple products using a multi-dimensional one. The way we + // 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 $save_cart = FALSE; @@ -344,7 +344,7 @@ class CI_Cart { return FALSE; } - // Is the quantity zero? If so we will remove the item from the cart. + // Is the quantity zero? If so we will remove the item from the cart. // If the quantity is greater than zero we are updating if ($items['qty'] == 0) { @@ -392,7 +392,7 @@ class CI_Cart { $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 + // 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'); diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index b90b5aba6..d1925c0ec 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -1,4 +1,4 @@ -_attach_name[] = $filename; $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename)))); - $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters + $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters return $this; } @@ -600,7 +600,7 @@ class CI_Email { $from = str_replace(">", "", $from); $from = str_replace("<", "", $from); - return "<".uniqid('').strstr($from, '@').">"; + return "<".uniqid('').strstr($from, '@').">"; } // -------------------------------------------------------------------- @@ -660,15 +660,15 @@ class CI_Email { */ private function _get_content_type() { - if ($this->mailtype == 'html' && count($this->_attach_name) == 0) + if ($this->mailtype == 'html' && count($this->_attach_name) == 0) { return 'html'; } - elseif ($this->mailtype == 'html' && count($this->_attach_name) > 0) + elseif ($this->mailtype == 'html' && count($this->_attach_name) > 0) { return 'html-attach'; } - elseif ($this->mailtype == 'text' && count($this->_attach_name) > 0) + elseif ($this->mailtype == 'text' && count($this->_attach_name) > 0) { return 'plain-attach'; } @@ -881,7 +881,7 @@ class CI_Email { // Use PHP's native public function to do the initial wordwrap. // We set the cut flag to FALSE so that any individual words that are - // too long get left alone. In the next step we'll deal with them. + // 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 @@ -999,7 +999,7 @@ class CI_Email { */ private function _build_message() { - if ($this->wordwrap === TRUE AND $this->mailtype != 'html') + if ($this->wordwrap === TRUE AND $this->mailtype != 'html') { $this->_body = $this->word_wrap($this->_body); } @@ -1135,7 +1135,7 @@ class CI_Email { return FALSE; } - $h = "--".$this->_atc_boundary.$this->newline; + $h = "--".$this->_atc_boundary.$this->newline; $h .= "Content-type: ".$ctype."; "; $h .= "name=\"".$basename."\"".$this->newline; $h .= "Content-Disposition: ".$this->_attach_disp[$i].";".$this->newline; @@ -1237,7 +1237,7 @@ class CI_Email { // encode = signs if ($ascii == '61') { - $char = $escape.strtoupper(sprintf('%02s', dechex($ascii))); // =3D + $char = $escape.strtoupper(sprintf('%02s', dechex($ascii))); // =3D } // If we're at the character limit, add the line to the output, @@ -1267,7 +1267,7 @@ class CI_Email { /** * Prep Q Encoding * - * Performs "Q Encoding" on a string for use in email headers. It's related + * Performs "Q Encoding" on a string for use in email headers. It's related * but not identical to quoted-printable, so it has its own method * * @access public @@ -1349,7 +1349,7 @@ class CI_Email { $this->reply_to($this->_headers['From']); } - if (( ! isset($this->_recipients) AND ! isset($this->_headers['To'])) AND + if (( ! isset($this->_recipients) AND ! isset($this->_headers['To'])) AND ( ! isset($this->_bcc_array) AND ! isset($this->_headers['Bcc'])) AND ( ! isset($this->_headers['Cc']))) { @@ -1359,7 +1359,7 @@ class CI_Email { $this->_build_headers(); - if ($this->bcc_batch_mode AND count($this->_bcc_array) > 0) + if ($this->bcc_batch_mode AND count($this->_bcc_array) > 0) { if (count($this->_bcc_array) > $this->bcc_batch_size) return $this->batch_bcc_send(); @@ -1380,7 +1380,7 @@ class CI_Email { // -------------------------------------------------------------------- /** - * Batch Bcc Send. Sends groups of BCCs in batches + * Batch Bcc Send. Sends groups of BCCs in batches * * @access public * @return bool @@ -1752,7 +1752,7 @@ class CI_Email { // -------------------------------------------------------------------- /** - * SMTP Authenticate + * SMTP Authenticate * * @access private * @return bool @@ -1764,7 +1764,7 @@ class CI_Email { return TRUE; } - if ($this->smtp_user == "" AND $this->smtp_pass == "") + if ($this->smtp_user == "" AND $this->smtp_pass == "") { $this->_set_error_message('lang:email_no_smtp_unpw'); return FALSE; diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 2f7db6623..b30a8cf0b 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -1,4 +1,4 @@ -_field_data) == 0) { - // No validation rules? We're done... + // No validation rules? We're done... if (count($this->_config_rules) == 0) { return FALSE; @@ -648,7 +648,7 @@ class CI_Form_validation { } } - // Did the rule test negatively? If so, grab the error. + // Did the rule test negatively? If so, grab the error. if ($result === FALSE) { if ( ! isset($this->_error_messages[$rule])) @@ -664,7 +664,7 @@ class CI_Form_validation { } // Is the parameter we are inserting into the error message the name - // of another field? If so we need to grab its "field label" + // 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']); @@ -704,7 +704,7 @@ class CI_Form_validation { // Grab the variable $line = substr($fieldname, 5); - // Were we able to translate the field name? If not we use $line + // Were we able to translate the field name? If not we use $line if (FALSE === ($fieldname = $this->CI->lang->line($line))) { return $line; @@ -735,7 +735,7 @@ class CI_Form_validation { } // If the data is an array output them one at a time. - // E.g: form_input('name[]', set_value('name[]'); + // E.g: form_input('name[]', set_value('name[]'); if (is_array($this->_field_data[$field]['postdata'])) { return array_shift($this->_field_data[$field]['postdata']); @@ -914,7 +914,7 @@ class CI_Form_validation { return FALSE; } - return TRUE; + return TRUE; } // -------------------------------------------------------------------- @@ -1207,7 +1207,7 @@ class CI_Form_validation { // -------------------------------------------------------------------- /** - * Is a Natural number (0,1,2,3, etc.) + * Is a Natural number (0,1,2,3, etc.) * * @access public * @param string @@ -1221,7 +1221,7 @@ class CI_Form_validation { // -------------------------------------------------------------------- /** - * Is a Natural number, but not a zero (1,2,3, etc.) + * Is a Natural number, but not a zero (1,2,3, etc.) * * @access public * @param string @@ -1354,7 +1354,7 @@ class CI_Form_validation { */ function encode_php_tags($str) { - return str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); + return str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); } } diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 859cc9c30..d7a8b3b02 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -1,4 +1,4 @@ -list_files($filepath); @@ -513,7 +513,7 @@ class CI_FTP { * Read a directory and recreate it remotely * * This function recursively reads a folder and everything it contains (including - * sub-folders) and creates a mirror via FTP based on it. Whatever the directory structure + * sub-folders) and creates a mirror via FTP based on it. Whatever the directory structure * of the original file path will be recreated on the server. * * @access public diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 099a238dd..8902f524d 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1,4 +1,4 @@ -source_image == '') { $this->set_error('imglib_source_image_required'); - return FALSE; + return FALSE; } /* * Is getimagesize() Available? * * We use it to determine the image properties (width/height). - * Note: We need to figure out how to determine image + * Note: We need to figure out how to determine image * properties using ImageMagick and NetPBM * */ @@ -189,7 +189,7 @@ class CI_Image_lib { // Set the Image Properties if ( ! $this->get_image_properties($this->source_folder.$this->source_image)) { - return FALSE; + return FALSE; } /* @@ -197,7 +197,7 @@ class CI_Image_lib { * * If the user has set a "new_image" name it means * we are making a copy of the source image. If not - * it means we are altering the original. We'll + * it means we are altering the original. We'll * set the destination filename and path accordingly. * */ @@ -267,7 +267,7 @@ class CI_Image_lib { * * When creating thumbs or copies, the target width/height * might not be in correct proportion with the source - * image's width/height. We'll recalculate it here. + * image's width/height. We'll recalculate it here. * */ if ($this->maintain_ratio === TRUE && ($this->width != '' AND $this->height != '')) @@ -399,7 +399,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 @@ -469,8 +469,8 @@ class CI_Image_lib { // Let's set up our values based on the action if ($action == 'crop') { - // Reassign the source width/height if cropping - $this->orig_width = $this->width; + // Reassign the source width/height if cropping + $this->orig_width = $this->width; $this->orig_height = $this->height; // GD 2.0 has a cropping bug so we'll test for it @@ -487,19 +487,19 @@ class CI_Image_lib { $this->y_axis = 0; } - // Create the image handle + // Create the image handle if ( ! ($src_img = $this->image_create_gd())) { 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. + // 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') AND $v2_override == FALSE) if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor')) { $create = 'imagecreatetruecolor'; @@ -521,7 +521,7 @@ class CI_Image_lib { $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 + // Show the image if ($this->dynamic_output == TRUE) { $this->image_display_gd($dst_img); @@ -535,7 +535,7 @@ class CI_Image_lib { } } - // Kill the file handles + // Kill the file handles imagedestroy($dst_img); imagedestroy($src_img); @@ -558,7 +558,7 @@ class CI_Image_lib { */ function image_process_imagemagick($action = 'resize') { - // Do we have a vaild library path? + // Do we have a vaild library path? if ($this->library_path == '') { $this->set_error('imglib_libpath_invalid'); @@ -593,7 +593,7 @@ class CI_Image_lib { $cmd .= " ".$angle." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; } - else // Resize + else // Resize { $cmd .= " -resize ".$this->width."x".$this->height." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; } @@ -634,7 +634,7 @@ class CI_Image_lib { return FALSE; } - // Build the resizing command + // Build the resizing command switch ($this->image_type) { case 1 : @@ -684,7 +684,7 @@ class CI_Image_lib { @exec($cmd, $output, $retval); - // Did it work? + // Did it work? if ($retval > 0) { $this->set_error('imglib_image_process_failed'); @@ -711,7 +711,7 @@ class CI_Image_lib { */ function image_rotate_gd() { - // Create the image handle + // Create the image handle if ( ! ($src_img = $this->image_create_gd())) { return FALSE; @@ -724,10 +724,10 @@ class CI_Image_lib { $white = imagecolorallocate($src_img, 255, 255, 255); - // Rotate it! + // Rotate it! $dst_img = imagerotate($src_img, $this->rotation_angle, $white); - // Save the Image + // Save the Image if ($this->dynamic_output == TRUE) { $this->image_display_gd($dst_img); @@ -741,7 +741,7 @@ class CI_Image_lib { } } - // Kill the file handles + // Kill the file handles imagedestroy($dst_img); imagedestroy($src_img); @@ -769,14 +769,14 @@ class CI_Image_lib { return FALSE; } - $width = $this->orig_width; + $width = $this->orig_width; $height = $this->orig_height; if ($this->rotation_angle == 'hor') { for ($i = 0; $i < $height; $i++) { - $left = 0; + $left = 0; $right = $width-1; while ($left < $right) @@ -813,7 +813,7 @@ class CI_Image_lib { } } - // Show the image + // Show the image if ($this->dynamic_output == TRUE) { $this->image_display_gd($src_img); @@ -827,7 +827,7 @@ class CI_Image_lib { } } - // Kill the file handles + // Kill the file handles imagedestroy($src_img); // Set the file to 777 @@ -876,24 +876,24 @@ class CI_Image_lib { return FALSE; } - // Fetch source image properties + // Fetch source image properties $this->get_image_properties(); - // Fetch watermark image properties + // Fetch watermark image properties $props = $this->get_image_properties($this->wm_overlay_path, TRUE); $wm_img_type = $props['image_type']; $wm_width = $props['width']; $wm_height = $props['height']; - // Create two image resources - $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type); + // Create two image resources + $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type); $src_img = $this->image_create_gd($this->full_src_path); // Reverse the offset if necessary // When the image is positioned at the bottom // we don't want the vertical offset to push it - // further down. We want the reverse, so we'll - // invert the offset. Same with the horizontal + // further down. We want the reverse, so we'll + // invert the offset. Same with the horizontal // offset when the image is at the right $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); @@ -905,11 +905,11 @@ class CI_Image_lib { if ($this->wm_hor_alignment == 'R') $this->wm_hor_offset = $this->wm_hor_offset * -1; - // Set the base x and y axis values + // Set the base x and y axis values $x_axis = $this->wm_hor_offset + $this->wm_padding; $y_axis = $this->wm_vrt_offset + $this->wm_padding; - // Set the vertical position + // Set the vertical position switch ($this->wm_vrt_alignment) { case 'T': @@ -920,7 +920,7 @@ class CI_Image_lib { break; } - // Set the horizontal position + // Set the horizontal position switch ($this->wm_hor_alignment) { case 'L': @@ -931,7 +931,7 @@ class CI_Image_lib { break; } - // Build the finalized image + // Build the finalized image if ($wm_img_type == 3 AND function_exists('imagealphablending')) { @imagealphablending($src_img, TRUE); @@ -954,7 +954,7 @@ class CI_Image_lib { imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity); } - // Output the image + // Output the image if ($this->dynamic_output == TRUE) { $this->image_display_gd($src_img); @@ -994,7 +994,7 @@ class CI_Image_lib { return FALSE; } - // Fetch source image properties + // Fetch source image properties $this->get_image_properties(); // Set RGB values for text and shadow @@ -1015,8 +1015,8 @@ class CI_Image_lib { // Reverse the vertical offset // When the image is positioned at the bottom // we don't want the vertical offset to push it - // further down. We want the reverse, so we'll - // invert the offset. Note: The horizontal + // further down. We want the reverse, so we'll + // invert the offset. Note: The horizontal // offset flips itself automatically if ($this->wm_vrt_alignment == 'B') @@ -1033,13 +1033,13 @@ class CI_Image_lib { if ($this->wm_font_size == '') $this->wm_font_size = '17'; - $fontwidth = $this->wm_font_size-($this->wm_font_size/4); + $fontwidth = $this->wm_font_size-($this->wm_font_size/4); $fontheight = $this->wm_font_size; $this->wm_vrt_offset += $this->wm_font_size; } else { - $fontwidth = imagefontwidth($this->wm_font_size); + $fontwidth = imagefontwidth($this->wm_font_size); $fontheight = imagefontheight($this->wm_font_size); } @@ -1080,11 +1080,11 @@ class CI_Image_lib { case "C": if ($this->wm_use_drop_shadow) $x_shad += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2); - $x_axis += floor(($this->orig_width -$fontwidth*strlen($this->wm_text))/2); + $x_axis += floor(($this->orig_width -$fontwidth*strlen($this->wm_text))/2); break; } - // Add the text to the source image + // Add the text to the source image if ($this->wm_use_truetype) { if ($this->wm_use_drop_shadow) @@ -1098,7 +1098,7 @@ class CI_Image_lib { imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); } - // Output the final image + // Output the final image if ($this->dynamic_output == TRUE) { $this->image_display_gd($src_img); @@ -1366,7 +1366,7 @@ class CI_Image_lib { * Size calculator * * This function takes a known width x height and - * recalculates it to a new size. Only one + * recalculates it to a new size. Only one * new variable needs to be known * * $props = array( @@ -1374,7 +1374,7 @@ class CI_Image_lib { * 'height' => $height, * 'new_width' => 40, * 'new_height' => '' - * ); + * ); * * @access public * @param array @@ -1418,10 +1418,10 @@ class CI_Image_lib { * Explode source_image * * This is a helper function that extracts the extension - * from the source_image. This function lets us deal with - * source_images with multiple periods, like: my.cool.jpg + * from the source_image. This function lets us deal with + * source_images with multiple periods, like: my.cool.jpg * It returns an associative array with two elements: - * $array['ext'] = '.jpg'; + * $array['ext'] = '.jpg'; * $array['name'] = 'my.cool'; * * @access public diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php index 9e42a4385..34e0d7001 100644 --- a/system/libraries/Javascript.php +++ b/system/libraries/Javascript.php @@ -1,4 +1,4 @@ -js =& $this->CI->$js_library_driver; - log_message('debug', "Javascript Class Initialized and loaded. Driver used: $js_library_driver"); + log_message('debug', "Javascript Class Initialized and loaded. Driver used: $js_library_driver"); } - // -------------------------------------------------------------------- + // -------------------------------------------------------------------- // Event Code // -------------------------------------------------------------------- @@ -378,7 +378,7 @@ class CI_Javascript { return $this->js->_unload($element, $js); } - // -------------------------------------------------------------------- + // -------------------------------------------------------------------- // Effects // -------------------------------------------------------------------- @@ -685,7 +685,7 @@ class CI_Javascript { return $str; } - + // -------------------------------------------------------------------- /** @@ -855,7 +855,7 @@ class CI_Javascript { } elseif (is_string($result) OR $is_key) { - return '"'.str_replace(array('\\', "\t", "\n", "\r", '"', '/'), array('\\\\', '\\t', '\\n', "\\r", '\"', '\/'), $result).'"'; + return '"'.str_replace(array('\\', "\t", "\n", "\r", '"', '/'), array('\\\\', '\\t', '\\n', "\\r", '\"', '\/'), $result).'"'; } elseif (is_scalar($result)) { diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 2505fc678..9f1db76ba 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -1,4 +1,4 @@ - '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4'); + protected $_levels = array('ERROR' => '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4'); /** * Constructor @@ -84,11 +84,11 @@ class CI_Log { } $filepath = $this->_log_path.'log-'.date('Y-m-d').'.php'; - $message = ''; + $message = ''; if ( ! file_exists($filepath)) { - $message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; + $message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; } if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE)) diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index d9c22d501..cc62e660b 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -1,4 +1,4 @@ -cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1; - $end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages; + $end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages; - // Is pagination being used over GET or POST? If get, add a per_page query + // Is pagination being used over GET or POST? If get, add a per_page query // string. If post, add a trailing slash to the base URL if needed if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) { @@ -194,14 +194,14 @@ class CI_Pagination { $output = ''; // Render the "First" link - if ($this->first_link !== FALSE AND $this->cur_page > ($this->num_links + 1)) + if ($this->first_link !== FALSE AND $this->cur_page > ($this->num_links + 1)) { $first_url = ($this->first_url == '') ? $this->base_url : $this->first_url; $output .= $this->first_tag_open.'anchor_class.'href="'.$first_url.'">'.$this->first_link.''.$this->first_tag_close; } // Render the "previous" link - if ($this->prev_link !== FALSE AND $this->cur_page != 1) + if ($this->prev_link !== FALSE AND $this->cur_page != 1) { $i = $uri_page_number - $this->per_page; @@ -263,7 +263,7 @@ class CI_Pagination { $output .= $this->last_tag_open.'anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->last_link.''.$this->last_tag_close; } - // Kill double slashes. Note: Sometimes we can end up with a double slash + // Kill double slashes. Note: Sometimes we can end up with a double slash // in the penultimate link so we'll kill all double slashes. $output = preg_replace("#([^:])//+#", "\\1/", $output); diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index f48f2a7e5..d223da020 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -1,4 +1,4 @@ -'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_benchmarks').'  '; @@ -168,7 +168,7 @@ class CI_Profiler { if (count($dbs) == 0) { - $output = "\n\n"; + $output = "\n\n"; $output .= '
'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; @@ -187,7 +187,7 @@ class CI_Profiler { // Key words we want bolded $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"; + $output = "\n\n"; $count = 0; @@ -249,7 +249,7 @@ class CI_Profiler { */ protected function _compile_get() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_get_data').'  '; @@ -298,7 +298,7 @@ class CI_Profiler { */ protected function _compile_post() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_post_data').'  '; @@ -347,7 +347,7 @@ class CI_Profiler { */ protected function _compile_uri_string() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_uri_string').'  '; @@ -376,7 +376,7 @@ class CI_Profiler { */ protected function _compile_controller_info() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_controller_info').'  '; @@ -400,7 +400,7 @@ class CI_Profiler { */ protected function _compile_memory_usage() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_memory_usage').'  '; @@ -431,7 +431,7 @@ class CI_Profiler { */ protected function _compile_http_headers() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_headers').'  ('.$this->CI->lang->line('profiler_section_show').')'; @@ -462,7 +462,7 @@ class CI_Profiler { */ protected function _compile_config() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_config').'  ('.$this->CI->lang->line('profiler_section_show').')'; diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 76525dbb8..2c8a80163 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -1,4 +1,4 @@ -CI->load->library('encrypt'); } - // Are we using a database? If so, load it + // Are we using a database? If so, load it if ($this->sess_use_database === TRUE AND $this->sess_table_name != '') { $this->CI->load->database(); } - // Set the "now" time. Can either be GMT or server time, based on the - // config prefs. We use this to set the "last activity" time + // Set the "now" time. Can either be GMT or server time, based on the + // config prefs. We use this to set the "last activity" time $this->now = $this->_get_time(); // Set the session length. If the session expiration is @@ -97,12 +97,12 @@ 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; // Run the Session routine. If a session doesn't exist we'll - // create a new one. If it does, we'll update it. + // create a new one. If it does, we'll update it. if ( ! $this->sess_read()) { $this->sess_create(); @@ -137,7 +137,7 @@ class CI_Session { // Fetch the cookie $session = $this->CI->input->cookie($this->sess_cookie_name); - // No cookie? Goodbye cruel world!... + // No cookie? Goodbye cruel world!... if ($session === FALSE) { log_message('debug', 'A session cookie was not found.'); @@ -155,8 +155,8 @@ class CI_Session { $hash = substr($session, strlen($session)-32); // get last 32 chars $session = substr($session, 0, strlen($session)-32); - // Does the md5 hash match? This is to prevent manipulation of session data in userspace - if ($hash !== md5($session.$this->encryption_key)) + // Does the md5 hash match? This is to prevent manipulation of session data in userspace + if ($hash !== md5($session.$this->encryption_key)) { log_message('error', 'The session cookie data did not match what was expected. This could be a possible hacking attempt.'); $this->sess_destroy(); @@ -212,14 +212,14 @@ class CI_Session { $query = $this->CI->db->get($this->sess_table_name); - // No result? Kill it! + // No result? Kill it! if ($query->num_rows() == 0) { $this->sess_destroy(); return FALSE; } - // Is there custom data? If so, add it to the main session array + // Is there custom data? If so, add it to the main session array $row = $query->row(); if (isset($row->user_data) AND $row->user_data != '') { @@ -252,7 +252,7 @@ class CI_Session { */ function sess_write() { - // Are we saving custom data to the DB? If not, all we do is update the cookie + // Are we saving custom data to the DB? If not, all we do is update the cookie if ($this->sess_use_database === FALSE) { $this->_set_cookie(); @@ -272,7 +272,7 @@ class CI_Session { $cookie_userdata[$val] = $this->userdata[$val]; } - // Did we find any custom data? If not, we turn the empty array into a string + // Did we find any custom data? If not, we turn the empty array into a string // since there's no reason to serialize and store an empty array in the DB if (count($custom_userdata) === 0) { @@ -288,7 +288,7 @@ class CI_Session { $this->CI->db->where('session_id', $this->userdata['session_id']); $this->CI->db->update($this->sess_table_name, array('last_activity' => $this->userdata['last_activity'], 'user_data' => $custom_userdata)); - // Write the cookie. Notice that we manually pass the cookie data array to the + // Write the cookie. Notice that we manually pass the cookie data array to the // _set_cookie() function. Normally that function will store $this->userdata, but // in this case that array contains custom data, which we do not want in the cookie. $this->_set_cookie($cookie_userdata); @@ -535,7 +535,7 @@ class CI_Session { */ function keep_flashdata($key) { - // 'old' flashdata gets removed. Here we mark all + // 'old' flashdata gets removed. Here we mark all // flashdata as 'new' to preserve it from _flashdata_sweep() // Note the function will return FALSE if the $key // provided cannot be found diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index 04e07d1c1..1a657572b 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -1,4 +1,4 @@ -heading) == 0 AND count($this->rows) == 0) { return 'Undefined table data'; @@ -376,7 +376,7 @@ class CI_Table { // -------------------------------------------------------------------- /** - * Clears the table arrays. Useful if multiple tables are being generated + * Clears the table arrays. Useful if multiple tables are being generated * * @access public * @return void @@ -495,7 +495,7 @@ class CI_Table { */ function _default_template() { - return array ( + return array ( 'table_open' => '
<<
', 'thead_open' => '', diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index b0f8a9098..b0a767822 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -1,4 +1,4 @@ -","\"", "'", "-"), array("&", "<", ">", """, "'", "-"), diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index 3ceb0b52b..734cec104 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -1,4 +1,4 @@ - tags if they exist. It's cheaper to do this separately since most content will + // match and yank
 tags if they exist.  It's cheaper to do this separately since most content will
 		// not contain 
 tags, and it keeps the PCRE patterns below simpler and faster
 		if (strpos($str, 'inline_elements.")([ >])#i", "{@TAG}\\1\\2\\3", $str);
 
-		// Split the string at every tag. This expression creates an array with this prototype:
+		// Split the string at every tag.  This expression creates an array with this prototype:
 		//
 		//	[array]
 		//	{
@@ -126,7 +126,7 @@ class CI_Typography {
 		//	}
 		$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;
@@ -143,7 +143,7 @@ class CI_Typography {
 			{
 				if (preg_match("#".$this->skip_elements."#", $match[2]))
 				{
-					$process = ($match[1] == '/') ? TRUE : FALSE;
+					$process =  ($match[1] == '/') ? TRUE : FALSE;
 				}
 
 				if ($match[1] == '')
@@ -161,17 +161,17 @@ class CI_Typography {
 				continue;
 			}
 
-			// Force a newline to make sure end tags get processed by _format_newlines()
+			//  Force a newline to make sure end tags get processed by _format_newlines()
 			if ($current_chunk == $total_chunks)
 			{
 				$chunk .= "\n";
 			}
 
-			// Convert Newlines into 

and
tags + // Convert Newlines into

and
tags $str .= $this->_format_newlines($chunk); } - // No opening block level tag? Add it if needed. + // 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", '

$1

<$2', $str); @@ -204,14 +204,14 @@ class CI_Typography { '#

<('.$this->block_elements.')#' => '<$1', // Clean up stray non-breaking spaces preceeding block elements - '#( \s*)+<('.$this->block_elements.')#' => ' <$2', + '#( \s*)+<('.$this->block_elements.')#' => ' <$2', // Replace the temporary markers we added earlier '/\{@TAG\}/' => '<', '/\{@DQ\}/' => '"', '/\{@SQ\}/' => "'", '/\{@DD\}/' => '--', - '/\{@NBS\}/' => ' ', + '/\{@NBS\}/' => ' ', // An unintended consequence of the _format_newlines function is that // some of the newlines get truncated, resulting in

tags @@ -296,7 +296,7 @@ class CI_Typography { '/(\w)\.{3}/' => '$1…', // double space after sentences - '/(\W) /' => '$1  ', + '/(\W) /' => '$1  ', // ampersands, if not a character entity '/&(?!#?[a-zA-Z0-9]{2,};)/' => '&' @@ -324,7 +324,7 @@ class CI_Typography { return $str; } - if (strpos($str, "\n") === FALSE && ! in_array($this->last_block_element, $this->inner_block_required)) + if (strpos($str, "\n") === FALSE && ! in_array($this->last_block_element, $this->inner_block_required)) { return $str; } @@ -341,7 +341,7 @@ class CI_Typography { // We trim off the right-side new line so that the closing

tag // will be positioned immediately following the string, matching // the behavior of the opening

tag - $str = '

'.rtrim($str).'

'; + $str = '

'.rtrim($str).'

'; } // Remove empty paragraphs if they are on the first line, as this @@ -367,7 +367,7 @@ class CI_Typography { */ function _protect_characters($match) { - return str_replace(array("'",'"','--',' '), array('{@SQ}', '{@DQ}', '{@DD}', '{@NBS}'), $match[0]); + return str_replace(array("'",'"','--',' '), array('{@SQ}', '{@DQ}', '{@DD}', '{@NBS}'), $match[0]); } // -------------------------------------------------------------------- diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index c9012f646..5bd7e801a 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -1,4 +1,4 @@ -set_error('upload_stopped_by_extension'); break; - default : $this->set_error('upload_no_file_selected'); + default : $this->set_error('upload_no_file_selected'); break; } @@ -290,7 +290,7 @@ class CI_Upload { /* * Run the file through the XSS hacking filter * This helps prevent malicious code from being - * embedded within a file. Scripts can easily + * embedded within a file. Scripts can easily * be disguised as images or other file types. */ if ($this->xss_clean) @@ -305,8 +305,8 @@ class CI_Upload { /* * Move the file to the final destination * To deal with different server configurations - * we'll attempt to use copy() first. If that fails - * we'll use move_uploaded_file(). One of the two should + * we'll attempt to use copy() first. If that fails + * we'll use move_uploaded_file(). One of the two should * reliably work in most environments */ if ( ! @copy($this->file_temp, $this->upload_path.$this->file_name)) @@ -321,7 +321,7 @@ class CI_Upload { /* * Set the finalized image dimensions * This sets the image width/height (assuming the - * file was an image). We use this information + * file was an image). We use this information * in the "data" function. */ $this->set_image_properties($this->upload_path.$this->file_name); @@ -518,7 +518,7 @@ class CI_Upload { $this->image_width = $D['0']; $this->image_height = $D['1']; $this->image_type = ( ! isset($types[$D['2']])) ? 'unknown' : $types[$D['2']]; - $this->image_size_str = $D['3']; // string containing height and width + $this->image_size_str = $D['3']; // string containing height and width } } } @@ -551,7 +551,7 @@ class CI_Upload { // IE will sometimes return odd mime-types during upload, so here we just standardize all // jpegs or pngs to the same file type. - $png_mimes = array('image/x-png'); + $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)) @@ -642,7 +642,7 @@ class CI_Upload { */ public function is_allowed_filesize() { - if ($this->max_size != 0 AND $this->file_size > $this->max_size) + if ($this->max_size != 0 AND $this->file_size > $this->max_size) { return FALSE; } @@ -721,7 +721,7 @@ class CI_Upload { return FALSE; } - $this->upload_path = preg_replace("/(.+?)\/*$/", "\\1/", $this->upload_path); + $this->upload_path = preg_replace("/(.+?)\/*$/", "\\1/", $this->upload_path); return TRUE; } @@ -834,7 +834,7 @@ class CI_Upload { $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 + // 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, '.', ''); @@ -844,8 +844,8 @@ class CI_Upload { // If the file being uploaded is an image, then we should have no problem with XSS attacks (in theory), but // 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 + // 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 // attempted XSS attack. @@ -933,7 +933,7 @@ class CI_Upload { /** * List of Mime Types * - * This is a list of mime types. We use it to validate + * This is a list of mime types. We use it to validate * the "allowed types" set by the developer * * @param string diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 543d1d5a3..016102a2a 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -1,4 +1,4 @@ -xmlrpcerr['unknown_method'] = '1'; $this->xmlrpcstr['unknown_method'] = 'This is not a known method for this XML-RPC Server'; $this->xmlrpcerr['invalid_return'] = '2'; - $this->xmlrpcstr['invalid_return'] = 'The XML data received was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.'; + $this->xmlrpcstr['invalid_return'] = 'The XML data received was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.'; $this->xmlrpcerr['incorrect_params'] = '3'; $this->xmlrpcstr['incorrect_params'] = 'Incorrect parameters were passed to method'; $this->xmlrpcerr['introspect_unknown'] = '4'; @@ -129,7 +129,7 @@ class CI_Xmlrpc { //------------------------------------- - // Initialize Prefs + // Initialize Prefs //------------------------------------- function initialize($config = array()) @@ -148,7 +148,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Take URL and parse it + // Take URL and parse it //------------------------------------- function server($url, $port=80) @@ -172,7 +172,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Set Timeout + // Set Timeout //------------------------------------- function timeout($seconds=5) @@ -185,7 +185,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Set Methods + // Set Methods //------------------------------------- function method($function) @@ -195,7 +195,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Take Array of Data and Create Objects + // Take Array of Data and Create Objects //------------------------------------- function request($incoming) @@ -216,7 +216,7 @@ class CI_Xmlrpc { //------------------------------------- - // Set Debug + // Set Debug //------------------------------------- function set_debug($flag = TRUE) @@ -225,7 +225,7 @@ class CI_Xmlrpc { } //------------------------------------- - // Values Parsing + // Values Parsing //------------------------------------- function values_parsing($value, $return = FALSE) @@ -268,7 +268,7 @@ class CI_Xmlrpc { //------------------------------------- - // Sends XML-RPC Request + // Sends XML-RPC Request //------------------------------------- function send_request() @@ -294,7 +294,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Returns Error + // Returns Error //------------------------------------- function display_error() @@ -304,7 +304,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Returns Remote Server Response + // Returns Remote Server Response //------------------------------------- function display_response() @@ -314,7 +314,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Sends an Error Message for Server Request + // Sends an Error Message for Server Request //------------------------------------- function send_error_message($number, $message) @@ -325,7 +325,7 @@ class CI_Xmlrpc { //------------------------------------- - // Send Response for Server Request + // Send Response for Server Request //------------------------------------- function send_response($response) @@ -399,7 +399,7 @@ class XML_RPC_Client extends CI_Xmlrpc } $r = "\r\n"; - $op = "POST {$this->path} HTTP/1.0$r"; + $op = "POST {$this->path} HTTP/1.0$r"; $op .= "Host: {$this->server}$r"; $op .= "Content-Type: text/xml$r"; $op .= "User-Agent: {$this->xmlrpcName}$r"; @@ -447,7 +447,7 @@ class XML_RPC_Response else if ( ! is_object($val)) { // programmer error, not an object - error_log("Invalid type '" . gettype($val) . "' (value: $val) passed to XML_RPC_Response. Defaulting to empty value."); + error_log("Invalid type '" . gettype($val) . "' (value: $val) passed to XML_RPC_Response. Defaulting to empty value."); $this->val = new XML_RPC_Values(); } else @@ -504,7 +504,7 @@ class XML_RPC_Response function decode($array=FALSE) { $CI =& get_instance(); - + if ($array !== FALSE && is_array($array)) { while (list($key) = each($array)) @@ -541,7 +541,7 @@ class XML_RPC_Response //------------------------------------- - // XML-RPC Object to PHP Types + // XML-RPC Object to PHP Types //------------------------------------- function xmlrpc_decoder($xmlrpc_val) @@ -581,7 +581,7 @@ class XML_RPC_Response //------------------------------------- - // ISO-8601 time to server or UTC time + // ISO-8601 time to server or UTC time //------------------------------------- function iso8601_decode($time, $utc=0) @@ -630,7 +630,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // Create Payload to Send + // Create Payload to Send //------------------------------------- function createPayload() @@ -650,7 +650,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // Parse External XML-RPC Server's Response + // Parse External XML-RPC Server's Response //------------------------------------- function parseResponse($fp) @@ -663,7 +663,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // DISPLAY HTTP CONTENT for DEBUGGING + // DISPLAY HTTP CONTENT for DEBUGGING //------------------------------------- if ($this->debug === TRUE) @@ -674,7 +674,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // Check for data + // Check for data //------------------------------------- if ($data == "") @@ -686,7 +686,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- - // Check for HTTP 200 Response + // Check for HTTP 200 Response //------------------------------------- if (strncmp($data, 'HTTP', 4) == 0 && ! preg_match('/^HTTP\/[0-9\.]+ 200 /', $data)) @@ -697,7 +697,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // Create and Set Up XML Parser + // Create and Set Up XML Parser //------------------------------------- $parser = xml_parser_create($this->xmlrpc_defencoding); @@ -718,7 +718,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- - // GET HEADERS + // GET HEADERS //------------------------------------- $lines = explode("\r\n", $data); @@ -734,7 +734,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- - // PARSE XML DATA + // PARSE XML DATA //------------------------------------- if ( ! xml_parse($parser, $data, count($data))) @@ -750,7 +750,7 @@ class XML_RPC_Message extends CI_Xmlrpc xml_parser_free($parser); // --------------------------------------- - // Got Ourselves Some Badness, It Seems + // Got Ourselves Some Badness, It Seems // --------------------------------------- if ($this->xh[$parser]['isf'] > 1) @@ -772,7 +772,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // DISPLAY XML CONTENT for DEBUGGING + // DISPLAY XML CONTENT for DEBUGGING //------------------------------------- if ($this->debug === TRUE) @@ -797,7 +797,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // SEND RESPONSE + // SEND RESPONSE //------------------------------------- $v = $this->xh[$parser]['value']; @@ -826,21 +826,21 @@ class XML_RPC_Message extends CI_Xmlrpc } // ------------------------------------ - // Begin Return Message Parsing section + // Begin Return Message Parsing section // ------------------------------------ // quick explanation of components: - // ac - used to accumulate values - // isf - used to indicate a fault - // lv - used to indicate "looking for a value": implements + // ac - used to accumulate values + // isf - used to indicate a fault + // lv - used to indicate "looking for a value": implements // the logic to allow values with no types to be strings - // params - used to store parameters in method calls - // method - used to store method name + // params - used to store parameters in method calls + // method - used to store method name // stack - array with parent tree of the xml element, // used to validate the nesting of elements //------------------------------------- - // Start Element Handler + // Start Element Handler //------------------------------------- function open_tag($the_parser, $name, $attrs) @@ -942,7 +942,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- - // End Element Handler + // End Element Handler //------------------------------------- function closing_tag($the_parser, $name) @@ -951,7 +951,7 @@ class XML_RPC_Message extends CI_Xmlrpc // 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 + // 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']); @@ -1080,13 +1080,13 @@ class XML_RPC_Message extends CI_Xmlrpc // We're all good kids with nuthin' to do break; default: - // End of an Invalid Element. Taken care of during the opening tag though + // End of an Invalid Element. Taken care of during the opening tag though break; } } //------------------------------------- - // Parses Character Data + // Parses Character Data //------------------------------------- function character_data($the_parser, $data) @@ -1116,7 +1116,7 @@ class XML_RPC_Message extends CI_Xmlrpc function output_parameters($array=FALSE) { $CI =& get_instance(); - + if ($array !== FALSE && is_array($array)) { while (list($key) = each($array)) diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 88af60693..9cd332147 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -1,4 +1,4 @@ -parseRequest(); - $payload = 'xmlrpc_defencoding.'"?'.'>'."\n"; + $payload = 'xmlrpc_defencoding.'"?'.'>'."\n"; $payload .= $this->debug_msg; $payload .= $r->prepare_response(); @@ -156,7 +156,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc function add_to_map($methodname, $function, $sig, $doc) { $this->methods[$methodname] = array( - 'function' => $function, + 'function' => $function, 'signature' => $sig, 'docstring' => $doc ); @@ -176,7 +176,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc global $HTTP_RAW_POST_DATA; //------------------------------------- - // Get Data + // Get Data //------------------------------------- if ($data == '') @@ -185,7 +185,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } //------------------------------------- - // Set up XML Parser + // Set up XML Parser //------------------------------------- $parser = xml_parser_create($this->xmlrpc_defencoding); @@ -207,7 +207,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- - // PARSE + PROCESS XML DATA + // PARSE + PROCESS XML DATA //------------------------------------- if ( ! xml_parse($parser, $data, 1)) @@ -235,7 +235,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc { if ($this->debug === TRUE) { - $plist .= "$i - " . print_r(get_object_vars($parser_object->xh[$parser]['params'][$i]), TRUE). ";\n"; + $plist .= "$i - " . print_r(get_object_vars($parser_object->xh[$parser]['params'][$i]), TRUE). ";\n"; } $m->addParam($parser_object->xh[$parser]['params'][$i]); @@ -252,7 +252,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } //------------------------------------- - // SET DEBUGGING MESSAGE + // SET DEBUGGING MESSAGE //------------------------------------- if ($this->debug === TRUE) @@ -285,7 +285,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } //------------------------------------- - // Valid Method + // Valid Method //------------------------------------- if ( ! isset($this->methods[$methName]['function'])) @@ -294,7 +294,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } //------------------------------------- - // Check for Method (and Object) + // Check for Method (and Object) //------------------------------------- $method_parts = explode(".", $this->methods[$methName]['function']); @@ -320,7 +320,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } //------------------------------------- - // Checking Methods Signature + // Checking Methods Signature //------------------------------------- if (isset($this->methods[$methName]['signature'])) @@ -353,7 +353,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } //------------------------------------- - // Calls the Function + // Calls the Function //------------------------------------- if ($objectCall === TRUE) @@ -381,11 +381,11 @@ class CI_Xmlrpcs extends CI_Xmlrpc return call_user_func($this->methods[$methName]['function'], $m); } } - + // -------------------------------------------------------------------- /** - * Server Function: List Methods + * Server Function: List Methods * * @access public * @param mixed @@ -409,11 +409,11 @@ class CI_Xmlrpcs extends CI_Xmlrpc $v->addArray($output); return new XML_RPC_Response($v); } - + // -------------------------------------------------------------------- /** - * Server Function: Return Signature for Method + * Server Function: Return Signature for Method * * @access public * @param mixed @@ -458,7 +458,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc // -------------------------------------------------------------------- /** - * Server Function: Doc String for Method + * Server Function: Doc String for Method * * @access public * @param mixed @@ -480,11 +480,11 @@ class CI_Xmlrpcs extends CI_Xmlrpc return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); } } - + // -------------------------------------------------------------------- /** - * Server Function: Multi-call + * Server Function: Multi-call * * @access public * @param mixed @@ -528,7 +528,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc // -------------------------------------------------------------------- /** - * Multi-call Function: Error Handling + * Multi-call Function: Error Handling * * @access public * @param mixed @@ -536,7 +536,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc */ function multicall_error($err) { - $str = is_string($err) ? $this->xmlrpcstr["multicall_${err}"] : $err->faultString(); + $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'); @@ -548,7 +548,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc // -------------------------------------------------------------------- /** - * Multi-call Function: Processes method + * Multi-call Function: Processes method * * @access public * @param mixed diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 1ae3e7f25..666327d5c 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -1,4 +1,4 @@ -CI =& get_instance(); + $this->CI =& get_instance(); extract($params); if ($autoload === TRUE) { - $this->script(); + $this->script(); } - + log_message('debug', "Jquery Class Initialized"); } - - // -------------------------------------------------------------------- + + // -------------------------------------------------------------------- // Event Code - // -------------------------------------------------------------------- + // -------------------------------------------------------------------- /** * Blur @@ -65,9 +65,9 @@ class CI_Jquery extends CI_Javascript { { return $this->_add_event($element, $js, 'blur'); } - + // -------------------------------------------------------------------- - + /** * Change * @@ -82,9 +82,9 @@ class CI_Jquery extends CI_Javascript { { return $this->_add_event($element, $js, 'change'); } - + // -------------------------------------------------------------------- - + /** * Click * @@ -112,7 +112,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Double Click * @@ -129,7 +129,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Error * @@ -146,7 +146,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Focus * @@ -163,7 +163,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Hover * @@ -185,7 +185,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Keydown * @@ -202,7 +202,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Keyup * @@ -216,10 +216,10 @@ class CI_Jquery extends CI_Javascript { function _keyup($element = 'this', $js = '') { return $this->_add_event($element, $js, 'keyup'); - } + } // -------------------------------------------------------------------- - + /** * Load * @@ -233,10 +233,10 @@ class CI_Jquery extends CI_Javascript { function _load($element = 'this', $js = '') { return $this->_add_event($element, $js, 'load'); - } - + } + // -------------------------------------------------------------------- - + /** * Mousedown * @@ -253,7 +253,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Mouse Out * @@ -270,7 +270,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Mouse Over * @@ -321,7 +321,7 @@ class CI_Jquery extends CI_Javascript { { $array_js = array($array_js); } - + foreach ($array_js as $js) { $this->jquery_code_for_compile[] = "\t$js\n"; @@ -361,7 +361,7 @@ class CI_Jquery extends CI_Javascript { { return $this->_add_event($element, $js, 'scroll'); } - + // -------------------------------------------------------------------- /** @@ -379,10 +379,10 @@ class CI_Jquery extends CI_Javascript { return $this->_add_event($element, $js, 'unload'); } - // -------------------------------------------------------------------- + // -------------------------------------------------------------------- // Effects - // -------------------------------------------------------------------- - + // -------------------------------------------------------------------- + /** * Add Class * @@ -395,7 +395,7 @@ class CI_Jquery extends CI_Javascript { function _addClass($element = 'this', $class='') { $element = $this->_prep_element($element); - $str = "$({$element}).addClass(\"$class\");"; + $str = "$({$element}).addClass(\"$class\");"; return $str; } @@ -416,9 +416,9 @@ class CI_Jquery extends CI_Javascript { { $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + $animations = "\t\t\t"; - + foreach ($params as $param=>$value) { $animations .= $param.': \''.$value.'\', '; @@ -430,19 +430,19 @@ class CI_Jquery extends CI_Javascript { { $speed = ', '.$speed; } - + if ($extra != '') { $extra = ', '.$extra; } - - $str = "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");"; - + + $str = "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");"; + return $str; } // -------------------------------------------------------------------- - + /** * Fade In * @@ -456,21 +456,21 @@ class CI_Jquery extends CI_Javascript { */ function _fadeIn($element = 'this', $speed = '', $callback = '') { - $element = $this->_prep_element($element); + $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).fadeIn({$speed}{$callback});"; - + + $str = "$({$element}).fadeIn({$speed}{$callback});"; + return $str; } - + // -------------------------------------------------------------------- - + /** * Fade Out * @@ -486,14 +486,14 @@ class CI_Jquery extends CI_Javascript { { $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).fadeOut({$speed}{$callback});"; - + + $str = "$({$element}).fadeOut({$speed}{$callback});"; + return $str; } @@ -512,19 +512,19 @@ class CI_Jquery extends CI_Javascript { */ function _hide($element = 'this', $speed = '', $callback = '') { - $element = $this->_prep_element($element); + $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).hide({$speed}{$callback});"; + + $str = "$({$element}).hide({$speed}{$callback});"; return $str; } - + // -------------------------------------------------------------------- /** @@ -539,12 +539,12 @@ class CI_Jquery extends CI_Javascript { function _removeClass($element = 'this', $class='') { $element = $this->_prep_element($element); - $str = "$({$element}).removeClass(\"$class\");"; + $str = "$({$element}).removeClass(\"$class\");"; return $str; } // -------------------------------------------------------------------- - + /** * Slide Up * @@ -558,21 +558,21 @@ class CI_Jquery extends CI_Javascript { */ function _slideUp($element = 'this', $speed = '', $callback = '') { - $element = $this->_prep_element($element); + $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).slideUp({$speed}{$callback});"; - + + $str = "$({$element}).slideUp({$speed}{$callback});"; + return $str; } - + // -------------------------------------------------------------------- - + /** * Slide Down * @@ -588,19 +588,19 @@ class CI_Jquery extends CI_Javascript { { $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).slideDown({$speed}{$callback});"; - + + $str = "$({$element}).slideDown({$speed}{$callback});"; + return $str; } // -------------------------------------------------------------------- - + /** * Slide Toggle * @@ -616,19 +616,19 @@ class CI_Jquery extends CI_Javascript { { $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).slideToggle({$speed}{$callback});"; - + + $str = "$({$element}).slideToggle({$speed}{$callback});"; + return $str; } - + // -------------------------------------------------------------------- - + /** * Toggle * @@ -641,12 +641,12 @@ class CI_Jquery extends CI_Javascript { function _toggle($element = 'this') { $element = $this->_prep_element($element); - $str = "$({$element}).toggle();"; + $str = "$({$element}).toggle();"; return $str; } - + // -------------------------------------------------------------------- - + /** * Toggle Class * @@ -659,12 +659,12 @@ class CI_Jquery extends CI_Javascript { function _toggleClass($element = 'this', $class='') { $element = $this->_prep_element($element); - $str = "$({$element}).toggleClass(\"$class\");"; + $str = "$({$element}).toggleClass(\"$class\");"; return $str; } - + // -------------------------------------------------------------------- - + /** * Show * @@ -678,16 +678,16 @@ class CI_Jquery extends CI_Javascript { */ function _show($element = 'this', $speed = '', $callback = '') { - $element = $this->_prep_element($element); + $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).show({$speed}{$callback});"; - + + $str = "$({$element}).show({$speed}{$callback});"; + return $str; } @@ -696,7 +696,7 @@ class CI_Jquery extends CI_Javascript { /** * Updater * - * An Ajax call that populates the designated DOM node with + * An Ajax call that populates the designated DOM node with * returned content * * @access private @@ -705,13 +705,13 @@ class CI_Jquery extends CI_Javascript { * @param string optional parameters * @return string */ - + function _updater($container = 'this', $controller, $options = '') - { + { $container = $this->_prep_element($container); - + $controller = (strpos('://', $controller) === FALSE) ? $controller : $this->CI->config->site_url($controller); - + // ajaxStart and ajaxStop are better choices here... but this is a stop gap if ($this->CI->config->item('javascript_ajax_img') == '') { @@ -721,7 +721,7 @@ class CI_Jquery extends CI_Javascript { { $loading_notifier = 'CI->config->slash_item('base_url') . $this->CI->config->item('javascript_ajax_img') . '\' alt=\'Loading\' />'; } - + $updater = "$($container).empty();\n"; // anything that was in... get it out $updater .= "\t\t$($container).prepend(\"$loading_notifier\");\n"; // to replace with an image @@ -741,7 +741,7 @@ class CI_Jquery extends CI_Javascript { // -------------------------------------------------------------------- // Pre-written handy stuff // -------------------------------------------------------------------- - + /** * Zebra tables * @@ -753,8 +753,8 @@ class CI_Jquery extends CI_Javascript { function _zebraTables($class = '', $odd = 'odd', $hover = '') { $class = ($class != '') ? '.'.$class : ''; - - $zebra = "\t\$(\"table{$class} tbody tr:nth-child(even)\").addClass(\"{$odd}\");"; + + $zebra = "\t\$(\"table{$class} tbody tr:nth-child(even)\").addClass(\"{$odd}\");"; $this->jquery_code_for_compile[] = $zebra; @@ -771,7 +771,7 @@ class CI_Jquery extends CI_Javascript { // -------------------------------------------------------------------- // Plugins // -------------------------------------------------------------------- - + /** * Corner Plugin * @@ -793,7 +793,7 @@ class CI_Jquery extends CI_Javascript { return "$(" . $this->_prep_element($element) . ").corner(".$corner_style.");"; } - + // -------------------------------------------------------------------- /** @@ -805,7 +805,7 @@ class CI_Jquery extends CI_Javascript { * @return void */ function modal($src, $relative = FALSE) - { + { $this->jquery_code_for_load[] = $this->external($src, $relative); } @@ -897,7 +897,7 @@ class CI_Jquery extends CI_Javascript { { $this->jquery_code_for_compile[] = "\t$(" . $this->_prep_element($table) . ").tablesorter($options);\n"; } - + // -------------------------------------------------------------------- // Class functions // -------------------------------------------------------------------- @@ -912,7 +912,7 @@ class CI_Jquery extends CI_Javascript { * @param string The code to execute * @param string The event to pass * @return string - */ + */ function _add_event($element, $js, $event) { if (is_array($js)) @@ -953,15 +953,15 @@ class CI_Jquery extends CI_Javascript { $script = '$(document).ready(function() {' . "\n"; $script .= implode('', $this->jquery_code_for_compile); $script .= '});'; - + $output = ($script_tags === FALSE) ? $script : $this->inline($script); $this->CI->load->vars(array($view_var => $output)); } - + // -------------------------------------------------------------------- - + /** * Clear Compile * @@ -976,7 +976,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Document Ready * @@ -992,7 +992,7 @@ class CI_Jquery extends CI_Javascript { $js = array ($js); } - + foreach ($js as $script) { $this->jquery_code_for_compile[] = $script; @@ -1016,7 +1016,7 @@ class CI_Jquery extends CI_Javascript { $this->jquery_code_for_load[] = $library_src; return $library_src; } - + // -------------------------------------------------------------------- /** @@ -1036,10 +1036,10 @@ class CI_Jquery extends CI_Javascript { { $element = '"'.$element.'"'; } - + return $element; } - + // -------------------------------------------------------------------- /** @@ -1050,7 +1050,7 @@ class CI_Jquery extends CI_Javascript { * @access private * @param string * @return string - */ + */ function _validate_speed($speed) { if (in_array($speed, array('slow', 'normal', 'fast'))) @@ -1061,7 +1061,7 @@ class CI_Jquery extends CI_Javascript { { $speed = ''; } - + return $speed; } -- cgit v1.2.3-24-g4f1b From 72038ba6fd2e8196623bf1bd1a38756ad41ce905 Mon Sep 17 00:00:00 2001 From: MarcosCoelho Date: Mon, 18 Jul 2011 16:12:47 -0300 Subject: sync total items count and total amount price; by sum of quantity of each item in cart --- system/libraries/Cart.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 7f65b48b9..b2eaa9ad7 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -374,6 +374,7 @@ class CI_Cart { // Lets add up the individual prices and set the cart sub-total $total = 0; + $items = 0; foreach ($this->_cart_contents as $key => $val) { // We make sure the array contains the proper indexes @@ -383,13 +384,14 @@ class CI_Cart { } $total += ($val['price'] * $val['qty']); + $items += $val['qty']; // Set the subtotal $this->_cart_contents[$key]['subtotal'] = ($this->_cart_contents[$key]['price'] * $this->_cart_contents[$key]['qty']); } // Set the cart total and total items. - $this->_cart_contents['total_items'] = count($this->_cart_contents); + $this->_cart_contents['total_items'] = $items; $this->_cart_contents['cart_total'] = $total; // Is our cart empty? If so we delete it from the session -- cgit v1.2.3-24-g4f1b From 9d887b32a1fe998cbb0307a5e678ac3ba5076a1e Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 10 Aug 2011 08:06:37 -0600 Subject: Fixed conflicts in changelog. --- system/libraries/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index cd89f8f3d..03eccea09 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -395,7 +395,7 @@ class CI_Email { public function attach($filename, $disposition = 'attachment') { $this->_attach_name[] = $filename; - $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename)))); + $this->_attach_type[] = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)); $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters return $this; } -- cgit v1.2.3-24-g4f1b