3 final class PhamePostHeaderPictureController
4 extends PhamePostController
{
6 public function handleRequest(AphrontRequest
$request) {
7 $viewer = $request->getViewer();
8 $id = $request->getURIData('id');
10 $post = id(new PhamePostQuery())
13 ->needHeaderImage(true)
14 ->requireCapabilities(
16 PhabricatorPolicyCapability
::CAN_VIEW
,
17 PhabricatorPolicyCapability
::CAN_EDIT
,
21 return new Aphront404Response();
24 $post_uri = '/phame/post/view/'.$id;
26 $supported_formats = PhabricatorFile
::getTransformableImageFormats();
29 $delete_header = ($request->getInt('delete') == 1);
31 if ($request->isFormPost()) {
32 if ($request->getFileExists('header')) {
33 $file = PhabricatorFile
::newFromPHPUpload(
36 'authorPHID' => $viewer->getPHID(),
39 } else if (!$delete_header) {
40 $e_file = pht('Required');
42 'You must choose a file when uploading a new post header.');
45 if (!$errors && !$delete_header) {
46 if (!$file->isTransformableImage()) {
47 $e_file = pht('Not Supported');
49 'This server only supports these image formats: %s.',
50 implode(', ', $supported_formats));
58 $file->attachToObject($post->getPHID());
59 $new_value = $file->getPHID();
63 $xactions[] = id(new PhamePostTransaction())
64 ->setTransactionType(PhamePostHeaderImageTransaction
::TRANSACTIONTYPE
)
65 ->setNewValue($new_value);
67 $editor = id(new PhamePostEditor())
69 ->setContentSourceFromRequest($request)
70 ->setContinueOnMissingFields(true)
71 ->setContinueOnNoEffect(true);
73 $editor->applyTransactions($post, $xactions);
75 return id(new AphrontRedirectResponse())->setURI($post_uri);
79 $title = pht('Edit Post Header');
81 $upload_form = id(new AphrontFormView())
83 ->setEncType('multipart/form-data')
85 id(new AphrontFormFileControl())
87 ->setLabel(pht('Upload Header'))
90 pht('Supported formats: %s', implode(', ', $supported_formats))))
92 id(new AphrontFormCheckboxControl())
94 ->setLabel(pht('Delete Header'))
101 id(new AphrontFormSubmitControl())
102 ->addCancelButton($post_uri)
103 ->setValue(pht('Upload Header')));
105 $upload_box = id(new PHUIObjectBoxView())
106 ->setHeaderText(pht('Upload New Header'))
107 ->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
)
108 ->setForm($upload_form);
110 $crumbs = $this->buildApplicationCrumbs();
111 $crumbs->addTextCrumb(
113 $this->getApplicationURI('post/view/'.$id));
114 $crumbs->addTextCrumb(pht('Post Header'));
115 $crumbs->setBorder(true);
117 $header = id(new PHUIHeaderView())
118 ->setHeader(pht('Edit Post Header'))
119 ->setHeaderIcon('fa-camera');
121 $view = id(new PHUITwoColumnView())
127 return $this->newPage()