public function markupNavigation($matches)
 {
     if (!$this->isFlatText($matches[0])) {
         return $matches[0];
     }
     $elements = ltrim($matches[1], ", \n");
     $elements = explode('>', $elements);
     $defaults = array('name' => null, 'type' => 'link', 'href' => null, 'icon' => null);
     $sequence = array();
     $parser = new PhutilSimpleOptions();
     foreach ($elements as $element) {
         if (strpos($element, '=') === false) {
             $sequence[] = array('name' => trim($element)) + $defaults;
         } else {
             $sequence[] = $parser->parse($element) + $defaults;
         }
     }
     if ($this->getEngine()->isTextMode()) {
         return implode(' > ', ipull($sequence, 'name'));
     }
     static $icon_names;
     if (!$icon_names) {
         $icon_names = array_fuse(PHUIIconView::getFontIcons());
     }
     $out = array();
     foreach ($sequence as $item) {
         $item_name = $item['name'];
         $item_color = PHUITagView::COLOR_GREY;
         if ($item['type'] == 'instructions') {
             $item_name = phutil_tag('em', array(), $item_name);
             $item_color = PHUITagView::COLOR_INDIGO;
         }
         $tag = id(new PHUITagView())->setType(PHUITagView::TYPE_SHADE)->setShade($item_color)->setName($item_name);
         if ($item['icon']) {
             $icon_name = 'fa-' . $item['icon'];
             if (isset($icon_names[$icon_name])) {
                 $tag->setIcon($icon_name);
             }
         }
         if ($item['href'] !== null) {
             if (PhabricatorEnv::isValidWebResource($item['href'])) {
                 $tag->setHref($item['href']);
                 $tag->setExternal(true);
             }
         }
         $out[] = $tag;
     }
     $joiner = phutil_tag('span', array('class' => 'remarkup-nav-sequence-arrow'), " → ");
     $out = phutil_implode_html($joiner, $out);
     $out = phutil_tag('span', array('class' => 'remarkup-nav-sequence'), $out);
     return $this->getEngine()->storeText($out);
 }
 public function processRequest()
 {
     if ($this->id) {
         $list = id(new PhabricatorMetaMTAMailingList())->load($this->id);
         if (!$list) {
             return new Aphront404Response();
         }
     } else {
         $list = new PhabricatorMetaMTAMailingList();
     }
     $e_email = true;
     $e_uri = null;
     $e_name = true;
     $errors = array();
     $request = $this->getRequest();
     if ($request->isFormPost()) {
         $list->setName($request->getStr('name'));
         $list->setEmail($request->getStr('email'));
         $list->setURI($request->getStr('uri'));
         $e_email = null;
         $e_name = null;
         if (!strlen($list->getEmail())) {
             $e_email = 'Required';
             $errors[] = 'Email is required.';
         }
         if (!strlen($list->getName())) {
             $e_name = 'Required';
             $errors[] = 'Name is required.';
         } else {
             if (preg_match('/[ ,]/', $list->getName())) {
                 $e_name = 'Invalid';
                 $errors[] = 'Name must not contain spaces or commas.';
             }
         }
         if ($list->getURI()) {
             if (!PhabricatorEnv::isValidWebResource($list->getURI())) {
                 $e_uri = 'Invalid';
                 $errors[] = 'Mailing list URI must point to a valid web page.';
             }
         }
         if (!$errors) {
             try {
                 $list->save();
                 return id(new AphrontRedirectResponse())->setURI('/mail/lists/');
             } catch (AphrontQueryDuplicateKeyException $ex) {
                 $e_email = 'Duplicate';
                 $errors[] = 'Another mailing list already uses that address.';
             }
         }
     }
     $error_view = null;
     if ($errors) {
         $error_view = id(new AphrontErrorView())->setTitle('Form Errors')->setErrors($errors);
     }
     $form = new AphrontFormView();
     $form->setUser($request->getUser());
     if ($list->getID()) {
         $form->setAction('/mail/lists/edit/' . $list->getID() . '/');
     } else {
         $form->setAction('/mail/lists/edit/');
     }
     $form->appendChild(id(new AphrontFormTextControl())->setLabel('Email')->setName('email')->setValue($list->getEmail())->setCaption('Email will be delivered to this address.')->setError($e_email))->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setError($e_name)->setCaption('Human-readable display and autocomplete name.')->setValue($list->getName()))->appendChild(id(new AphrontFormTextControl())->setLabel('URI')->setName('uri')->setError($e_uri)->setCaption('Optional link to mailing list archives or info.')->setValue($list->getURI()))->appendChild(id(new AphrontFormStaticControl())->setLabel('ID')->setValue(nonempty($list->getID(), '-')))->appendChild(id(new AphrontFormStaticControl())->setLabel('PHID')->setValue(nonempty($list->getPHID(), '-')))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save')->addCancelButton('/mail/lists/'));
     $panel = new AphrontPanelView();
     if ($list->getID()) {
         $panel->setHeader('Edit Mailing List');
     } else {
         $panel->setHeader('Create New Mailing List');
     }
     $panel->appendChild($form);
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Edit Mailing List'));
 }
 private function renderFooter()
 {
     if (!$this->getShowChrome()) {
         return null;
     }
     if (!$this->getShowFooter()) {
         return null;
     }
     $items = PhabricatorEnv::getEnvConfig('ui.footer-items');
     if (!$items) {
         return null;
     }
     $foot = array();
     foreach ($items as $item) {
         $name = idx($item, 'name', pht('Unnamed Footer Item'));
         $href = idx($item, 'href');
         if (!PhabricatorEnv::isValidWebResource($href)) {
             $href = null;
         }
         if ($href !== null) {
             $tag = 'a';
         } else {
             $tag = 'span';
         }
         $foot[] = phutil_tag($tag, array('href' => $href), $name);
     }
     $foot = phutil_implode_html(" · ", $foot);
     return phutil_tag('div', array('class' => 'phabricator-standard-page-footer'), $foot);
 }
 public function processRequest()
 {
     if ($this->id) {
         $item = id(new PhabricatorDirectoryItem())->load($this->id);
         if (!$item) {
             return new Aphront404Response();
         }
     } else {
         $item = new PhabricatorDirectoryItem();
     }
     $e_name = true;
     $e_href = true;
     $errors = array();
     $request = $this->getRequest();
     if ($request->isFormPost()) {
         $item->setName($request->getStr('name'));
         $item->setHref($request->getStr('href'));
         $item->setDescription($request->getStr('description'));
         $item->setCategoryID($request->getStr('categoryID'));
         $item->setSequence($request->getStr('sequence'));
         if (!strlen($item->getName())) {
             $errors[] = 'Item name is required.';
             $e_name = 'Required';
         }
         if (!strlen($item->getHref())) {
             $errors[] = 'Item link is required.';
             $e_href = 'Required';
         } else {
             $href = $item->getHref();
             if (!PhabricatorEnv::isValidWebResource($href)) {
                 $e_href = 'Invalid';
                 $errors[] = 'Item link must point to a valid web page.';
             }
         }
         if (!$errors) {
             $item->save();
             return id(new AphrontRedirectResponse())->setURI('/directory/edit/');
         }
     }
     $error_view = null;
     if ($errors) {
         $error_view = id(new AphrontErrorView())->setTitle('Form Errors')->setErrors($errors);
     }
     $form = new AphrontFormView();
     $form->setUser($request->getUser());
     if ($item->getID()) {
         $form->setAction('/directory/item/edit/' . $item->getID() . '/');
     } else {
         $form->setAction('/directory/item/edit/');
     }
     $categories = id(new PhabricatorDirectoryCategory())->loadAll();
     $category_map = mpull($categories, 'getName', 'getID');
     $form->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($item->getName())->setError($e_name))->appendChild(id(new AphrontFormSelectControl())->setLabel('Category')->setName('categoryID')->setOptions($category_map)->setValue($item->getCategoryID()))->appendChild(id(new AphrontFormTextControl())->setLabel('Link')->setName('href')->setValue($item->getHref())->setError($e_href))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Description')->setName('description')->setValue($item->getDescription()))->appendChild(id(new AphrontFormTextControl())->setLabel('Order')->setName('sequence')->setCaption('Items in a category are sorted by "order", then by name.')->setValue((int) $item->getSequence()))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save')->addCancelButton('/directory/edit/'));
     $panel = new AphrontPanelView();
     if ($item->getID()) {
         $panel->setHeader('Edit Directory Item');
     } else {
         $panel->setHeader('Create New Directory Item');
     }
     $panel->appendChild($form);
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Edit Directory Item'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     if ($this->id) {
         $page_title = pht('Edit Mailing List');
         $list = id(new PhabricatorMailingListQuery())->setViewer($viewer)->withIDs(array($this->id))->executeOne();
         if (!$list) {
             return new Aphront404Response();
         }
     } else {
         $page_title = pht('Create Mailing List');
         $list = new PhabricatorMetaMTAMailingList();
     }
     $e_email = true;
     $e_uri = null;
     $e_name = true;
     $errors = array();
     $crumbs = $this->buildApplicationCrumbs();
     if ($request->isFormPost()) {
         $list->setName($request->getStr('name'));
         $list->setEmail($request->getStr('email'));
         $list->setURI($request->getStr('uri'));
         $e_email = null;
         $e_name = null;
         if (!strlen($list->getEmail())) {
             $e_email = pht('Required');
             $errors[] = pht('Email is required.');
         }
         if (!strlen($list->getName())) {
             $e_name = pht('Required');
             $errors[] = pht('Name is required.');
         } else {
             if (preg_match('/[ ,]/', $list->getName())) {
                 $e_name = pht('Invalid');
                 $errors[] = pht('Name must not contain spaces or commas.');
             }
         }
         if ($list->getURI()) {
             if (!PhabricatorEnv::isValidWebResource($list->getURI())) {
                 $e_uri = pht('Invalid');
                 $errors[] = pht('Mailing list URI must point to a valid web page.');
             }
         }
         if (!$errors) {
             try {
                 $list->save();
                 return id(new AphrontRedirectResponse())->setURI($this->getApplicationURI());
             } catch (AphrontDuplicateKeyQueryException $ex) {
                 $e_email = pht('Duplicate');
                 $errors[] = pht('Another mailing list already uses that address.');
             }
         }
     }
     $form = new AphrontFormView();
     $form->setUser($request->getUser());
     if ($list->getID()) {
         $form->setAction($this->getApplicationURI('/edit/' . $list->getID() . '/'));
     } else {
         $form->setAction($this->getApplicationURI('/edit/'));
     }
     $form->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Email'))->setName('email')->setValue($list->getEmail())->setCaption(pht('Email will be delivered to this address.'))->setError($e_email))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Name'))->setName('name')->setError($e_name)->setCaption(pht('Human-readable display and autocomplete name.'))->setValue($list->getName()))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('URI'))->setName('uri')->setError($e_uri)->setCaption(pht('Optional link to mailing list archives or info.'))->setValue($list->getURI()))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Save'))->addCancelButton($this->getApplicationURI()));
     if ($list->getID()) {
         $crumbs->addTextCrumb(pht('Edit Mailing List'));
     } else {
         $crumbs->addTextCrumb(pht('Create Mailing List'));
     }
     $form_box = id(new PHUIObjectBoxView())->setHeaderText($page_title)->setFormErrors($errors)->setForm($form);
     return $this->buildApplicationPage(array($crumbs, $form_box), array('title' => $page_title));
 }