Remove product literal strings in "pht()", part 18
[phabricator.git] / src / infrastructure / markup / rule / PhabricatorNavigationRemarkupRule.php
blob3fc33730018ca443eaab687bf3d1939157f293b8
1 <?php
3 final class PhabricatorNavigationRemarkupRule extends PhutilRemarkupRule {
5 public function getPriority() {
6 return 200.0;
9 public function apply($text) {
10 return preg_replace_callback(
11 '@{nav\b((?:[^}\\\\]+|\\\\.)*)}@m',
12 array($this, 'markupNavigation'),
13 $text);
16 public function markupNavigation(array $matches) {
17 if (!$this->isFlatText($matches[0])) {
18 return $matches[0];
21 $elements = ltrim($matches[1], ", \n");
22 $elements = explode('>', $elements);
24 $defaults = array(
25 'name' => null,
26 'type' => 'link',
27 'href' => null,
28 'icon' => null,
31 $sequence = array();
32 $parser = new PhutilSimpleOptions();
33 foreach ($elements as $element) {
34 if (strpos($element, '=') === false) {
35 $sequence[] = array(
36 'name' => trim($element),
37 ) + $defaults;
38 } else {
39 $sequence[] = $parser->parse($element) + $defaults;
43 if ($this->getEngine()->isTextMode()) {
44 return implode(' > ', ipull($sequence, 'name'));
47 static $icon_names;
48 if (!$icon_names) {
49 $icon_names = array_fuse(PHUIIconView::getIcons());
52 $out = array();
53 foreach ($sequence as $item) {
54 $item_name = $item['name'];
55 $item_color = PHUITagView::COLOR_GREY;
56 if ($item['type'] == 'instructions') {
57 $item_name = phutil_tag('em', array(), $item_name);
58 $item_color = PHUITagView::COLOR_INDIGO;
61 $tag = id(new PHUITagView())
62 ->setType(PHUITagView::TYPE_SHADE)
63 ->setColor($item_color)
64 ->setName($item_name);
66 if ($item['icon']) {
67 $icon_name = 'fa-'.$item['icon'];
68 if (isset($icon_names[$icon_name])) {
69 $tag->setIcon($icon_name);
73 if ($item['href'] !== null) {
74 if (PhabricatorEnv::isValidRemoteURIForLink($item['href'])) {
75 $tag->setHref($item['href']);
76 $tag->setExternal(true);
80 $out[] = $tag;
83 if ($this->getEngine()->isHTMLMailMode()) {
84 $arrow_attr = array(
85 'style' => 'color: #92969D;',
87 $nav_attr = array();
88 } else {
89 $arrow_attr = array(
90 'class' => 'remarkup-nav-sequence-arrow',
92 $nav_attr = array(
93 'class' => 'remarkup-nav-sequence',
97 $joiner = phutil_tag(
98 'span',
99 $arrow_attr,
100 " \xE2\x86\x92 ");
102 $out = phutil_implode_html($joiner, $out);
104 $out = phutil_tag(
105 'span',
106 $nav_attr,
107 $out);
109 return $this->getEngine()->storeText($out);