Skip to content

Commit dd82cd4

Browse files
committed
Clean up Phame Preview
Summary: This adds a separate Publish/Unpublish step aside from Preview in Phame Posts. This allows easier access to publishing without previewing, though I left publish in tact on the preview page. Also cleaned up some minor transaction issues with mail. Test Plan: New Post, Publish Post, Preview Post. Check mail logs. Get mail upon publish. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D14642
1 parent 9104867 commit dd82cd4

File tree

8 files changed

+127
-51
lines changed

8 files changed

+127
-51
lines changed

src/__phutil_library_map__.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3331,6 +3331,7 @@
33313331
'PhamePostMailReceiver' => 'applications/phame/mail/PhamePostMailReceiver.php',
33323332
'PhamePostNewController' => 'applications/phame/controller/post/PhamePostNewController.php',
33333333
'PhamePostNotLiveController' => 'applications/phame/controller/post/PhamePostNotLiveController.php',
3334+
'PhamePostPreviewController' => 'applications/phame/controller/post/PhamePostPreviewController.php',
33343335
'PhamePostPublishController' => 'applications/phame/controller/post/PhamePostPublishController.php',
33353336
'PhamePostQuery' => 'applications/phame/query/PhamePostQuery.php',
33363337
'PhamePostReplyHandler' => 'applications/phame/mail/PhamePostReplyHandler.php',
@@ -7670,6 +7671,7 @@
76707671
'PhamePostMailReceiver' => 'PhabricatorObjectMailReceiver',
76717672
'PhamePostNewController' => 'PhamePostController',
76727673
'PhamePostNotLiveController' => 'PhamePostController',
7674+
'PhamePostPreviewController' => 'PhamePostController',
76737675
'PhamePostPublishController' => 'PhamePostController',
76747676
'PhamePostQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
76757677
'PhamePostReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',

src/applications/phame/application/PhabricatorPhameApplication.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function getRoutes() {
4747
'edit/(?:(?P<id>[^/]+)/)?' => 'PhamePostEditController',
4848
'view/(?P<id>\d+)/' => 'PhamePostViewController',
4949
'publish/(?P<id>\d+)/' => 'PhamePostPublishController',
50+
'preview/(?P<id>\d+)/' => 'PhamePostPreviewController',
5051
'unpublish/(?P<id>\d+)/' => 'PhamePostUnpublishController',
5152
'notlive/(?P<id>\d+)/' => 'PhamePostNotLiveController',
5253
'preview/' => 'PhabricatorMarkupPreviewController',
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
final class PhamePostPreviewController extends PhamePostController {
4+
5+
public function handleRequest(AphrontRequest $request) {
6+
$viewer = $request->getViewer();
7+
$id = $request->getURIData('id');
8+
9+
$post = id(new PhamePostQuery())
10+
->setViewer($viewer)
11+
->withIDs(array($id))
12+
->requireCapabilities(
13+
array(
14+
PhabricatorPolicyCapability::CAN_EDIT,
15+
))
16+
->executeOne();
17+
if (!$post) {
18+
return new Aphront404Response();
19+
}
20+
21+
$view_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/');
22+
23+
if ($request->isFormPost()) {
24+
$xactions = array();
25+
$xactions[] = id(new PhamePostTransaction())
26+
->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY)
27+
->setNewValue(PhameConstants::VISIBILITY_PUBLISHED);
28+
29+
id(new PhamePostEditor())
30+
->setActor($viewer)
31+
->setContentSourceFromRequest($request)
32+
->setContinueOnNoEffect(true)
33+
->setContinueOnMissingFields(true)
34+
->applyTransactions($post, $xactions);
35+
36+
return id(new AphrontRedirectResponse())->setURI($view_uri);
37+
}
38+
39+
$form = id(new AphrontFormView())
40+
->setUser($viewer)
41+
->appendChild(
42+
id(new AphrontFormSubmitControl())
43+
->setValue(pht('Publish Post'))
44+
->addCancelButton($view_uri));
45+
46+
$frame = $this->renderPreviewFrame($post);
47+
48+
$form_box = id(new PHUIObjectBoxView())
49+
->setHeaderText(pht('Preview Post'))
50+
->setForm($form);
51+
52+
$blog = $post->getBlog();
53+
54+
$crumbs = $this->buildApplicationCrumbs();
55+
$crumbs->addTextCrumb(
56+
$blog->getName(),
57+
$this->getApplicationURI('blog/view/'.$blog->getID().'/'));
58+
$crumbs->addTextCrumb(pht('Preview Post'), $view_uri);
59+
60+
return $this->newPage()
61+
->setTitle(pht('Preview Post'))
62+
->setCrumbs($crumbs)
63+
->appendChild(
64+
array(
65+
$form_box,
66+
$frame,
67+
));
68+
}
69+
70+
private function renderPreviewFrame(PhamePost $post) {
71+
72+
return phutil_tag(
73+
'div',
74+
array(
75+
'style' => 'text-align: center; padding: 16px;',
76+
),
77+
phutil_tag(
78+
'iframe',
79+
array(
80+
'style' => 'width: 100%; height: 800px; '.
81+
'border: 1px solid #BFCFDA; '.
82+
'background-color: #fff; '.
83+
'border-radius: 3px; ',
84+
'src' => $this->getApplicationURI('/post/framed/'.$post->getID().'/'),
85+
),
86+
''));
87+
}
88+
89+
}

