mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 14:52:41 +01:00
Improve Phame live blogs/posts
Summary: Make "View Live" work on Posts. Test Plan: Clicked "View Live" on live/not-live posts/blogs. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T1373 Differential Revision: https://secure.phabricator.com/D3703
This commit is contained in:
parent
0c4eb79d3a
commit
9c94bf1bea
9 changed files with 131 additions and 62 deletions
|
@ -1167,6 +1167,7 @@ phutil_register_library_map(array(
|
|||
'PhamePostListController' => 'applications/phame/controller/post/PhamePostListController.php',
|
||||
'PhamePostListView' => 'applications/phame/view/PhamePostListView.php',
|
||||
'PhamePostNewController' => 'applications/phame/controller/post/PhamePostNewController.php',
|
||||
'PhamePostNotLiveController' => 'applications/phame/controller/post/PhamePostNotLiveController.php',
|
||||
'PhamePostPreviewController' => 'applications/phame/controller/post/PhamePostPreviewController.php',
|
||||
'PhamePostPublishController' => 'applications/phame/controller/post/PhamePostPublishController.php',
|
||||
'PhamePostQuery' => 'applications/phame/query/PhamePostQuery.php',
|
||||
|
@ -2278,6 +2279,7 @@ phutil_register_library_map(array(
|
|||
array(
|
||||
0 => 'PhameDAO',
|
||||
1 => 'PhabricatorPolicyInterface',
|
||||
2 => 'PhabricatorMarkupInterface',
|
||||
),
|
||||
'PhameBlogDeleteController' => 'PhameController',
|
||||
'PhameBlogDetailView' => 'AphrontView',
|
||||
|
@ -2293,6 +2295,7 @@ phutil_register_library_map(array(
|
|||
array(
|
||||
0 => 'PhameDAO',
|
||||
1 => 'PhabricatorPolicyInterface',
|
||||
2 => 'PhabricatorMarkupInterface',
|
||||
),
|
||||
'PhamePostDeleteController' => 'PhameController',
|
||||
'PhamePostDetailView' => 'AphrontView',
|
||||
|
@ -2301,6 +2304,7 @@ phutil_register_library_map(array(
|
|||
'PhamePostListController' => 'PhameController',
|
||||
'PhamePostListView' => 'AphrontView',
|
||||
'PhamePostNewController' => 'PhameController',
|
||||
'PhamePostNotLiveController' => 'PhameController',
|
||||
'PhamePostPreviewController' => 'PhameController',
|
||||
'PhamePostPublishController' => 'PhameController',
|
||||
'PhamePostQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
|
|
|
@ -164,7 +164,7 @@ abstract class AphrontApplicationConfiguration {
|
|||
// TODO: Make this more flexible and modular so any application can
|
||||
// do crazy stuff here if it wants.
|
||||
|
||||
$path = '/phame/blog/live/'.$blog->getID().'/'.$path;
|
||||
$path = '/phame/live/'.$blog->getID().'/'.$path;
|
||||
|
||||
$celerity = CelerityAPI::getStaticResourceResponse();
|
||||
$celerity->setUseFullURI(true);
|
||||
|
|
|
@ -46,6 +46,7 @@ final class PhabricatorApplicationPhame extends PhabricatorApplication {
|
|||
return array(
|
||||
'/phame/' => array(
|
||||
'' => 'PhamePostListController',
|
||||
'live/(?P<id>[^/]+)/(?P<more>.*)' => 'PhameBlogLiveController',
|
||||
'post/' => array(
|
||||
'(?:(?P<filter>draft|all)/)?' => 'PhamePostListController',
|
||||
'blogger/(?P<bloggername>[\w\.-_]+)/' => 'PhamePostListController',
|
||||
|
@ -54,6 +55,7 @@ final class PhabricatorApplicationPhame extends PhabricatorApplication {
|
|||
'view/(?P<id>\d+)/' => 'PhamePostViewController',
|
||||
'publish/(?P<id>\d+)/' => 'PhamePostPublishController',
|
||||
'unpublish/(?P<id>\d+)/' => 'PhamePostUnpublishController',
|
||||
'notlive/(?P<id>\d+)/' => 'PhamePostNotLiveController',
|
||||
'preview/' => 'PhamePostPreviewController',
|
||||
'framed/(?P<id>\d+)/' => 'PhamePostFramedController',
|
||||
'new/' => 'PhamePostNewController',
|
||||
|
@ -63,7 +65,6 @@ final class PhabricatorApplicationPhame extends PhabricatorApplication {
|
|||
'delete/(?P<id>[^/]+)/' => 'PhameBlogDeleteController',
|
||||
'edit/(?P<id>[^/]+)/' => 'PhameBlogEditController',
|
||||
'view/(?P<id>[^/]+)/' => 'PhameBlogViewController',
|
||||
'live/(?P<id>[^/]+)/(?P<more>.*)' => 'PhameBlogLiveController',
|
||||
'new/' => 'PhameBlogEditController',
|
||||
),
|
||||
'posts/' => array(
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
final class PhameBlogLiveController extends PhameController {
|
||||
|
||||
private $id;
|
||||
private $more;
|
||||
|
||||
public function shouldAllowPublic() {
|
||||
return true;
|
||||
|
@ -29,71 +30,50 @@ final class PhameBlogLiveController extends PhameController {
|
|||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->id = idx($data, 'id');
|
||||
$this->more = idx($data, 'more', '');
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
// NOTE: We're loading with the logged-out user so we can raise the right
|
||||
// error if the blog permissions aren't set correctly.
|
||||
|
||||
$blog = null;
|
||||
$policy_exception = null;
|
||||
|
||||
try {
|
||||
$blog = id(new PhameBlogQuery())
|
||||
->setViewer(new PhabricatorUser())
|
||||
->withIDs(array($this->id))
|
||||
->executeOne();
|
||||
} catch (PhabricatorPolicyException $ex) {
|
||||
$policy_exception = $ex;
|
||||
}
|
||||
|
||||
if (!$blog && !$policy_exception) {
|
||||
$blog = id(new PhameBlogQuery())
|
||||
->setViewer($user)
|
||||
->withIDs(array($this->id))
|
||||
->executeOne();
|
||||
if (!$blog) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$errors = array();
|
||||
if ($policy_exception) {
|
||||
$errors[] = pht('"Visible To" must be set to "Public".');
|
||||
}
|
||||
|
||||
if ($blog && !$blog->getDomain()) {
|
||||
$errors[] = pht('You must configure a custom domain.');
|
||||
}
|
||||
|
||||
if ($errors) {
|
||||
if ($blog) {
|
||||
$cancel_uri = $this->getApplicationURI('/blog/view/'.$blog->getID());
|
||||
} else {
|
||||
$cancel_uri = $this->getApplicationURI();
|
||||
}
|
||||
|
||||
$dialog = id(new AphrontDialogView())
|
||||
->setUser($user)
|
||||
->addCancelButton($cancel_uri)
|
||||
->setTitle(pht('Live Blog Unavailable'));
|
||||
|
||||
foreach ($errors as $error) {
|
||||
$dialog->appendChild('<p>'.$error.'</p>');
|
||||
}
|
||||
|
||||
return id(new AphrontDialogResponse())->setDialog($dialog);
|
||||
}
|
||||
|
||||
if ($request->getHost() != $blog->getDomain()) {
|
||||
$uri = 'http://'.$blog->getDomain().'/';
|
||||
return id(new AphrontRedirectResponse())->setURI($uri);
|
||||
if ($blog->getDomain() && ($request->getHost() != $blog->getDomain())) {
|
||||
return id(new AphrontRedirectResponse())
|
||||
->setURI('http://'.$blog->getDomain().'/'.$this->more);
|
||||
}
|
||||
|
||||
$pager = id(new AphrontCursorPagerView())
|
||||
->readFromRequest($request);
|
||||
|
||||
$posts = id(new PhamePostQuery())
|
||||
$query = id(new PhamePostQuery())
|
||||
->setViewer($user)
|
||||
->withBlogPHIDs(array($blog->getPHID()))
|
||||
->executeWithCursorPager($pager);
|
||||
->withBlogPHIDs(array($blog->getPHID()));
|
||||
|
||||
$matches = null;
|
||||
$path = $this->more;
|
||||
if (preg_match('@^/(?P<view>[^/]+)/(?P<name>.*)$@', $path, $matches)) {
|
||||
$view = $matches['view'];
|
||||
$name = $matches['name'];
|
||||
} else {
|
||||
$view = '';
|
||||
$name = '';
|
||||
}
|
||||
|
||||
switch ($view) {
|
||||
case 'post':
|
||||
$query->withPhameTitles(array($name));
|
||||
break;
|
||||
}
|
||||
|
||||
$posts = $query->executeWithCursorPager($pager);
|
||||
|
||||
$skin = $blog->getSkinRenderer();
|
||||
$skin
|
||||
|
|
|
@ -144,14 +144,11 @@ final class PhameBlogViewController extends PhameController {
|
|||
->setDisabled(!$can_join)
|
||||
->setWorkflow(!$can_join));
|
||||
|
||||
$has_domain = $blog->getDomain();
|
||||
$actions->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
->setIcon('world')
|
||||
->setHref($this->getApplicationURI('blog/live/'.$blog->getID().'/'))
|
||||
->setName(pht('View Live'))
|
||||
->setDisabled(!$has_domain)
|
||||
->setWorkflow(true));
|
||||
->setHref($this->getApplicationURI('live/'.$blog->getID().'/'))
|
||||
->setName(pht('View Live')));
|
||||
|
||||
$actions->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @group phame
|
||||
*/
|
||||
final class PhamePostNotLiveController extends PhameController {
|
||||
|
||||
private $id;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->id = $data['id'];
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
$post = id(new PhamePostQuery())
|
||||
->setViewer($user)
|
||||
->withIDs(array($this->id))
|
||||
->executeOne();
|
||||
if (!$post) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$reasons = array();
|
||||
if (!$post->getBlog()) {
|
||||
$reasons[] =
|
||||
'<p>'.pht('You can not view the live version of this post because it '.
|
||||
'is not associated with a blog. Edit the post and choose a blog to '.
|
||||
'publish it to.').'</p>';
|
||||
}
|
||||
|
||||
if ($post->isDraft()) {
|
||||
$reasons[] =
|
||||
'<p>'.pht('You can not view the live version of this post because it '.
|
||||
'is still a draft. Use "Preview/Publish" to publish the post.').'</p>';
|
||||
}
|
||||
|
||||
if ($reasons) {
|
||||
$cancel_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/');
|
||||
|
||||
$dialog = id(new AphrontDialogView())
|
||||
->setUser($user)
|
||||
->setTitle(pht('Post Not Live'))
|
||||
->addCancelButton($cancel_uri);
|
||||
|
||||
foreach ($reasons as $reason) {
|
||||
$dialog->appendChild($reason);
|
||||
}
|
||||
|
||||
return id(new AphrontDialogResponse())->setDialog($dialog);
|
||||
}
|
||||
|
||||
// No reason this can't go live, maybe an old link. Kick them live and see
|
||||
// what happens.
|
||||
|
||||
$blog = $post->getBlog();
|
||||
$live_uri = 'http://'.$blog->getDomain().'/'.$post->getPhameTitle();
|
||||
|
||||
return id(new AphrontRedirectResponse())->setURI($live_uri);
|
||||
}
|
||||
}
|
|
@ -115,15 +115,23 @@ final class PhamePostViewController extends PhameController {
|
|||
->setDisabled(!$can_edit)
|
||||
->setWorkflow(!$can_edit));
|
||||
|
||||
$can_view_live = $post->getBlog() && !$post->isDraft();
|
||||
$blog = $post->getBlog();
|
||||
$can_view_live = $blog && !$post->isDraft();
|
||||
|
||||
if ($can_view_live) {
|
||||
$live_uri = 'live/'.$blog->getID().'/post/'.$post->getPhameTitle();
|
||||
} else {
|
||||
$live_uri = 'post/notlive/'.$post->getID().'/';
|
||||
}
|
||||
$live_uri = $this->getApplicationURI($live_uri);
|
||||
|
||||
$actions->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
->setIcon('world')
|
||||
->setHref($this->getApplicationURI('post/live/'.$id.'/'))
|
||||
->setHref($live_uri)
|
||||
->setName(pht('View Live'))
|
||||
->setDisabled(!$can_view_live)
|
||||
->setWorkflow(true));
|
||||
->setWorkflow(!$can_view_live));
|
||||
|
||||
if ($post->isDraft()) {
|
||||
$actions->addAction(
|
||||
|
|
|
@ -24,7 +24,6 @@ final class PhameBlog extends PhameDAO
|
|||
|
||||
const MARKUP_FIELD_DESCRIPTION = 'markup:description';
|
||||
|
||||
|
||||
const SKIN_DEFAULT = 'PhabricatorBlogSkin';
|
||||
|
||||
protected $id;
|
||||
|
|
|
@ -182,7 +182,8 @@ final class PhamePost extends PhameDAO
|
|||
|
||||
|
||||
public function getMarkupFieldKey($field) {
|
||||
return $this->getPHID().':'.$field;
|
||||
$hash = PhabricatorHash::digest($this->getMarkupText($field));
|
||||
return $this->getPHID().':'.$field.':'.$hash;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue