本文整理汇总了PHP中PhabricatorSlug::normalize方法的典型用法代码示例。如果您正苦于以下问题:PHP PhabricatorSlug::normalize方法的具体用法?PHP PhabricatorSlug::normalize怎么用?PHP PhabricatorSlug::normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhabricatorSlug
的用法示例。
在下文中一共展示了PhabricatorSlug::normalize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: markupDocumentLink
public function markupDocumentLink($matches)
{
$link = trim($matches[1]);
$name = trim(idx($matches, 2, $link));
if (empty($matches[2])) {
$name = explode('/', trim($name, '/'));
$name = end($name);
}
$uri = new PhutilURI($link);
$slug = $uri->getPath();
$fragment = $uri->getFragment();
$slug = PhabricatorSlug::normalize($slug);
$slug = PhrictionDocument::getSlugURI($slug);
$href = (string) id(new PhutilURI($slug))->setFragment($fragment);
if ($this->getEngine()->getState('toc')) {
$text = $name;
} else {
if ($this->getEngine()->isTextMode()) {
return PhabricatorEnv::getProductionURI($href);
} else {
$text = $this->newTag('a', array('href' => $href, 'class' => 'phriction-link'), $name);
}
}
return $this->getEngine()->storeText($text);
}
示例2: handleRequest
public function handleRequest(AphrontRequest $request)
{
$user = $request->getUser();
$id = $request->getURIData('id');
if ($id) {
$post = id(new PhamePostQuery())->setViewer($user)->withIDs(array($id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
if (!$post) {
return new Aphront404Response();
}
$cancel_uri = $this->getApplicationURI('/post/view/' . $id . '/');
$submit_button = pht('Save Changes');
$page_title = pht('Edit Post');
} else {
$blog = id(new PhameBlogQuery())->setViewer($user)->withIDs(array($request->getInt('blog')))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_JOIN))->executeOne();
if (!$blog) {
return new Aphront404Response();
}
$post = PhamePost::initializePost($user, $blog);
$cancel_uri = $this->getApplicationURI('/blog/view/' . $blog->getID() . '/');
$submit_button = pht('Save Draft');
$page_title = pht('Create Post');
}
$title = $post->getTitle();
$phame_title = $post->getPhameTitle();
$body = $post->getBody();
$comments_widget = $post->getCommentsWidget();
$e_title = true;
$e_phame_title = true;
$validation_exception = null;
if ($request->isFormPost()) {
$title = $request->getStr('title');
$phame_title = $request->getStr('phame_title');
$phame_title = PhabricatorSlug::normalize($phame_title);
$body = $request->getStr('body');
$comments_widget = $request->getStr('comments_widget');
$xactions = array(id(new PhamePostTransaction())->setTransactionType(PhamePostTransaction::TYPE_TITLE)->setNewValue($title), id(new PhamePostTransaction())->setTransactionType(PhamePostTransaction::TYPE_PHAME_TITLE)->setNewValue($phame_title), id(new PhamePostTransaction())->setTransactionType(PhamePostTransaction::TYPE_BODY)->setNewValue($body), id(new PhamePostTransaction())->setTransactionType(PhamePostTransaction::TYPE_COMMENTS_WIDGET)->setNewValue($comments_widget));
$editor = id(new PhamePostEditor())->setActor($user)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true);
try {
$editor->applyTransactions($post, $xactions);
$uri = $this->getApplicationURI('/post/view/' . $post->getID() . '/');
return id(new AphrontRedirectResponse())->setURI($uri);
} catch (PhabricatorApplicationTransactionValidationException $ex) {
$validation_exception = $ex;
$e_title = $validation_exception->getShortMessage(PhamePostTransaction::TYPE_TITLE);
$e_phame_title = $validation_exception->getShortMessage(PhamePostTransaction::TYPE_PHAME_TITLE);
}
}
$handle = id(new PhabricatorHandleQuery())->setViewer($user)->withPHIDs(array($post->getBlogPHID()))->executeOne();
$form = id(new AphrontFormView())->setUser($user)->addHiddenInput('blog', $request->getInt('blog'))->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Blog'))->setValue($handle->renderLink()))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Title'))->setName('title')->setValue($title)->setID('post-title')->setError($e_title))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Phame Title'))->setName('phame_title')->setValue(rtrim($phame_title, '/'))->setID('post-phame-title')->setCaption(pht('Up to 64 alphanumeric characters ' . 'with underscores for spaces. ' . 'Formatting is enforced.'))->setError($e_phame_title))->appendChild(id(new PhabricatorRemarkupControl())->setLabel(pht('Body'))->setName('body')->setValue($body)->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)->setID('post-body')->setUser($user)->setDisableMacros(true))->appendChild(id(new AphrontFormSelectControl())->setLabel(pht('Comments Widget'))->setName('comments_widget')->setvalue($comments_widget)->setOptions($post->getCommentsWidgetOptionsForSelect()))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($cancel_uri)->setValue($submit_button));
$loading = phutil_tag_div('aphront-panel-preview-loading-text', pht('Loading preview...'));
$preview_panel = phutil_tag_div('aphront-panel-preview', array(phutil_tag_div('phame-post-preview-header', pht('Post Preview')), phutil_tag('div', array('id' => 'post-preview'), $loading)));
require_celerity_resource('phame-css');
Javelin::initBehavior('phame-post-preview', array('preview' => 'post-preview', 'body' => 'post-body', 'title' => 'post-title', 'phame_title' => 'post-phame-title', 'uri' => '/phame/post/preview/'));
$form_box = id(new PHUIObjectBoxView())->setHeaderText($page_title)->setValidationException($validation_exception)->setForm($form);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($page_title, $this->getApplicationURI('/post/view/' . $id . '/'));
$nav = $this->renderSideNavFilterView(null);
$nav->appendChild(array($crumbs, $form_box, $preview_panel));
return $this->buildApplicationPage($nav, array('title' => $page_title));
}
示例3: testSlugNormalization
public function testSlugNormalization()
{
$slugs = array('' => '/', '/' => '/', '//' => '/', '&&&' => '_/', '/derp/' => 'derp/', 'derp' => 'derp/', 'derp//derp' => 'derp/derp/', 'DERP//DERP' => 'derp/derp/', 'a B c' => 'a_b_c/', '-1~2.3abcd' => '-1~2.3abcd/', "TODO" => 't_o_d_o/', 'x#%&+=\\?<> y' => 'x_y/', "☃" => "☃/", '..' => 'dotdot/', '../' => 'dotdot/', '/../' => 'dotdot/', 'a/b' => 'a/b/', 'a//b' => 'a/b/', 'a/../b/' => 'a/dotdot/b/', '/../a' => 'dotdot/a/', '../a' => 'dotdot/a/', 'a/..' => 'a/dotdot/', 'a/../' => 'a/dotdot/', 'a?' => 'a/', '??' => '_/', 'a/?' => 'a/_/', '??/a/??' => '_/a/_/', 'a/??/c' => 'a/_/c/', 'a/?b/c' => 'a/b/c/', 'a/b?/c' => 'a/b/c/', 'a - b' => 'a_-_b/', 'a[b]' => 'a_b/', 'ab!' => 'ab!/');
foreach ($slugs as $slug => $normal) {
$this->assertEqual($normal, PhabricatorSlug::normalize($slug), pht("Normalization of '%s'", $slug));
}
}
示例4: processRequest
public function processRequest()
{
$request = $this->getRequest();
$user = $request->getUser();
$slug = PhabricatorSlug::normalize($request->getStr('slug'));
if ($request->isFormPost()) {
$document = id(new PhrictionDocumentQuery())->setViewer($user)->withSlugs(array($slug))->executeOne();
$prompt = $request->getStr('prompt', 'no');
$document_exists = $document && $document->getStatus() == PhrictionDocumentStatus::STATUS_EXISTS;
if ($document_exists && $prompt == 'no') {
$dialog = new AphrontDialogView();
$dialog->setSubmitURI('/phriction/new/')->setTitle(pht('Edit Existing Document?'))->setUser($user)->appendChild(pht('The document %s already exists. Do you want to edit it instead?', phutil_tag('tt', array(), $slug)))->addHiddenInput('slug', $slug)->addHiddenInput('prompt', 'yes')->addCancelButton('/w/')->addSubmitButton(pht('Edit Document'));
return id(new AphrontDialogResponse())->setDialog($dialog);
} else {
if (PhrictionDocument::isProjectSlug($slug)) {
$project = id(new PhabricatorProjectQuery())->setViewer($user)->withPhrictionSlugs(array(PhrictionDocument::getProjectSlugIdentifier($slug)))->executeOne();
if (!$project) {
$dialog = new AphrontDialogView();
$dialog->setSubmitURI('/w/')->setTitle(pht('Oops!'))->setUser($user)->appendChild(pht('You cannot create wiki pages under "projects/",
because they are reserved as project pages.
Create a new project with this name first.'))->addCancelButton('/w/', 'Okay');
return id(new AphrontDialogResponse())->setDialog($dialog);
}
}
}
$uri = '/phriction/edit/?slug=' . $slug;
return id(new AphrontRedirectResponse())->setURI($uri);
}
if ($slug == '/') {
$slug = '';
}
$view = id(new PHUIFormLayoutView())->appendChild(id(new AphrontFormTextControl())->setLabel('/w/')->setValue($slug)->setName('slug'));
$dialog = id(new AphrontDialogView())->setUser($user)->setTitle(pht('New Document'))->setSubmitURI('/phriction/new/')->appendChild(phutil_tag('p', array(), pht('Create a new document at')))->appendChild($view)->addSubmitButton(pht('Create'))->addCancelButton('/w/');
return id(new AphrontDialogResponse())->setDialog($dialog);
}
示例5: buildLocalNavigation
protected function buildLocalNavigation(PhabricatorProject $project)
{
$id = $project->getID();
$nav_view = new AphrontSideNavFilterView();
$uri = new PhutilURI('/project/view/' . $id . '/');
$nav_view->setBaseURI($uri);
$external_arrow = "↗";
$tasks_uri = '/maniphest/view/all/?projects=' . $project->getPHID();
$slug = PhabricatorSlug::normalize($project->getName());
$phriction_uri = '/w/projects/' . $slug;
$edit_uri = '/project/edit/' . $id . '/';
$members_uri = '/project/members/' . $id . '/';
$nav_view->addFilter('dashboard', 'Dashboard');
$nav_view->addSpacer();
$nav_view->addFilter('feed', 'Feed');
$nav_view->addFilter(null, 'Tasks ' . $external_arrow, $tasks_uri);
$nav_view->addFilter(null, 'Wiki ' . $external_arrow, $phriction_uri);
$nav_view->addFilter('people', 'People');
$nav_view->addFilter('about', 'About');
$user = $this->getRequest()->getUser();
$can_edit = PhabricatorPolicyCapability::CAN_EDIT;
$nav_view->addSpacer();
if (PhabricatorPolicyFilter::hasCapability($user, $project, $can_edit)) {
$nav_view->addFilter('edit', "Edit Project…", $edit_uri);
$nav_view->addFilter('members', "Edit Members…", $members_uri);
} else {
$nav_view->addFilter('edit', "Edit Project…", $edit_uri, $relative = false, 'disabled');
$nav_view->addFilter('members', "Edit Members…", $members_uri, $relative = false, 'disabled');
}
return $nav_view;
}
示例6: testSlugNormalization
public function testSlugNormalization()
{
$slugs = array('' => '/', '/' => '/', '//' => '/', '&&&' => '/', '/derp/' => 'derp/', 'derp' => 'derp/', 'derp//derp' => 'derp/derp/', 'DERP//DERP' => 'derp/derp/', 'a B c' => 'a_b_c/', '-1~2.3abcd' => '-1~2.3abcd/', "TODO" => 't_o_d_o/', 'x#%&+=\\?<> y' => 'x_y/', "☃" => "☃/", '..' => 'dotdot/', '../' => 'dotdot/', '/../' => 'dotdot/', 'a/b' => 'a/b/', 'a//b' => 'a/b/', 'a/../b/' => 'a/dotdot/b/', '/../a' => 'dotdot/a/', '../a' => 'dotdot/a/', 'a/..' => 'a/dotdot/', 'a/../' => 'a/dotdot/');
foreach ($slugs as $slug => $normal) {
$this->assertEqual($normal, PhabricatorSlug::normalize($slug), "Normalization of '{$slug}'");
}
}
示例7: testSlugNormalization
public function testSlugNormalization()
{
$slugs = array('' => '/', '/' => '/', '//' => '/', '&&&' => '/', '/derp/' => 'derp/', 'derp' => 'derp/', 'derp//derp' => 'derp/derp/', 'DERP//DERP' => 'derp/derp/', 'a B c' => 'a_b_c/', '-1~2.3abcd' => '1_2_3abcd/', "T•O•D•O" => 't_o_d_o/');
foreach ($slugs as $slug => $normal) {
$this->assertEqual($normal, PhabricatorSlug::normalize($slug), "Normalization of '{$slug}'");
}
}
示例8: getProjectSlugIdentifier
public static function getProjectSlugIdentifier($slug)
{
if (!self::isProjectSlug($slug)) {
throw new Exception("Slug '{$slug}' is not a project slug!");
}
$slug = PhabricatorSlug::normalize($slug);
$parts = explode('/', $slug);
return $parts[1] . '/';
}
示例9: execute
protected function execute(ConduitAPIRequest $request)
{
$slug = $request->getValue('slug');
$document = id(new PhrictionDocumentQuery())->setViewer($request->getUser())->withSlugs(array(PhabricatorSlug::normalize($slug)))->needContent(true)->executeOne();
if (!$document) {
throw new ConduitException('ERR-BAD-DOCUMENT');
}
return $this->buildDocumentInfoDictionary($document, $document->getContent());
}
示例10: buildProjectActions
private function buildProjectActions(PhutilEvent $event)
{
if (!$this->canUseApplication($event->getUser())) {
return null;
}
$project = $event->getValue('object');
$slug = PhabricatorSlug::normalize($project->getPhrictionSlug());
$href = '/w/projects/' . $slug;
return id(new PhabricatorActionView())->setIcon('fa-book')->setName(pht('View Wiki'))->setHref($href);
}
示例11: execute
protected function execute(ConduitAPIRequest $request)
{
$slug = $request->getValue('slug');
$doc = id(new PhrictionDocumentQuery())->setViewer($request->getUser())->withSlugs(array(PhabricatorSlug::normalize($slug)))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
if (!$doc) {
throw new Exception(pht('No such document.'));
}
$editor = id(PhrictionDocumentEditor::newForSlug($slug))->setActor($request->getUser())->setTitle($request->getValue('title'))->setContent($request->getValue('content'))->setDescription($request->getvalue('description'))->save();
return $this->buildDocumentInfoDictionary($editor->getDocument());
}
示例12: markupDocumentLink
public function markupDocumentLink($matches)
{
$slug = trim($matches[1]);
$name = trim(idx($matches, 2, $slug));
$name = explode('/', trim($name, '/'));
$name = end($name);
$slug = PhabricatorSlug::normalize($slug);
$uri = PhrictionDocument::getSlugURI($slug);
return $this->getEngine()->storeText(phutil_render_tag('a', array('href' => $uri, 'class' => 'phriction-link'), phutil_escape_html($name)));
}
示例13: execute
protected function execute(ConduitAPIRequest $request)
{
$query = new PhabricatorProjectQuery();
$query->setViewer($request->getUser());
$query->needMembers(true);
$query->needSlugs(true);
$ids = $request->getValue('ids');
if ($ids) {
$query->withIDs($ids);
}
$names = $request->getValue('names');
if ($names) {
$query->withNames($names);
}
$status = $request->getValue('status');
if ($status) {
$query->withStatus($status);
}
$phids = $request->getValue('phids');
if ($phids) {
$query->withPHIDs($phids);
}
$slugs = $request->getValue('slugs');
if ($slugs) {
$query->withSlugs($slugs);
}
$members = $request->getValue('members');
if ($members) {
$query->withMemberPHIDs($members);
}
$limit = $request->getValue('limit');
if ($limit) {
$query->setLimit($limit);
}
$offset = $request->getValue('offset');
if ($offset) {
$query->setOffset($offset);
}
$pager = $this->newPager($request);
$results = $query->executeWithCursorPager($pager);
$projects = $this->buildProjectInfoDictionaries($results);
// TODO: This is pretty hideous.
$slug_map = array();
foreach ($slugs as $slug) {
$normal = rtrim(PhabricatorSlug::normalize($slug), '/');
foreach ($projects as $project) {
if (in_array($normal, $project['slugs'])) {
$slug_map[$slug] = $project['phid'];
}
}
}
$result = array('data' => $projects, 'slugMap' => $slug_map);
return $this->addPagerResults($result, $pager);
}
示例14: getViewURI
public function getViewURI()
{
// go for the pretty uri if we can
$domain = $this->blog ? $this->blog->getDomain() : '';
if ($domain) {
$phame_title = PhabricatorSlug::normalize($this->getPhameTitle());
return 'http://' . $domain . '/post/' . $phame_title;
}
$uri = '/phame/post/view/' . $this->getID() . '/';
return PhabricatorEnv::getProductionURI($uri);
}
示例15: setPhrictionSlug
public function setPhrictionSlug($slug)
{
// NOTE: We're doing a little magic here and stripping out '/' so that
// project pages always appear at top level under projects/ even if the
// display name is "Hack / Slash" or similar (it will become
// 'hack_slash' instead of 'hack/slash').
$slug = str_replace('/', ' ', $slug);
$slug = PhabricatorSlug::normalize($slug);
$this->phrictionSlug = $slug;
return $this;
}