1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-17 01:08: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:
epriestley 2012-10-15 14:51:30 -07:00
parent 0c4eb79d3a
commit 9c94bf1bea
9 changed files with 131 additions and 62 deletions

View file

@ -1167,6 +1167,7 @@ phutil_register_library_map(array(
'PhamePostListController' => 'applications/phame/controller/post/PhamePostListController.php', 'PhamePostListController' => 'applications/phame/controller/post/PhamePostListController.php',
'PhamePostListView' => 'applications/phame/view/PhamePostListView.php', 'PhamePostListView' => 'applications/phame/view/PhamePostListView.php',
'PhamePostNewController' => 'applications/phame/controller/post/PhamePostNewController.php', 'PhamePostNewController' => 'applications/phame/controller/post/PhamePostNewController.php',
'PhamePostNotLiveController' => 'applications/phame/controller/post/PhamePostNotLiveController.php',
'PhamePostPreviewController' => 'applications/phame/controller/post/PhamePostPreviewController.php', 'PhamePostPreviewController' => 'applications/phame/controller/post/PhamePostPreviewController.php',
'PhamePostPublishController' => 'applications/phame/controller/post/PhamePostPublishController.php', 'PhamePostPublishController' => 'applications/phame/controller/post/PhamePostPublishController.php',
'PhamePostQuery' => 'applications/phame/query/PhamePostQuery.php', 'PhamePostQuery' => 'applications/phame/query/PhamePostQuery.php',
@ -2278,6 +2279,7 @@ phutil_register_library_map(array(
array( array(
0 => 'PhameDAO', 0 => 'PhameDAO',
1 => 'PhabricatorPolicyInterface', 1 => 'PhabricatorPolicyInterface',
2 => 'PhabricatorMarkupInterface',
), ),
'PhameBlogDeleteController' => 'PhameController', 'PhameBlogDeleteController' => 'PhameController',
'PhameBlogDetailView' => 'AphrontView', 'PhameBlogDetailView' => 'AphrontView',
@ -2293,6 +2295,7 @@ phutil_register_library_map(array(
array( array(
0 => 'PhameDAO', 0 => 'PhameDAO',
1 => 'PhabricatorPolicyInterface', 1 => 'PhabricatorPolicyInterface',
2 => 'PhabricatorMarkupInterface',
), ),
'PhamePostDeleteController' => 'PhameController', 'PhamePostDeleteController' => 'PhameController',
'PhamePostDetailView' => 'AphrontView', 'PhamePostDetailView' => 'AphrontView',
@ -2301,6 +2304,7 @@ phutil_register_library_map(array(
'PhamePostListController' => 'PhameController', 'PhamePostListController' => 'PhameController',
'PhamePostListView' => 'AphrontView', 'PhamePostListView' => 'AphrontView',
'PhamePostNewController' => 'PhameController', 'PhamePostNewController' => 'PhameController',
'PhamePostNotLiveController' => 'PhameController',
'PhamePostPreviewController' => 'PhameController', 'PhamePostPreviewController' => 'PhameController',
'PhamePostPublishController' => 'PhameController', 'PhamePostPublishController' => 'PhameController',
'PhamePostQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhamePostQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',

View file

@ -164,7 +164,7 @@ abstract class AphrontApplicationConfiguration {
// TODO: Make this more flexible and modular so any application can // TODO: Make this more flexible and modular so any application can
// do crazy stuff here if it wants. // do crazy stuff here if it wants.
$path = '/phame/blog/live/'.$blog->getID().'/'.$path; $path = '/phame/live/'.$blog->getID().'/'.$path;
$celerity = CelerityAPI::getStaticResourceResponse(); $celerity = CelerityAPI::getStaticResourceResponse();
$celerity->setUseFullURI(true); $celerity->setUseFullURI(true);

View file

@ -46,6 +46,7 @@ final class PhabricatorApplicationPhame extends PhabricatorApplication {
return array( return array(
'/phame/' => array( '/phame/' => array(
'' => 'PhamePostListController', '' => 'PhamePostListController',
'live/(?P<id>[^/]+)/(?P<more>.*)' => 'PhameBlogLiveController',
'post/' => array( 'post/' => array(
'(?:(?P<filter>draft|all)/)?' => 'PhamePostListController', '(?:(?P<filter>draft|all)/)?' => 'PhamePostListController',
'blogger/(?P<bloggername>[\w\.-_]+)/' => 'PhamePostListController', 'blogger/(?P<bloggername>[\w\.-_]+)/' => 'PhamePostListController',
@ -54,6 +55,7 @@ final class PhabricatorApplicationPhame extends PhabricatorApplication {
'view/(?P<id>\d+)/' => 'PhamePostViewController', 'view/(?P<id>\d+)/' => 'PhamePostViewController',
'publish/(?P<id>\d+)/' => 'PhamePostPublishController', 'publish/(?P<id>\d+)/' => 'PhamePostPublishController',
'unpublish/(?P<id>\d+)/' => 'PhamePostUnpublishController', 'unpublish/(?P<id>\d+)/' => 'PhamePostUnpublishController',
'notlive/(?P<id>\d+)/' => 'PhamePostNotLiveController',
'preview/' => 'PhamePostPreviewController', 'preview/' => 'PhamePostPreviewController',
'framed/(?P<id>\d+)/' => 'PhamePostFramedController', 'framed/(?P<id>\d+)/' => 'PhamePostFramedController',
'new/' => 'PhamePostNewController', 'new/' => 'PhamePostNewController',
@ -63,7 +65,6 @@ final class PhabricatorApplicationPhame extends PhabricatorApplication {
'delete/(?P<id>[^/]+)/' => 'PhameBlogDeleteController', 'delete/(?P<id>[^/]+)/' => 'PhameBlogDeleteController',
'edit/(?P<id>[^/]+)/' => 'PhameBlogEditController', 'edit/(?P<id>[^/]+)/' => 'PhameBlogEditController',
'view/(?P<id>[^/]+)/' => 'PhameBlogViewController', 'view/(?P<id>[^/]+)/' => 'PhameBlogViewController',
'live/(?P<id>[^/]+)/(?P<more>.*)' => 'PhameBlogLiveController',
'new/' => 'PhameBlogEditController', 'new/' => 'PhameBlogEditController',
), ),
'posts/' => array( 'posts/' => array(

View file

@ -22,6 +22,7 @@
final class PhameBlogLiveController extends PhameController { final class PhameBlogLiveController extends PhameController {
private $id; private $id;
private $more;
public function shouldAllowPublic() { public function shouldAllowPublic() {
return true; return true;
@ -29,71 +30,50 @@ final class PhameBlogLiveController extends PhameController {
public function willProcessRequest(array $data) { public function willProcessRequest(array $data) {
$this->id = idx($data, 'id'); $this->id = idx($data, 'id');
$this->more = idx($data, 'more', '');
} }
public function processRequest() { public function processRequest() {
$request = $this->getRequest(); $request = $this->getRequest();
$user = $request->getUser(); $user = $request->getUser();
// NOTE: We're loading with the logged-out user so we can raise the right $blog = id(new PhameBlogQuery())
// error if the blog permissions aren't set correctly. ->setViewer($user)
->withIDs(array($this->id))
$blog = null; ->executeOne();
$policy_exception = null; if (!$blog) {
try {
$blog = id(new PhameBlogQuery())
->setViewer(new PhabricatorUser())
->withIDs(array($this->id))
->executeOne();
} catch (PhabricatorPolicyException $ex) {
$policy_exception = $ex;
}
if (!$blog && !$policy_exception) {
return new Aphront404Response(); return new Aphront404Response();
} }
$errors = array(); if ($blog->getDomain() && ($request->getHost() != $blog->getDomain())) {
if ($policy_exception) { return id(new AphrontRedirectResponse())
$errors[] = pht('"Visible To" must be set to "Public".'); ->setURI('http://'.$blog->getDomain().'/'.$this->more);
}
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);
} }
$pager = id(new AphrontCursorPagerView()) $pager = id(new AphrontCursorPagerView())
->readFromRequest($request); ->readFromRequest($request);
$posts = id(new PhamePostQuery()) $query = id(new PhamePostQuery())
->setViewer($user) ->setViewer($user)
->withBlogPHIDs(array($blog->getPHID())) ->withBlogPHIDs(array($blog->getPHID()));
->executeWithCursorPager($pager);
$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 = $blog->getSkinRenderer();
$skin $skin

View file

@ -144,14 +144,11 @@ final class PhameBlogViewController extends PhameController {
->setDisabled(!$can_join) ->setDisabled(!$can_join)
->setWorkflow(!$can_join)); ->setWorkflow(!$can_join));
$has_domain = $blog->getDomain();
$actions->addAction( $actions->addAction(
id(new PhabricatorActionView()) id(new PhabricatorActionView())
->setIcon('world') ->setIcon('world')
->setHref($this->getApplicationURI('blog/live/'.$blog->getID().'/')) ->setHref($this->getApplicationURI('live/'.$blog->getID().'/'))
->setName(pht('View Live')) ->setName(pht('View Live')));
->setDisabled(!$has_domain)
->setWorkflow(true));
$actions->addAction( $actions->addAction(
id(new PhabricatorActionView()) id(new PhabricatorActionView())

View file

@ -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);
}
}

View file

@ -115,15 +115,23 @@ final class PhamePostViewController extends PhameController {
->setDisabled(!$can_edit) ->setDisabled(!$can_edit)
->setWorkflow(!$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( $actions->addAction(
id(new PhabricatorActionView()) id(new PhabricatorActionView())
->setIcon('world') ->setIcon('world')
->setHref($this->getApplicationURI('post/live/'.$id.'/')) ->setHref($live_uri)
->setName(pht('View Live')) ->setName(pht('View Live'))
->setDisabled(!$can_view_live) ->setDisabled(!$can_view_live)
->setWorkflow(true)); ->setWorkflow(!$can_view_live));
if ($post->isDraft()) { if ($post->isDraft()) {
$actions->addAction( $actions->addAction(

View file

@ -24,7 +24,6 @@ final class PhameBlog extends PhameDAO
const MARKUP_FIELD_DESCRIPTION = 'markup:description'; const MARKUP_FIELD_DESCRIPTION = 'markup:description';
const SKIN_DEFAULT = 'PhabricatorBlogSkin'; const SKIN_DEFAULT = 'PhabricatorBlogSkin';
protected $id; protected $id;

View file

@ -182,7 +182,8 @@ final class PhamePost extends PhameDAO
public function getMarkupFieldKey($field) { public function getMarkupFieldKey($field) {
return $this->getPHID().':'.$field; $hash = PhabricatorHash::digest($this->getMarkupText($field));
return $this->getPHID().':'.$field.':'.$hash;
} }