Changeset View
Changeset View
Standalone View
Standalone View
src/applications/macro/markup/PhabricatorIconRemarkupRule.php
Show All 35 Lines | public function markupIcon(array $matches) { | ||||
$extra = preg_split('/[\s,]+/', $extra, 2); | $extra = preg_split('/[\s,]+/', $extra, 2); | ||||
// Choose some arbitrary default icon so that previews render in a mostly | // Choose some arbitrary default icon so that previews render in a mostly | ||||
// reasonable way as you're typing the syntax. | // reasonable way as you're typing the syntax. | ||||
$icon = idx($extra, 0, 'paw'); | $icon = idx($extra, 0, 'paw'); | ||||
$defaults = array( | $defaults = array( | ||||
'color' => null, | 'color' => null, | ||||
'spin' => false, | |||||
); | ); | ||||
$options = idx($extra, 1, ''); | $options = idx($extra, 1, ''); | ||||
$parser = new PhutilSimpleOptions(); | $parser = new PhutilSimpleOptions(); | ||||
$options = $parser->parse($options) + $defaults; | $options = $parser->parse($options) + $defaults; | ||||
// NOTE: We're validating icon and color names to prevent users from | // NOTE: We're validating icon and color names to prevent users from | ||||
// adding arbitrary CSS classes to the document. Although this probably | // adding arbitrary CSS classes to the document. Although this probably | ||||
Show All 13 Lines | if (empty($icon_names['fa-'.$icon])) { | ||||
$icon = 'paw'; | $icon = 'paw'; | ||||
} | } | ||||
$color = $options['color']; | $color = $options['color']; | ||||
if (empty($color_names[$color])) { | if (empty($color_names[$color])) { | ||||
$color = null; | $color = null; | ||||
} | } | ||||
$classes = array(); | |||||
$classes[] = $color; | |||||
$spin = $options['spin']; | |||||
if ($spin) { | |||||
$classes[] = 'ph-spin'; | |||||
} | |||||
$icon_view = id(new PHUIIconView()) | $icon_view = id(new PHUIIconView()) | ||||
->setIconFont('fa-'.$icon, $color); | ->setIconFont('fa-'.$icon, implode(' ', $classes)); | ||||
return $this->getEngine()->storeText($icon_view); | return $this->getEngine()->storeText($icon_view); | ||||
} | } | ||||
} | } |