From 9c94bf1bea3f1dd64d9980fccc94bd3b0939dad5 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 15 Oct 2012 14:51:30 -0700 Subject: [PATCH] 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 --- src/__phutil_library_map__.php | 4 + .../AphrontApplicationConfiguration.php | 2 +- .../PhabricatorApplicationPhame.php | 3 +- .../blog/PhameBlogLiveController.php | 80 +++++++------------ .../blog/PhameBlogViewController.php | 7 +- .../post/PhamePostNotLiveController.php | 79 ++++++++++++++++++ .../post/PhamePostViewController.php | 14 +++- src/applications/phame/storage/PhameBlog.php | 1 - src/applications/phame/storage/PhamePost.php | 3 +- 9 files changed, 131 insertions(+), 62 deletions(-) create mode 100644 src/applications/phame/controller/post/PhamePostNotLiveController.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 4c866c6cb8..eac0000185 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/aphront/configuration/AphrontApplicationConfiguration.php b/src/aphront/configuration/AphrontApplicationConfiguration.php index dabe7e40e1..2f180f8d44 100644 --- a/src/aphront/configuration/AphrontApplicationConfiguration.php +++ b/src/aphront/configuration/AphrontApplicationConfiguration.php @@ -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); diff --git a/src/applications/phame/application/PhabricatorApplicationPhame.php b/src/applications/phame/application/PhabricatorApplicationPhame.php index 072dbd0255..5867f9d194 100644 --- a/src/applications/phame/application/PhabricatorApplicationPhame.php +++ b/src/applications/phame/application/PhabricatorApplicationPhame.php @@ -46,6 +46,7 @@ final class PhabricatorApplicationPhame extends PhabricatorApplication { return array( '/phame/' => array( '' => 'PhamePostListController', + 'live/(?P[^/]+)/(?P.*)' => 'PhameBlogLiveController', 'post/' => array( '(?:(?Pdraft|all)/)?' => 'PhamePostListController', 'blogger/(?P[\w\.-_]+)/' => 'PhamePostListController', @@ -54,6 +55,7 @@ final class PhabricatorApplicationPhame extends PhabricatorApplication { 'view/(?P\d+)/' => 'PhamePostViewController', 'publish/(?P\d+)/' => 'PhamePostPublishController', 'unpublish/(?P\d+)/' => 'PhamePostUnpublishController', + 'notlive/(?P\d+)/' => 'PhamePostNotLiveController', 'preview/' => 'PhamePostPreviewController', 'framed/(?P\d+)/' => 'PhamePostFramedController', 'new/' => 'PhamePostNewController', @@ -63,7 +65,6 @@ final class PhabricatorApplicationPhame extends PhabricatorApplication { 'delete/(?P[^/]+)/' => 'PhameBlogDeleteController', 'edit/(?P[^/]+)/' => 'PhameBlogEditController', 'view/(?P[^/]+)/' => 'PhameBlogViewController', - 'live/(?P[^/]+)/(?P.*)' => 'PhameBlogLiveController', 'new/' => 'PhameBlogEditController', ), 'posts/' => array( diff --git a/src/applications/phame/controller/blog/PhameBlogLiveController.php b/src/applications/phame/controller/blog/PhameBlogLiveController.php index 7982b06d18..9b6b76a72e 100644 --- a/src/applications/phame/controller/blog/PhameBlogLiveController.php +++ b/src/applications/phame/controller/blog/PhameBlogLiveController.php @@ -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('

'.$error.'

'); - } - - 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[^/]+)/(?P.*)$@', $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 diff --git a/src/applications/phame/controller/blog/PhameBlogViewController.php b/src/applications/phame/controller/blog/PhameBlogViewController.php index 058b7c0d80..7533d0b86b 100644 --- a/src/applications/phame/controller/blog/PhameBlogViewController.php +++ b/src/applications/phame/controller/blog/PhameBlogViewController.php @@ -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()) diff --git a/src/applications/phame/controller/post/PhamePostNotLiveController.php b/src/applications/phame/controller/post/PhamePostNotLiveController.php new file mode 100644 index 0000000000..9676a11ad8 --- /dev/null +++ b/src/applications/phame/controller/post/PhamePostNotLiveController.php @@ -0,0 +1,79 @@ +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[] = + '

'.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.').'

'; + } + + if ($post->isDraft()) { + $reasons[] = + '

'.pht('You can not view the live version of this post because it '. + 'is still a draft. Use "Preview/Publish" to publish the post.').'

'; + } + + 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); + } +} diff --git a/src/applications/phame/controller/post/PhamePostViewController.php b/src/applications/phame/controller/post/PhamePostViewController.php index 74cf64dff8..affbfbda81 100644 --- a/src/applications/phame/controller/post/PhamePostViewController.php +++ b/src/applications/phame/controller/post/PhamePostViewController.php @@ -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( diff --git a/src/applications/phame/storage/PhameBlog.php b/src/applications/phame/storage/PhameBlog.php index 6e4b6e1167..3c6b867d85 100644 --- a/src/applications/phame/storage/PhameBlog.php +++ b/src/applications/phame/storage/PhameBlog.php @@ -24,7 +24,6 @@ final class PhameBlog extends PhameDAO const MARKUP_FIELD_DESCRIPTION = 'markup:description'; - const SKIN_DEFAULT = 'PhabricatorBlogSkin'; protected $id; diff --git a/src/applications/phame/storage/PhamePost.php b/src/applications/phame/storage/PhamePost.php index bebce50589..c9143141d2 100644 --- a/src/applications/phame/storage/PhamePost.php +++ b/src/applications/phame/storage/PhamePost.php @@ -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; }