本文整理汇总了PHP中PhabricatorSlug类的典型用法代码示例。如果您正苦于以下问题:PHP PhabricatorSlug类的具体用法?PHP PhabricatorSlug怎么用?PHP PhabricatorSlug使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PhabricatorSlug类的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: renderBreadcrumbs
public function renderBreadcrumbs($slug)
{
$ancestor_handles = array();
$ancestral_slugs = PhabricatorSlug::getAncestry($slug);
$ancestral_slugs[] = $slug;
if ($ancestral_slugs) {
$empty_slugs = array_fill_keys($ancestral_slugs, null);
$ancestors = id(new PhrictionDocumentQuery())->setViewer($this->getRequest()->getUser())->withSlugs($ancestral_slugs)->execute();
$ancestors = mpull($ancestors, null, 'getSlug');
$ancestor_phids = mpull($ancestors, 'getPHID');
$handles = array();
if ($ancestor_phids) {
$handles = $this->loadViewerHandles($ancestor_phids);
}
$ancestor_handles = array();
foreach ($ancestral_slugs as $slug) {
if (isset($ancestors[$slug])) {
$ancestor_handles[] = $handles[$ancestors[$slug]->getPHID()];
} else {
$handle = new PhabricatorObjectHandle();
$handle->setName(PhabricatorSlug::getDefaultTitle($slug));
$handle->setURI(PhrictionDocument::getSlugURI($slug));
$ancestor_handles[] = $handle;
}
}
}
$breadcrumbs = array();
foreach ($ancestor_handles as $ancestor_handle) {
$breadcrumbs[] = id(new PHUICrumbView())->setName($ancestor_handle->getName())->setHref($ancestor_handle->getUri());
}
return $breadcrumbs;
}
示例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: loadPage
protected function loadPage()
{
$table = new PhrictionDocument();
$conn_r = $table->establishConnection('r');
$rows = queryfx_all($conn_r, 'SELECT * FROM %T %Q %Q %Q', $table->getTableName(), $this->buildWhereClause($conn_r), $this->buildOrderClause($conn_r), $this->buildLimitClause($conn_r));
$documents = $table->loadAllFromArray($rows);
if ($documents) {
$ancestor_slugs = array();
foreach ($documents as $key => $document) {
$document_slug = $document->getSlug();
foreach (PhabricatorSlug::getAncestry($document_slug) as $ancestor) {
$ancestor_slugs[$ancestor][] = $key;
}
}
if ($ancestor_slugs) {
$ancestors = queryfx_all($conn_r, 'SELECT * FROM %T WHERE slug IN (%Ls)', $document->getTableName(), array_keys($ancestor_slugs));
$ancestors = $table->loadAllFromArray($ancestors);
$ancestors = mpull($ancestors, null, 'getSlug');
foreach ($ancestor_slugs as $ancestor_slug => $document_keys) {
$ancestor = idx($ancestors, $ancestor_slug);
foreach ($document_keys as $document_key) {
$documents[$document_key]->attachAncestor($ancestor_slug, $ancestor);
}
}
}
}
return $documents;
}
示例6: 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;
}
示例7: testSlugDepth
public function testSlugDepth()
{
$slugs = array('/' => 0, 'a/' => 1, 'a/b/' => 2, 'a////b/' => 2);
foreach ($slugs as $slug => $depth) {
$this->assertEqual($depth, PhabricatorSlug::getDepth($slug), "Depth 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: 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;
}
示例14: execute
protected function execute(ConduitAPIRequest $request)
{
$slug = $request->getValue('slug');
$doc = id(new PhrictionDocument())->loadOneWhere('slug = %s', PhabricatorSlug::normalize($slug));
if (!$doc) {
throw new ConduitException('ERR-BAD-DOCUMENT');
}
$content = id(new PhrictionContent())->load($doc->getContentID());
$doc->attachContent($content);
return $this->buildDocumentInfoDictionary($doc);
}
示例15: getViewURI
public function getViewURI($blogger_name = '')
{
// go for the pretty uri if we can
if ($blogger_name) {
$phame_title = PhabricatorSlug::normalize($this->getPhameTitle());
$uri = phutil_escape_uri('/phame/posts/' . $blogger_name . '/' . $phame_title);
} else {
$uri = $this->getActionURI('view');
}
return $uri;
}