Archived
1
0

Update to CodeIgniter 3.19

This commit is contained in:
Marcel
2018-12-29 16:16:49 +01:00
parent b036b4d36e
commit d09ee2788d
159 changed files with 2508 additions and 1910 deletions

View File

@@ -6,7 +6,7 @@
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014 - 2016, British Columbia Institute of Technology
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -29,7 +29,7 @@
* @package CodeIgniter
* @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
* @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/)
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
* @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 1.0.0
@@ -493,6 +493,63 @@ class CI_Form_validation {
// --------------------------------------------------------------------
/**
* Prepare rules
*
* Re-orders the provided rules in order of importance, so that
* they can easily be executed later without weird checks ...
*
* "Callbacks" are given the highest priority (always called),
* followed by 'required' (called if callbacks didn't fail),
* and then every next rule depends on the previous one passing.
*
* @param array $rules
* @return array
*/
protected function _prepare_rules($rules)
{
$new_rules = array();
$callbacks = array();
foreach ($rules as &$rule)
{
// Let 'required' always be the first (non-callback) rule
if ($rule === 'required')
{
array_unshift($new_rules, 'required');
}
// 'isset' is a kind of a weird alias for 'required' ...
elseif ($rule === 'isset' && (empty($new_rules) OR $new_rules[0] !== 'required'))
{
array_unshift($new_rules, 'isset');
}
// The old/classic 'callback_'-prefixed rules
elseif (is_string($rule) && strncmp('callback_', $rule, 9) === 0)
{
$callbacks[] = $rule;
}
// Proper callables
elseif (is_callable($rule))
{
$callbacks[] = $rule;
}
// "Named" callables; i.e. array('name' => $callable)
elseif (is_array($rule) && isset($rule[0], $rule[1]) && is_callable($rule[1]))
{
$callbacks[] = $rule;
}
// Everything else goes at the end of the queue
else
{
$new_rules[] = $rule;
}
}
return array_merge($callbacks, $new_rules);
}
// --------------------------------------------------------------------
/**
* Traverse a multidimensional $_POST array index until the data is found
*
@@ -580,70 +637,7 @@ class CI_Form_validation {
return;
}
// If the field is blank, but NOT required, no further tests are necessary
$callback = FALSE;
if ( ! in_array('required', $rules) && ($postdata === NULL OR $postdata === ''))
{
// Before we bail out, does the rule contain a callback?
foreach ($rules as &$rule)
{
if (is_string($rule))
{
if (strncmp($rule, 'callback_', 9) === 0)
{
$callback = TRUE;
$rules = array(1 => $rule);
break;
}
}
elseif (is_callable($rule))
{
$callback = TRUE;
$rules = array(1 => $rule);
break;
}
elseif (is_array($rule) && isset($rule[0], $rule[1]) && is_callable($rule[1]))
{
$callback = TRUE;
$rules = array(array($rule[0], $rule[1]));
break;
}
}
if ( ! $callback)
{
return;
}
}
// Isset Test. Typically this rule will only apply to checkboxes.
if (($postdata === NULL OR $postdata === '') && ! $callback)
{
if (in_array('isset', $rules, TRUE) OR in_array('required', $rules))
{
// Set the message type
$type = in_array('required', $rules) ? 'required' : 'isset';
$line = $this->_get_error_message($type, $row['field']);
// Build the error message
$message = $this->_build_error_msg($line, $this->_translate_fieldname($row['label']));
// Save the error message
$this->_field_data[$row['field']]['error'] = $message;
if ( ! isset($this->_error_array[$row['field']]))
{
$this->_error_array[$row['field']] = $message;
}
}
return;
}
// --------------------------------------------------------------------
// Cycle through each rule and run it
$rules = $this->_prepare_rules($rules);
foreach ($rules as $rule)
{
$_in_array = FALSE;
@@ -702,6 +696,17 @@ class CI_Form_validation {
$param = $match[2];
}
// Ignore empty, non-required inputs with a few exceptions ...
if (
($postdata === NULL OR $postdata === '')
&& $callback === FALSE
&& $callable === FALSE
&& ! in_array($rule, array('required', 'isset', 'matches'), TRUE)
)
{
continue;
}
// Call the function that corresponds to the rule
if ($callback OR $callable !== FALSE)
{
@@ -740,12 +745,6 @@ class CI_Form_validation {
{
$this->_field_data[$row['field']]['postdata'] = is_bool($result) ? $postdata : $result;
}
// If the field isn't required and we just processed a callback we'll move on...
if ( ! in_array('required', $rules, TRUE) && $result !== FALSE)
{
continue;
}
}
elseif ( ! method_exists($this, $rule))
{
@@ -1055,7 +1054,9 @@ class CI_Form_validation {
*/
public function required($str)
{
return is_array($str) ? (bool) count($str) : (trim($str) !== '');
return is_array($str)
? (empty($str) === FALSE)
: (trim($str) !== '');
}
// --------------------------------------------------------------------
@@ -1199,7 +1200,7 @@ class CI_Form_validation {
{
return FALSE;
}
elseif ( ! in_array($matches[1], array('http', 'https'), TRUE))
elseif ( ! in_array(strtolower($matches[1]), array('http', 'https'), TRUE))
{
return FALSE;
}
@@ -1215,18 +1216,7 @@ class CI_Form_validation {
$str = 'ipv6.host'.substr($str, strlen($matches[1]) + 2);
}
$str = 'http://'.$str;
// There's a bug affecting PHP 5.2.13, 5.3.2 that considers the
// underscore to be a valid hostname character instead of a dash.
// Reference: https://bugs.php.net/bug.php?id=51192
if (version_compare(PHP_VERSION, '5.2.13', '==') OR version_compare(PHP_VERSION, '5.3.2', '=='))
{
sscanf($str, 'http://%[^/]', $host);
$str = substr_replace($str, strtr($host, array('_' => '-', '-' => '_')), 7, strlen($host));
}
return (filter_var($str, FILTER_VALIDATE_URL) !== FALSE);
return (filter_var('http://'.$str, FILTER_VALIDATE_URL) !== FALSE);
}
// --------------------------------------------------------------------
@@ -1239,9 +1229,16 @@ class CI_Form_validation {
*/
public function valid_email($str)
{
if (function_exists('idn_to_ascii') && $atpos = strpos($str, '@'))
if (function_exists('idn_to_ascii') && preg_match('#\A([^@]+)@(.+)\z#', $str, $matches))
{
$str = substr($str, 0, ++$atpos).idn_to_ascii(substr($str, $atpos));
$domain = defined('INTL_IDNA_VARIANT_UTS46')
? idn_to_ascii($matches[2], 0, INTL_IDNA_VARIANT_UTS46)
: idn_to_ascii($matches[2]);
if ($domain !== FALSE)
{
$str = $matches[1].'@'.$domain;
}
}
return (bool) filter_var($str, FILTER_VALIDATE_EMAIL);