src/applications/phame/controller/post/PhamePostPublishController.php

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ public function handleRequest(AphrontRequest $request) {
1818
return new Aphront404Response();
1919
}
2020

21-
$view_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/');
22-
2321
if ($request->isFormPost()) {
2422
$xactions = array();
2523
$xactions[] = id(new PhamePostTransaction())
@@ -33,52 +31,22 @@ public function handleRequest(AphrontRequest $request) {
3331
->setContinueOnMissingFields(true)
3432
->applyTransactions($post, $xactions);
3533

36-
return id(new AphrontRedirectResponse())->setURI($view_uri);
34+
return id(new AphrontRedirectResponse())
35+
->setURI($this->getApplicationURI('/post/view/'.$post->getID().'/'));
3736
}
3837

39-
$form = id(new AphrontFormView())
40-
->setUser($viewer)
41-
->appendChild(
42-
id(new AphrontFormSubmitControl())
43-
->setValue(pht('Publish Post'))
44-
->addCancelButton($view_uri));
45-
46-
$frame = $this->renderPreviewFrame($post);
47-
48-
$form_box = id(new PHUIObjectBoxView())
49-
->setHeaderText(pht('Preview Post'))
50-
->setForm($form);
51-
52-
$crumbs = $this->buildApplicationCrumbs();
53-
$crumbs->addTextCrumb(pht('Preview'), $view_uri);
38+
$cancel_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/');
5439

55-
return $this->newPage()
56-
->setTitle(pht('Preview Post'))
57-
->setCrumbs($crumbs)
40+
$dialog = $this->newDialog()
41+
->setTitle(pht('Publish Post?'))
5842
->appendChild(
59-
array(
60-
$form_box,
61-
$frame,
62-
));
63-
}
43+
pht(
44+
'The post "%s" will go live once you publish it.',
45+
$post->getTitle()))
46+
->addSubmitButton(pht('Publish'))
47+
->addCancelButton($cancel_uri);
6448

65-
private function renderPreviewFrame(PhamePost $post) {
66-
67-
return phutil_tag(
68-
'div',
69-
array(
70-
'style' => 'text-align: center; padding: 16px;',
71-
),
72-
phutil_tag(
73-
'iframe',
74-
array(
75-
'style' => 'width: 100%; height: 600px; '.
76-
'border: 1px solid #BFCFDA; '.
77-
'background-color: #fff; '.
78-
'border-radius: 3px; ',
79-
'src' => $this->getApplicationURI('/post/framed/'.$post->getID().'/'),
80-
),
81-
''));
49+
return id(new AphrontDialogResponse())->setDialog($dialog);
8250
}
8351

8452
}

src/applications/phame/controller/post/PhamePostUnpublishController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ public function handleRequest(AphrontRequest $request) {
3737

3838
$cancel_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/');
3939

40-
$dialog = id(new AphrontDialogView())
41-
->setUser($viewer)
40+
$dialog = $this->newDialog()
4241
->setTitle(pht('Unpublish Post?'))
4342
->appendChild(
4443
pht(

src/applications/phame/controller/post/PhamePostViewController.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function handleRequest(AphrontRequest $request) {
6363
->appendChild(
6464
pht(
6565
'Only you can see this draft until you publish it. '.
66-
'Use "Preview / Publish" to publish this post.')));
66+
'Use "Preview or Publish" to publish this post.')));
6767
}
6868

6969
if (!$post->getBlog()) {
@@ -150,7 +150,14 @@ private function renderActions(
150150
->setIcon('fa-eye')
151151
->setHref($this->getApplicationURI('post/publish/'.$id.'/'))
152152
->setDisabled(!$can_edit)
153-
->setName(pht('Preview / Publish')));
153+
->setName(pht('Publish'))
154+
->setWorkflow(true));
155+
$actions->addAction(
156+
id(new PhabricatorActionView())
157+
->setIcon('fa-eye')
158+
->setHref($this->getApplicationURI('post/preview/'.$id.'/'))
159+
->setDisabled(!$can_edit)
160+
->setName(pht('Preview in Skin')));
154161
} else {
155162
$actions->addAction(
156163
id(new PhabricatorActionView())

src/applications/phame/editor/PhamePostEditor.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,21 @@ protected function buildMailBody(
209209

210210
$body = parent::buildMailBody($object, $xactions);
211211

212+
// We don't send mail if the object is a draft, and we only want
213+
// to include the full body of the post on the either the
214+
// first creation or if it was created as a draft, once it goes live.
212215
if ($this->getIsNewObject()) {
213216
$body->addRemarkupSection(null, $object->getBody());
217+
} else {
218+
foreach ($xactions as $xaction) {
219+
switch ($xaction->getTransactionType()) {
220+
case PhamePostTransaction::TYPE_VISIBILITY:
221+
if (!$object->isDraft()) {
222+
$body->addRemarkupSection(null, $object->getBody());
223+
}
224+
break;
225+
}
226+
}
214227
}
215228

216229
$body->addLinkSection(

src/applications/phame/storage/PhamePostTransaction.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,7 @@ public function getBodyForFeed(PhabricatorFeedStory $story) {
206206
}
207207

208208
if (strlen($text)) {
209-
return phutil_escape_html_newlines(
210-
id(new PhutilUTF8StringTruncator())
211-
->setMaximumGlyphs(128)
212-
->truncateString($text));
209+
return PhabricatorMarkupEngine::summarize($text);
213210
}
214211

215212
return parent::getBodyForFeed($story);

0 commit comments

Comments
 (0)