Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F98659217
PhabricatorRemarkupRuleIcon.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Jan 15, 09:06
Size
1 KB
Mime Type
text/x-php
Expires
Fri, Jan 17, 09:06 (1 d, 19 h)
Engine
blob
Format
Raw Data
Handle
23618822
Attached To
rPH Phabricator
PhabricatorRemarkupRuleIcon.php
View Options
<?php
final
class
PhabricatorRemarkupRuleIcon
extends
PhutilRemarkupRule
{
public
function
getPriority
()
{
return
50.0
;
}
public
function
apply
(
$text
)
{
return
preg_replace_callback
(
'@{icon
\b
((?:[^}
\\\\
]+|
\\\\
.)*)}@m'
,
array
(
$this
,
'markupIcon'
),
$text
);
}
public
function
markupIcon
(
$matches
)
{
$extra
=
idx
(
$matches
,
1
);
// We allow various forms, like these:
//
// {icon}
// {icon camera}
// {icon,camera}
// {icon camera color=red}
// {icon, camera, color=red}
$extra
=
ltrim
(
$extra
,
",
\n
"
);
$extra
=
preg_split
(
'/[
\s
,]+/'
,
$extra
,
2
);
// Choose some arbitrary default icon so that previews render in a mostly
// reasonable way as you're typing the syntax.
$icon
=
idx
(
$extra
,
0
,
'paw'
);
$defaults
=
array
(
'color'
=>
null
,
);
$options
=
idx
(
$extra
,
1
,
''
);
$parser
=
new
PhutilSimpleOptions
();
$options
=
$parser
->
parse
(
$options
)
+
$defaults
;
// NOTE: We're validating icon and color names to prevent users from
// adding arbitrary CSS classes to the document. Although this probably
// isn't dangerous, it's safer to validate.
static
$icon_names
;
if
(!
$icon_names
)
{
$icon_names
=
array_fuse
(
PHUIIconView
::
getFontIcons
());
}
static
$color_names
;
if
(!
$color_names
)
{
$color_names
=
array_fuse
(
PHUIIconView
::
getFontIconColors
());
}
if
(
empty
(
$icon_names
[
'fa-'
.
$icon
]))
{
$icon
=
'paw'
;
}
$color
=
$options
[
'color'
];
if
(
empty
(
$color_names
[
$color
]))
{
$color
=
null
;
}
$icon_view
=
id
(
new
PHUIIconView
())
->
setIconFont
(
'fa-'
.
$icon
,
$color
);
return
$this
->
getEngine
()->
storeText
(
$icon_view
);
}
}
Event Timeline
Log In to Comment