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} | ',
+ 'heading_next_cell' => '>> | ',
+ 'heading_row_end' => '
',
+ 'week_row_start' => '',
+ 'week_day_cell' => '{week_day} | ',
+ 'week_row_end' => '
',
+ 'cal_row_start' => '',
+ 'cal_cell_start' => '',
+ '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' => ' | ',
+ 'cal_cell_end_today' => '',
+ 'cal_row_end' => '
',
+ 'table_close' => '
'
+ );
+ }
+ // 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", "\\1;", $str);
+ $str = preg_replace("/%([a-z0-9]{2})/i", "\\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:
';
+ 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) . "{$typ}>\n";
+ break;
+ case $this->xmlrpcBoolean:
+ $rs .= "<{$typ}>" . ($val ? '1' : '0') . "{$typ}>\n";
+ break;
+ case $this->xmlrpcString:
+ $rs .= "<{$typ}>" . htmlspecialchars($val). "{$typ}>\n";
+ break;
+ default:
+ $rs .= "<{$typ}>{$val}{$typ}>\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