Kohana v3.3.2

This commit is contained in:
Deon George
2014-09-06 23:43:07 +10:00
parent f96694b18f
commit 8888719653
236 changed files with 1685 additions and 996 deletions

View File

@@ -8,8 +8,6 @@
* - PCRE needs to be compiled with UTF-8 support (--enable-utf8)
* - Support for [Unicode properties](http://php.net/manual/reference.pcre.pattern.modifiers.php)
* is highly recommended (--enable-unicode-properties)
* - UTF-8 conversion will be much more reliable if the
* [iconv extension](http://php.net/iconv) is loaded
* - The [mbstring extension](http://php.net/mbstring) is highly recommended,
* but must not be overloading string functions
*
@@ -42,11 +40,10 @@ class Kohana_UTF8 {
*
* UTF8::clean($_GET); // Clean GET data
*
* [!!] This method requires [Iconv](http://php.net/iconv)
*
* @param mixed $var variable to clean
* @param string $charset character set, defaults to Kohana::$charset
* @return mixed
* @uses UTF8::clean
* @uses UTF8::strip_ascii_ctrl
* @uses UTF8::is_ascii
*/
@@ -63,21 +60,20 @@ class Kohana_UTF8 {
foreach ($var as $key => $val)
{
// Recursion!
$var[self::clean($key)] = self::clean($val);
$var[UTF8::clean($key)] = UTF8::clean($val);
}
}
elseif (is_string($var) AND $var !== '')
{
// Remove control characters
$var = self::strip_ascii_ctrl($var);
$var = UTF8::strip_ascii_ctrl($var);
if ( ! self::is_ascii($var))
if ( ! UTF8::is_ascii($var))
{
// Disable notices
$error_reporting = error_reporting(~E_NOTICE);
// iconv is expensive, so it is only used when needed
$var = iconv($charset, $charset.'//IGNORE', $var);
$var = mb_convert_encoding($var, $charset, $charset);
// Turn notices back on
error_reporting($error_reporting);
@@ -144,12 +140,12 @@ class Kohana_UTF8 {
*/
public static function transliterate_to_ascii($str, $case = 0)
{
if ( ! isset(self::$called[__FUNCTION__]))
if ( ! isset(UTF8::$called[__FUNCTION__]))
{
require Kohana::find_file('utf8', __FUNCTION__);
// Function has been called
self::$called[__FUNCTION__] = TRUE;
UTF8::$called[__FUNCTION__] = TRUE;
}
return _transliterate_to_ascii($str, $case);
@@ -164,18 +160,19 @@ class Kohana_UTF8 {
* @param string $str string being measured for length
* @return integer
* @uses UTF8::$server_utf8
* @uses Kohana::$charset
*/
public static function strlen($str)
{
if (UTF8::$server_utf8)
return mb_strlen($str, Kohana::$charset);
if ( ! isset(self::$called[__FUNCTION__]))
if ( ! isset(UTF8::$called[__FUNCTION__]))
{
require Kohana::find_file('utf8', __FUNCTION__);
// Function has been called
self::$called[__FUNCTION__] = TRUE;
UTF8::$called[__FUNCTION__] = TRUE;
}
return _strlen($str);
@@ -194,18 +191,19 @@ class Kohana_UTF8 {
* @return integer position of needle
* @return boolean FALSE if the needle is not found
* @uses UTF8::$server_utf8
* @uses Kohana::$charset
*/
public static function strpos($str, $search, $offset = 0)
{
if (UTF8::$server_utf8)
return mb_strpos($str, $search, $offset, Kohana::$charset);
if ( ! isset(self::$called[__FUNCTION__]))
if ( ! isset(UTF8::$called[__FUNCTION__]))
{
require Kohana::find_file('utf8', __FUNCTION__);
// Function has been called
self::$called[__FUNCTION__] = TRUE;
UTF8::$called[__FUNCTION__] = TRUE;
}
return _strpos($str, $search, $offset);
@@ -230,12 +228,12 @@ class Kohana_UTF8 {
if (UTF8::$server_utf8)
return mb_strrpos($str, $search, $offset, Kohana::$charset);
if ( ! isset(self::$called[__FUNCTION__]))
if ( ! isset(UTF8::$called[__FUNCTION__]))
{
require Kohana::find_file('utf8', __FUNCTION__);
// Function has been called
self::$called[__FUNCTION__] = TRUE;
UTF8::$called[__FUNCTION__] = TRUE;
}
return _strrpos($str, $search, $offset);
@@ -262,12 +260,12 @@ class Kohana_UTF8 {
? mb_substr($str, $offset, mb_strlen($str), Kohana::$charset)
: mb_substr($str, $offset, $length, Kohana::$charset);
if ( ! isset(self::$called[__FUNCTION__]))
if ( ! isset(UTF8::$called[__FUNCTION__]))
{
require Kohana::find_file('utf8', __FUNCTION__);
// Function has been called
self::$called[__FUNCTION__] = TRUE;
UTF8::$called[__FUNCTION__] = TRUE;
}
return _substr($str, $offset, $length);
@@ -287,12 +285,12 @@ class Kohana_UTF8 {
*/
public static function substr_replace($str, $replacement, $offset, $length = NULL)
{
if ( ! isset(self::$called[__FUNCTION__]))
if ( ! isset(UTF8::$called[__FUNCTION__]))
{
require Kohana::find_file('utf8', __FUNCTION__);
// Function has been called
self::$called[__FUNCTION__] = TRUE;
UTF8::$called[__FUNCTION__] = TRUE;
}
return _substr_replace($str, $replacement, $offset, $length);
@@ -305,21 +303,22 @@ class Kohana_UTF8 {
* $str = UTF8::strtolower($str);
*
* @author Andreas Gohr <andi@splitbrain.org>
* @param string $str mixed case string
* @param string $str mixed case string
* @return string
* @uses UTF8::$server_utf8
* @uses Kohana::$charset
*/
public static function strtolower($str)
{
if (UTF8::$server_utf8)
return mb_strtolower($str, Kohana::$charset);
if ( ! isset(self::$called[__FUNCTION__]))
if ( ! isset(UTF8::$called[__FUNCTION__]))
{
require Kohana::find_file('utf8', __FUNCTION__);
// Function has been called
self::$called[__FUNCTION__] = TRUE;
UTF8::$called[__FUNCTION__] = TRUE;
}
return _strtolower($str);
@@ -330,7 +329,7 @@ class Kohana_UTF8 {
* of [strtoupper](http://php.net/strtoupper).
*
* @author Andreas Gohr <andi@splitbrain.org>
* @param string $str mixed case string
* @param string $str mixed case string
* @return string
* @uses UTF8::$server_utf8
* @uses Kohana::$charset
@@ -340,12 +339,12 @@ class Kohana_UTF8 {
if (UTF8::$server_utf8)
return mb_strtoupper($str, Kohana::$charset);
if ( ! isset(self::$called[__FUNCTION__]))
if ( ! isset(UTF8::$called[__FUNCTION__]))
{
require Kohana::find_file('utf8', __FUNCTION__);
// Function has been called
self::$called[__FUNCTION__] = TRUE;
UTF8::$called[__FUNCTION__] = TRUE;
}
return _strtoupper($str);
@@ -358,17 +357,17 @@ class Kohana_UTF8 {
* $str = UTF8::ucfirst($str);
*
* @author Harry Fuecks <hfuecks@gmail.com>
* @param string $str mixed case string
* @param string $str mixed case string
* @return string
*/
public static function ucfirst($str)
{
if ( ! isset(self::$called[__FUNCTION__]))
if ( ! isset(UTF8::$called[__FUNCTION__]))
{
require Kohana::find_file('utf8', __FUNCTION__);
// Function has been called
self::$called[__FUNCTION__] = TRUE;
UTF8::$called[__FUNCTION__] = TRUE;
}
return _ucfirst($str);
@@ -381,18 +380,17 @@ class Kohana_UTF8 {
* $str = UTF8::ucwords($str);
*
* @author Harry Fuecks <hfuecks@gmail.com>
* @param string $str mixed case string
* @param string $str mixed case string
* @return string
* @uses UTF8::$server_utf8
*/
public static function ucwords($str)
{
if ( ! isset(self::$called[__FUNCTION__]))
if ( ! isset(UTF8::$called[__FUNCTION__]))
{
require Kohana::find_file('utf8', __FUNCTION__);
// Function has been called
self::$called[__FUNCTION__] = TRUE;
UTF8::$called[__FUNCTION__] = TRUE;
}
return _ucwords($str);
@@ -413,12 +411,12 @@ class Kohana_UTF8 {
*/
public static function strcasecmp($str1, $str2)
{
if ( ! isset(self::$called[__FUNCTION__]))
if ( ! isset(UTF8::$called[__FUNCTION__]))
{
require Kohana::find_file('utf8', __FUNCTION__);
// Function has been called
self::$called[__FUNCTION__] = TRUE;
UTF8::$called[__FUNCTION__] = TRUE;
}
return _strcasecmp($str1, $str2);
@@ -442,25 +440,25 @@ class Kohana_UTF8 {
*/
public static function str_ireplace($search, $replace, $str, & $count = NULL)
{
if ( ! isset(self::$called[__FUNCTION__]))
if ( ! isset(UTF8::$called[__FUNCTION__]))
{
require Kohana::find_file('utf8', __FUNCTION__);
// Function has been called
self::$called[__FUNCTION__] = TRUE;
UTF8::$called[__FUNCTION__] = TRUE;
}
return _str_ireplace($search, $replace, $str, $count);
}
/**
* Case-insenstive UTF-8 version of strstr. Returns all of input string
* Case-insensitive UTF-8 version of strstr. Returns all of input string
* from the first occurrence of needle to the end. This is a UTF8-aware
* version of [stristr](http://php.net/stristr).
*
* $found = UTF8::stristr($str, $search);
*
* @author Harry Fuecks <hfuecks@gmail.com>
* @author Harry Fuecks <hfuecks@gmail.com>
* @param string $str input string
* @param string $search needle
* @return string matched substring if found
@@ -468,12 +466,12 @@ class Kohana_UTF8 {
*/
public static function stristr($str, $search)
{
if ( ! isset(self::$called[__FUNCTION__]))
if ( ! isset(UTF8::$called[__FUNCTION__]))
{
require Kohana::find_file('utf8', __FUNCTION__);
// Function has been called
self::$called[__FUNCTION__] = TRUE;
UTF8::$called[__FUNCTION__] = TRUE;
}
return _stristr($str, $search);
@@ -485,7 +483,7 @@ class Kohana_UTF8 {
*
* $found = UTF8::strspn($str, $mask);
*
* @author Harry Fuecks <hfuecks@gmail.com>
* @author Harry Fuecks <hfuecks@gmail.com>
* @param string $str input string
* @param string $mask mask for search
* @param integer $offset start position of the string to examine
@@ -494,12 +492,12 @@ class Kohana_UTF8 {
*/
public static function strspn($str, $mask, $offset = NULL, $length = NULL)
{
if ( ! isset(self::$called[__FUNCTION__]))
if ( ! isset(UTF8::$called[__FUNCTION__]))
{
require Kohana::find_file('utf8', __FUNCTION__);
// Function has been called
self::$called[__FUNCTION__] = TRUE;
UTF8::$called[__FUNCTION__] = TRUE;
}
return _strspn($str, $mask, $offset, $length);
@@ -520,12 +518,12 @@ class Kohana_UTF8 {
*/
public static function strcspn($str, $mask, $offset = NULL, $length = NULL)
{
if ( ! isset(self::$called[__FUNCTION__]))
if ( ! isset(UTF8::$called[__FUNCTION__]))
{
require Kohana::find_file('utf8', __FUNCTION__);
// Function has been called
self::$called[__FUNCTION__] = TRUE;
UTF8::$called[__FUNCTION__] = TRUE;
}
return _strcspn($str, $mask, $offset, $length);
@@ -546,12 +544,12 @@ class Kohana_UTF8 {
*/
public static function str_pad($str, $final_str_length, $pad_str = ' ', $pad_type = STR_PAD_RIGHT)
{
if ( ! isset(self::$called[__FUNCTION__]))
if ( ! isset(UTF8::$called[__FUNCTION__]))
{
require Kohana::find_file('utf8', __FUNCTION__);
// Function has been called
self::$called[__FUNCTION__] = TRUE;
UTF8::$called[__FUNCTION__] = TRUE;
}
return _str_pad($str, $final_str_length, $pad_str, $pad_type);
@@ -570,12 +568,12 @@ class Kohana_UTF8 {
*/
public static function str_split($str, $split_length = 1)
{
if ( ! isset(self::$called[__FUNCTION__]))
if ( ! isset(UTF8::$called[__FUNCTION__]))
{
require Kohana::find_file('utf8', __FUNCTION__);
// Function has been called
self::$called[__FUNCTION__] = TRUE;
UTF8::$called[__FUNCTION__] = TRUE;
}
return _str_split($str, $split_length);
@@ -587,17 +585,17 @@ class Kohana_UTF8 {
* $str = UTF8::strrev($str);
*
* @author Harry Fuecks <hfuecks@gmail.com>
* @param string $str string to be reversed
* @param string $str string to be reversed
* @return string
*/
public static function strrev($str)
{
if ( ! isset(self::$called[__FUNCTION__]))
if ( ! isset(UTF8::$called[__FUNCTION__]))
{
require Kohana::find_file('utf8', __FUNCTION__);
// Function has been called
self::$called[__FUNCTION__] = TRUE;
UTF8::$called[__FUNCTION__] = TRUE;
}
return _strrev($str);
@@ -616,12 +614,12 @@ class Kohana_UTF8 {
*/
public static function trim($str, $charlist = NULL)
{
if ( ! isset(self::$called[__FUNCTION__]))
if ( ! isset(UTF8::$called[__FUNCTION__]))
{
require Kohana::find_file('utf8', __FUNCTION__);
// Function has been called
self::$called[__FUNCTION__] = TRUE;
UTF8::$called[__FUNCTION__] = TRUE;
}
return _trim($str, $charlist);
@@ -640,12 +638,12 @@ class Kohana_UTF8 {
*/
public static function ltrim($str, $charlist = NULL)
{
if ( ! isset(self::$called[__FUNCTION__]))
if ( ! isset(UTF8::$called[__FUNCTION__]))
{
require Kohana::find_file('utf8', __FUNCTION__);
// Function has been called
self::$called[__FUNCTION__] = TRUE;
UTF8::$called[__FUNCTION__] = TRUE;
}
return _ltrim($str, $charlist);
@@ -664,12 +662,12 @@ class Kohana_UTF8 {
*/
public static function rtrim($str, $charlist = NULL)
{
if ( ! isset(self::$called[__FUNCTION__]))
if ( ! isset(UTF8::$called[__FUNCTION__]))
{
require Kohana::find_file('utf8', __FUNCTION__);
// Function has been called
self::$called[__FUNCTION__] = TRUE;
UTF8::$called[__FUNCTION__] = TRUE;
}
return _rtrim($str, $charlist);
@@ -687,12 +685,12 @@ class Kohana_UTF8 {
*/
public static function ord($chr)
{
if ( ! isset(self::$called[__FUNCTION__]))
if ( ! isset(UTF8::$called[__FUNCTION__]))
{
require Kohana::find_file('utf8', __FUNCTION__);
// Function has been called
self::$called[__FUNCTION__] = TRUE;
UTF8::$called[__FUNCTION__] = TRUE;
}
return _ord($chr);
@@ -717,12 +715,12 @@ class Kohana_UTF8 {
*/
public static function to_unicode($str)
{
if ( ! isset(self::$called[__FUNCTION__]))
if ( ! isset(UTF8::$called[__FUNCTION__]))
{
require Kohana::find_file('utf8', __FUNCTION__);
// Function has been called
self::$called[__FUNCTION__] = TRUE;
UTF8::$called[__FUNCTION__] = TRUE;
}
return _to_unicode($str);
@@ -731,7 +729,7 @@ class Kohana_UTF8 {
/**
* Takes an array of ints representing the Unicode characters and returns a UTF-8 string.
* Astral planes are supported i.e. the ints in the input can be > 0xFFFF.
* Occurrances of the BOM are ignored. Surrogates are not allowed.
* Occurrences of the BOM are ignored. Surrogates are not allowed.
*
* $str = UTF8::to_unicode($array);
*
@@ -747,18 +745,18 @@ class Kohana_UTF8 {
*/
public static function from_unicode($arr)
{
if ( ! isset(self::$called[__FUNCTION__]))
if ( ! isset(UTF8::$called[__FUNCTION__]))
{
require Kohana::find_file('utf8', __FUNCTION__);
// Function has been called
self::$called[__FUNCTION__] = TRUE;
UTF8::$called[__FUNCTION__] = TRUE;
}
return _from_unicode($arr);
}
} // End UTF8
}
if (Kohana_UTF8::$server_utf8 === NULL)
{