Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
c05ccc5d
Commit
c05ccc5d
authored
Jun 12, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved entities method to html class and added encoding configuration option.
parent
a77b6a97
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
25 deletions
+41
-25
application.php
application/config/application.php
+12
-0
form.php
system/form.php
+6
-6
html.php
system/html.php
+19
-8
str.php
system/str.php
+4
-11
No files found.
application/config/application.php
View file @
c05ccc5d
...
...
@@ -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
...
...
system/form.php
View file @
c05ccc5d
...
...
@@ -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
;
...
...
system/html.php
View file @
c05ccc5d
...
...
@@ -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
)
.
'"'
;
}
}
...
...
system/str.php
View file @
c05ccc5d
...
...
@@ -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
));
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment