mirror of
https://github.com/laravel/laravel.git
synced 2025-02-20 11:53:14 +08:00
moved entities method to html class and added encoding configuration option.
This commit is contained in:
parent
a77b6a9737
commit
c05ccc5d49
@ -29,6 +29,18 @@ return array(
|
||||
|
||||
'language' => 'en',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Character Encoding
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This default character encoding used by your application. This is the
|
||||
| character encoding that will be used by the Str, Text, and Form classes.
|
||||
|
|
||||
*/
|
||||
|
||||
'encoding' => 'UTF-8',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Timezone
|
||||
|
@ -22,12 +22,12 @@ class Form {
|
||||
|
||||
$action = URL::to($action);
|
||||
|
||||
$attributes['action'] = $action;
|
||||
$attributes['action'] = HTML::entities($action);
|
||||
$attributes['method'] = ($method == 'GET' or $method == 'POST') ? $method : 'POST';
|
||||
|
||||
if ( ! array_key_exists('accept-charset', $attributes))
|
||||
{
|
||||
$attributes['accept-charset'] = 'UTF-8';
|
||||
$attributes['accept-charset'] = Config::get('application.encoding');
|
||||
}
|
||||
|
||||
$html = '<form'.HTML::attributes($attributes).'>';
|
||||
@ -142,7 +142,7 @@ class Form {
|
||||
*/
|
||||
public static function button($value, $attributes = array())
|
||||
{
|
||||
return '<button'.HTML::attributes($attributes).'>'.$value.'</button>'.PHP_EOL;
|
||||
return '<button'.HTML::attributes($attributes).'>'.HTML::entities($value).'</button>'.PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -221,7 +221,7 @@ class Form {
|
||||
$attributes['cols'] = 50;
|
||||
}
|
||||
|
||||
return '<textarea'.HTML::attributes($attributes).'>'.Str::entities($value).'</textarea>'.PHP_EOL;
|
||||
return '<textarea'.HTML::attributes($attributes).'>'.HTML::entities($value).'</textarea>'.PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -243,10 +243,10 @@ class Form {
|
||||
{
|
||||
$option_attributes = array();
|
||||
|
||||
$option_attributes['value'] = $value;
|
||||
$option_attributes['value'] = HTML::entities($value);
|
||||
$option_attributes['selected'] = ($value == $selected) ? 'selected' : null;
|
||||
|
||||
$html_options[] = '<option'.HTML::attributes($option_attributes).'>'.$display.'</option>';
|
||||
$html_options[] = '<option'.HTML::attributes($option_attributes).'>'.HTML::entities($display).'</option>';
|
||||
}
|
||||
|
||||
return '<select'.HTML::attributes($attributes).'>'.implode('', $html_options).'</select>'.PHP_EOL;
|
||||
|
@ -2,6 +2,17 @@
|
||||
|
||||
class HTML {
|
||||
|
||||
/**
|
||||
* Convert HTML characters to entities.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public static function entities($value)
|
||||
{
|
||||
return htmlentities($value, ENT_QUOTES, Config::get('application.encoding'), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a JavaScript reference.
|
||||
*
|
||||
@ -10,7 +21,7 @@ class HTML {
|
||||
*/
|
||||
public static function script($url)
|
||||
{
|
||||
return '<script type="text/javascript" src="'.trim(URL::to($url), '.js').'.js"></script>'.PHP_EOL;
|
||||
return '<script type="text/javascript" src="'.trim(static::entities(URL::to($url)), '.js').'.js"></script>'.PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -21,7 +32,7 @@ class HTML {
|
||||
*/
|
||||
public static function style($url, $media = 'all')
|
||||
{
|
||||
return '<link href="'.trim(URL::to($url), '.css').'.css" rel="stylesheet" type="text/css" media="'.$media.'" />'.PHP_EOL;
|
||||
return '<link href="'.trim(static::entities(URL::to($url)), '.css').'.css" rel="stylesheet" type="text/css" media="'.$media.'" />'.PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -35,7 +46,7 @@ class HTML {
|
||||
*/
|
||||
public static function link($url, $title, $attributes = array(), $https = false)
|
||||
{
|
||||
return '<a href="'.URL::to($url, $https).'"'.static::attributes($attributes).'>'.Str::entities($title).'</a>';
|
||||
return '<a href="'.static::entities(URL::to($url, $https)).'"'.static::attributes($attributes).'>'.static::entities($title).'</a>';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,7 +82,7 @@ class HTML {
|
||||
$title = $email;
|
||||
}
|
||||
|
||||
return '<a href="mailto:'.$email.'"'.static::attributes($attributes).'>'.$title.'</a>';
|
||||
return '<a href="mailto:'.$email.'"'.static::attributes($attributes).'>'.static::entities($title).'</a>';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,8 +106,8 @@ class HTML {
|
||||
*/
|
||||
public static function image($url, $alt = '', $attributes = array())
|
||||
{
|
||||
$attributes['alt'] = Str::entities($alt);
|
||||
return '<img src="'.URL::to($url).'"'.static::attributes($attributes).' />';
|
||||
$attributes['alt'] = static::entities($alt);
|
||||
return '<img src="'.static::entities(URL::to($url)).'"'.static::attributes($attributes).' />';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -164,7 +175,7 @@ class HTML {
|
||||
|
||||
foreach ($list as $key => $value)
|
||||
{
|
||||
$html .= '<li>'.Str::entities($value).'</li>';
|
||||
$html .= '<li>'.static::entities($value).'</li>';
|
||||
}
|
||||
|
||||
return '<'.$type.static::attributes($attributes).'>'.$html.'</'.$type.'>';
|
||||
@ -184,7 +195,7 @@ class HTML {
|
||||
{
|
||||
if ( ! is_null($value))
|
||||
{
|
||||
$html[] = $key.'="'.Str::entities($value).'"';
|
||||
$html[] = $key.'="'.static::entities($value).'"';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,13 +2,6 @@
|
||||
|
||||
class Str {
|
||||
|
||||
/**
|
||||
* The default encoding.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $encoding = 'UTF-8';
|
||||
|
||||
/**
|
||||
* Convert HTML characters to entities.
|
||||
*
|
||||
@ -17,7 +10,7 @@ class Str {
|
||||
*/
|
||||
public static function entities($value)
|
||||
{
|
||||
return htmlentities($value, ENT_QUOTES, static::$encoding, false);
|
||||
return htmlentities($value, ENT_QUOTES, Config::get('application.encoding'), false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -28,7 +21,7 @@ class Str {
|
||||
*/
|
||||
public static function lower($value)
|
||||
{
|
||||
return function_exists('mb_strtolower') ? mb_strtolower($value, static::$encoding) : strtolower($value);
|
||||
return function_exists('mb_strtolower') ? mb_strtolower($value, Config::get('application.encoding')) : strtolower($value);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -39,7 +32,7 @@ class Str {
|
||||
*/
|
||||
public static function upper($value)
|
||||
{
|
||||
return function_exists('mb_strtoupper') ? mb_strtoupper($value, static::$encoding) : strtoupper($value);
|
||||
return function_exists('mb_strtoupper') ? mb_strtoupper($value, Config::get('application.encoding')) : strtoupper($value);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,7 +43,7 @@ class Str {
|
||||
*/
|
||||
public static function title($value)
|
||||
{
|
||||
return (function_exists('mb_convert_case')) ? mb_convert_case($value, MB_CASE_TITLE, static::$encoding) : ucwords(strtolower($value));
|
||||
return (function_exists('mb_convert_case')) ? mb_convert_case($value, MB_CASE_TITLE, Config::get('application.encoding')) : ucwords(strtolower($value));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user