Kohana v3.3.5
This commit is contained in:
@@ -240,12 +240,13 @@ class Kohana_Text {
|
||||
*
|
||||
* @param string $string string to transform
|
||||
* @param string $delimiter delimiter to use
|
||||
* @uses UTF8::ucfirst
|
||||
* @return string
|
||||
*/
|
||||
public static function ucfirst($string, $delimiter = '-')
|
||||
{
|
||||
// Put the keys back the Case-Convention expected
|
||||
return implode($delimiter, array_map('ucfirst', explode($delimiter, $string)));
|
||||
return implode($delimiter, array_map('UTF8::ucfirst', explode($delimiter, $string)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -293,12 +294,15 @@ class Kohana_Text {
|
||||
|
||||
$regex = '!'.$regex.'!ui';
|
||||
|
||||
// if $replacement is a single character: replace each of the characters of the badword with $replacement
|
||||
if (UTF8::strlen($replacement) == 1)
|
||||
{
|
||||
$regex .= 'e';
|
||||
return preg_replace($regex, 'str_repeat($replacement, UTF8::strlen(\'$1\'))', $str);
|
||||
return preg_replace_callback($regex, function($matches) use ($replacement) {
|
||||
return str_repeat($replacement, UTF8::strlen($matches[1]));
|
||||
}, $str);
|
||||
}
|
||||
|
||||
// if $replacement is not a single character, fully replace the badword with $replacement
|
||||
return preg_replace($regex, $replacement, $str);
|
||||
}
|
||||
|
||||
@@ -587,35 +591,40 @@ class Kohana_Text {
|
||||
*
|
||||
* echo Text::widont($text);
|
||||
*
|
||||
* regex courtesy of the Typogrify project
|
||||
* @link http://code.google.com/p/typogrify/
|
||||
*
|
||||
* @param string $str text to remove widows from
|
||||
* @return string
|
||||
*/
|
||||
public static function widont($str)
|
||||
{
|
||||
$str = rtrim($str);
|
||||
$space = strrpos($str, ' ');
|
||||
|
||||
if ($space !== FALSE)
|
||||
{
|
||||
$str = substr($str, 0, $space).' '.substr($str, $space + 1);
|
||||
}
|
||||
|
||||
return $str;
|
||||
// use '%' as delimiter and 'x' as modifier
|
||||
$widont_regex = "%
|
||||
((?:</?(?:a|em|span|strong|i|b)[^>]*>)|[^<>\s]) # must be proceeded by an approved inline opening or closing tag or a nontag/nonspace
|
||||
\s+ # the space to replace
|
||||
([^<>\s]+ # must be flollowed by non-tag non-space characters
|
||||
\s* # optional white space!
|
||||
(</(a|em|span|strong|i|b)>\s*)* # optional closing inline tags with optional white space after each
|
||||
((</(p|h[1-6]|li|dt|dd)>)|$)) # end with a closing p, h1-6, li or the end of the string
|
||||
%x";
|
||||
return preg_replace($widont_regex, '$1 $2', $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about the client user agent.
|
||||
*
|
||||
* // Returns "Chrome" when using Google Chrome
|
||||
* $browser = Text::user_agent('browser');
|
||||
* $browser = Text::user_agent($agent, 'browser');
|
||||
*
|
||||
* Multiple values can be returned at once by using an array:
|
||||
*
|
||||
* // Get the browser and platform with a single call
|
||||
* $info = Text::user_agent(array('browser', 'platform'));
|
||||
* $info = Text::user_agent($agent, array('browser', 'platform'));
|
||||
*
|
||||
* When using an array for the value, an associative array will be returned.
|
||||
*
|
||||
* @param string $agent user_agent
|
||||
* @param mixed $value array or string to return: browser, version, robot, mobile, platform
|
||||
* @return mixed requested information, FALSE if nothing is found
|
||||
* @uses Kohana::$config
|
||||
@@ -649,7 +658,7 @@ class Kohana_Text {
|
||||
// Set the browser name
|
||||
$info['browser'] = $name;
|
||||
|
||||
if (preg_match('#'.preg_quote($search).'[^0-9.]*+([0-9.][0-9.a-z]*)#i', Request::$user_agent, $matches))
|
||||
if (preg_match('#'.preg_quote($search).'[^0-9.]*+([0-9.][0-9.a-z]*)#i', $agent, $matches))
|
||||
{
|
||||
// Set the version number
|
||||
$info['version'] = $matches[1];
|
||||
|
Reference in New Issue
Block a user