3 final class PhameBlogHeaderPictureController
4 extends PhameBlogController
{
6 public function handleRequest(AphrontRequest
$request) {
7 $viewer = $request->getViewer();
8 $id = $request->getURIData('id');
10 $blog = id(new PhameBlogQuery())
13 ->needHeaderImage(true)
14 ->requireCapabilities(
16 PhabricatorPolicyCapability
::CAN_VIEW
,
17 PhabricatorPolicyCapability
::CAN_EDIT
,
21 return new Aphront404Response();
24 $blog_uri = '/phame/blog/manage/'.$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 blog 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($blog->getPHID());
59 $new_value = $file->getPHID();
63 $xactions[] = id(new PhameBlogTransaction())
64 ->setTransactionType(PhameBlogHeaderImageTransaction
::TRANSACTIONTYPE
)
65 ->setNewValue($new_value);
67 $editor = id(new PhameBlogEditor())
69 ->setContentSourceFromRequest($request)
70 ->setContinueOnMissingFields(true)
71 ->setContinueOnNoEffect(true);
73 $editor->applyTransactions($blog, $xactions);
75 return id(new AphrontRedirectResponse())->setURI($blog_uri);
79 $title = pht('Edit Blog 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($blog_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('blog/'));
114 $crumbs->addTextCrumb(
116 $this->getApplicationURI('blog/view/'.$id));
117 $crumbs->addTextCrumb(pht('Blog Header'));
118 $crumbs->setBorder(true);
120 $header = id(new PHUIHeaderView())
121 ->setHeader(pht('Edit Blog Header'))
122 ->setHeaderIcon('fa-camera');
124 $view = id(new PHUITwoColumnView())
130 return $this->newPage()