[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorNavigationRemarkupRule extends PhutilRemarkupRule { 4 5 public function getPriority() { 6 return 200.0; 7 } 8 9 public function apply($text) { 10 return preg_replace_callback( 11 '@{nav\b((?:[^}\\\\]+|\\\\.)*)}@m', 12 array($this, 'markupNavigation'), 13 $text); 14 } 15 16 public function markupNavigation($matches) { 17 if (!$this->isFlatText($matches[0])) { 18 return $matches[0]; 19 } 20 21 $elements = ltrim($matches[1], ", \n"); 22 $elements = explode('>', $elements); 23 24 $defaults = array( 25 'name' => null, 26 'type' => 'link', 27 'href' => null, 28 'icon' => null, 29 ); 30 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; 40 } 41 } 42 43 if ($this->getEngine()->isTextMode()) { 44 return implode(' > ', ipull($sequence, 'name')); 45 } 46 47 static $icon_names; 48 if (!$icon_names) { 49 $icon_names = array_fuse(PHUIIconView::getFontIcons()); 50 } 51 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; 59 } 60 61 $tag = id(new PHUITagView()) 62 ->setType(PHUITagView::TYPE_SHADE) 63 ->setShade($item_color) 64 ->setName($item_name); 65 66 if ($item['icon']) { 67 $icon_name = 'fa-'.$item['icon']; 68 if (isset($icon_names[$icon_name])) { 69 $tag->setIcon($icon_name); 70 } 71 } 72 73 if ($item['href'] !== null) { 74 if (PhabricatorEnv::isValidWebResource($item['href'])) { 75 $tag->setHref($item['href']); 76 $tag->setExternal(true); 77 } 78 } 79 80 $out[] = $tag; 81 } 82 83 if ($this->getEngine()->isHTMLMailMode()) { 84 $arrow_attr = array( 85 'style' => 'color: #92969D;', 86 ); 87 $nav_attr = array(); 88 } else { 89 $arrow_attr = array( 90 'class' => 'remarkup-nav-sequence-arrow', 91 ); 92 $nav_attr = array( 93 'class' => 'remarkup-nav-sequence', 94 ); 95 } 96 97 $joiner = phutil_tag( 98 'span', 99 $arrow_attr, 100 " \xE2\x86\x92 "); 101 102 $out = phutil_implode_html($joiner, $out); 103 104 $out = phutil_tag( 105 'span', 106 $nav_attr, 107 $out); 108 109 return $this->getEngine()->storeText($out); 110 } 111 112 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |