protected function markupHyperlinkUngreedy($matches)
{
$match = $matches[1];
$tail = null;
$trailing = null;
if (preg_match('/[;,.:!?]+$/', $match, $trailing)) {
$tail = $trailing[0];
$match = substr($match, 0, -strlen($tail));
}
// If there's a closing paren at the end but no balancing open paren in
// the URL, don't link the close paren. This is an attempt to gracefully
// handle the two common paren cases, Wikipedia links and English language
// parentheticals, e.g.:
//
// http://en.wikipedia.org/wiki/Noun_(disambiguation)
// (see also http://www.example.com)
//
// We could apply a craftier heuristic here which tries to actually balance
// the parens, but this is probably sufficient.
if (preg_match('/\\)$/', $match) && !preg_match('/\\(/', $match)) {
$tail = ')' . $tail;
$match = substr($match, 0, -1);
}
return hsprintf('%s%s', $this->markupHyperlink(array(null, $match)), $tail);
}
public function testSingleVariant()
{
$translator = $this->newTranslator('en_US');
// In this translation, we have no alternatives for the first conversion.
$translator->setTranslations(array('Run the command %s %d time(s).' => array(array('Run the command %s once.', 'Run the command %s %d times.'))));
$this->assertEqual('Run the command <tt>ls</tt> 123 times.', (string) $translator->translate('Run the command %s %d time(s).', hsprintf('<tt>%s</tt>', 'ls'), 123));
}
public function renderExample()
{
$request = $this->getRequest();
$user = $request->getUser();
$action = id(new PHUIListItemView())->setName(pht('Actions'))->setType(PHUIListItemView::TYPE_LABEL);
$action1 = id(new PHUIListItemView())->setName(pht('Edit Document'))->setHref('#')->setIcon('fa-edit')->setType(PHUIListItemView::TYPE_LINK);
$action2 = id(new PHUIListItemView())->setName(pht('Move Document'))->setHref('#')->setIcon('fa-arrows')->setType(PHUIListItemView::TYPE_LINK);
$action3 = id(new PHUIListItemView())->setName(pht('Delete Document'))->setHref('#')->setIcon('fa-times')->setType(PHUIListItemView::TYPE_LINK);
$action4 = id(new PHUIListItemView())->setName(pht('View History'))->setHref('#')->setIcon('fa-list')->setType(PHUIListItemView::TYPE_LINK);
$action5 = id(new PHUIListItemView())->setName(pht('Subscribe'))->setHref('#')->setIcon('fa-plus-circle')->setType(PHUIListItemView::TYPE_LINK);
$divider = id(new PHUIListItemView())->setType(PHUIListItemView::TYPE_DIVIDER);
$header = id(new PHUIHeaderView())->setHeader(pht('Installation'));
$label1 = id(new PHUIListItemView())->setName(pht('Getting Started'))->setType(PHUIListItemView::TYPE_LABEL);
$label2 = id(new PHUIListItemView())->setName(pht('Documentation'))->setType(PHUIListItemView::TYPE_LABEL);
$item1 = id(new PHUIListItemView())->setName(pht('Installation'))->setHref('#')->setType(PHUIListItemView::TYPE_LINK);
$item2 = id(new PHUIListItemView())->setName(pht('Webserver Config'))->setHref('#')->setType(PHUIListItemView::TYPE_LINK);
$item3 = id(new PHUIListItemView())->setName(pht('Adding Users'))->setHref('#')->setType(PHUIListItemView::TYPE_LINK);
$item4 = id(new PHUIListItemView())->setName(pht('Debugging'))->setHref('#')->setType(PHUIListItemView::TYPE_LINK);
$sidenav = id(new PHUIListView())->setType(PHUIListView::SIDENAV_LIST)->addMenuItem($action)->addMenuItem($action1)->addMenuItem($action2)->addMenuItem($action3)->addMenuItem($action4)->addMenuItem($action5)->addMenuItem($divider)->addMenuItem($label1)->addMenuItem($item1)->addMenuItem($item2)->addMenuItem($item3)->addMenuItem($item4)->addMenuItem($label2)->addMenuItem($item2)->addMenuItem($item3)->addMenuItem($item4)->addMenuItem($item1);
$home = id(new PHUIListItemView())->setIcon('fa-home')->setHref('#')->setType(PHUIListItemView::TYPE_ICON);
$item1 = id(new PHUIListItemView())->setName(pht('Installation'))->setHref('#')->setSelected(true)->setType(PHUIListItemView::TYPE_LINK);
$item2 = id(new PHUIListItemView())->setName(pht('Webserver Config'))->setHref('#')->setType(PHUIListItemView::TYPE_LINK);
$item3 = id(new PHUIListItemView())->setName(pht('Adding Users'))->setHref('#')->setType(PHUIListItemView::TYPE_LINK);
$item4 = id(new PHUIListItemView())->setName(pht('Debugging'))->setHref('#')->setType(PHUIListItemView::TYPE_LINK);
$topnav = id(new PHUIListView())->setType(PHUIListView::NAVBAR_LIST)->addMenuItem($home)->addMenuItem($item1)->addMenuItem($item2)->addMenuItem($item3)->addMenuItem($item4);
$document = hsprintf('<p class="pl">Lorem ipsum dolor sit amet, consectetur adipisicing, ' . 'sed do eiusmod tempor incididunt ut labore et dolore magna ' . 'aliqua. Ut enim ad minim veniam, quis nostrud exercitation ' . 'ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis ' . 'aute irure dolor in reprehenderit in voluptate velit esse cillum ' . 'dolore eu fugiat nulla pariatur. Excepteur sint occaecat ' . 'cupidatat non proident, sunt in culpa qui officia deserunt ' . 'mollit anim id est laborum.</p>' . '<p class="plr pll plb">Lorem ipsum dolor sit amet, consectetur, ' . 'sed do eiusmod tempor incididunt ut labore et dolore magna ' . 'aliqua. Ut enim ad minim veniam, quis nostrud exercitation ' . 'ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis ' . 'aute irure dolor in reprehenderit in voluptate velit esse cillum ' . 'dolore eu fugiat nulla pariatur. Excepteur sint occaecat ' . 'cupidatat non proident, sunt in culpa qui officia deserunt ' . 'mollit anim id est laborum.</p>' . '<p class="plr pll plb">Lorem ipsum dolor sit amet, consectetur, ' . 'sed do eiusmod tempor incididunt ut labore et dolore magna ' . 'aliqua. Ut enim ad minim veniam, quis nostrud exercitation ' . 'ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis ' . 'aute irure dolor in reprehenderit in voluptate velit esse cillum ' . 'dolore eu fugiat nulla pariatur. Excepteur sint occaecat ' . 'cupidatat non proident, sunt in culpa qui officia deserunt ' . 'mollit anim id est laborum.</p>' . '<p class="plr pll plb">Lorem ipsum dolor sit amet, consectetur, ' . 'sed do eiusmod tempor incididunt ut labore et dolore magna ' . 'aliqua. Ut enim ad minim veniam, quis nostrud exercitation ' . 'ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis ' . 'aute irure dolor in reprehenderit in voluptate velit esse cillum ' . 'dolore eu fugiat nulla pariatur. Excepteur sint occaecat ' . 'cupidatat non proident, sunt in culpa qui officia deserunt ' . 'mollit anim id est laborum.</p>' . '<p class="plr pll plb">Lorem ipsum dolor sit amet, consectetur, ' . 'sed do eiusmod tempor incididunt ut labore et dolore magna ' . 'aliqua. Ut enim ad minim veniam, quis nostrud exercitation ' . 'ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis ' . 'aute irure dolor in reprehenderit in voluptate velit esse cillum ' . 'dolore eu fugiat nulla pariatur. Excepteur sint occaecat ' . 'cupidatat non proident, sunt in culpa qui officia deserunt ' . 'mollit anim id est laborum.</p>' . '<p class="plr pll plb">Lorem ipsum dolor sit amet, consectetur, ' . 'sed do eiusmod tempor incididunt ut labore et dolore magna ' . 'aliqua. Ut enim ad minim veniam, quis nostrud exercitation ' . 'ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis ' . 'aute irure dolor in reprehenderit in voluptate velit esse cillum ' . 'dolore eu fugiat nulla pariatur. Excepteur sint occaecat ' . 'cupidatat non proident, sunt in culpa qui officia deserunt ' . 'mollit anim id est laborum.</p>');
$content = new PHUIDocumentView();
$content->setBook(pht('Book or Project Name'), pht('Article'));
$content->setHeader($header);
$content->setFluid(true);
$content->setTopNav($topnav);
$content->setSidenav($sidenav);
$content->appendChild($document);
return $content;
}
protected function applyCallback(array $matches)
{
// Remove the two exclamation points that represent syntax.
$excitement = substr($matches[2], 2);
// $excitement now has two fewer !'s than we started with.
return hsprintf('<span class="remarkup-highlight">%s%s</span>', $matches[1], $excitement);
}
public function handleRequest(AphrontRequest $request)
{
$viewer = $request->getViewer();
$stories = id(new PhabricatorNotificationQuery())->setViewer($viewer)->withUserPHIDs(array($viewer->getPHID()))->withKeys(array($request->getStr('key')))->execute();
if (!$stories) {
return $this->buildEmptyResponse();
}
$story = head($stories);
if ($story->getAuthorPHID() === $viewer->getPHID()) {
// Don't show the user individual notifications about their own
// actions. Primarily, this stops pages from showing notifications
// immediately after you click "Submit" on a comment form if the
// notification server returns faster than the web server.
// TODO: It would be nice to retain the "page updated" bubble on copies
// of the page that are open in other tabs, but there isn't an obvious
// way to do this easily.
return $this->buildEmptyResponse();
}
$builder = id(new PhabricatorNotificationBuilder(array($story)))->setUser($viewer)->setShowTimestamps(false);
$content = $builder->buildView()->render();
$dict = $builder->buildDict();
$data = $dict[0];
$response = array('pertinent' => true, 'primaryObjectPHID' => $story->getPrimaryObjectPHID(), 'desktopReady' => $data['desktopReady'], 'href' => $data['href'], 'icon' => $data['icon'], 'title' => $data['title'], 'body' => $data['body'], 'content' => hsprintf('%s', $content));
return id(new AphrontAjaxResponse())->setContent($response);
}
请发表评论