Differential D16140 Diff 38830 src/applications/phame/controller/blog/PhameBlogHeaderPictureController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phame/controller/blog/PhameBlogHeaderPictureController.php
- This file was added.
<?php | |||||
final class PhameBlogHeaderPictureController | |||||
extends PhameBlogController { | |||||
public function handleRequest(AphrontRequest $request) { | |||||
$viewer = $request->getViewer(); | |||||
$id = $request->getURIData('id'); | |||||
epriestley: You should be able to get rid of this method, this should be the default behavior. | |||||
$blog = id(new PhameBlogQuery()) | |||||
->setViewer($viewer) | |||||
->withIDs(array($id)) | |||||
->needHeaderImage(true) | |||||
->requireCapabilities( | |||||
array( | |||||
PhabricatorPolicyCapability::CAN_VIEW, | |||||
PhabricatorPolicyCapability::CAN_EDIT, | |||||
)) | |||||
->executeOne(); | |||||
if (!$blog) { | |||||
return new Aphront404Response(); | |||||
} | |||||
$blog_uri = '/phame/blog/manage/'.$id; | |||||
$supported_formats = PhabricatorFile::getTransformableImageFormats(); | |||||
$e_file = true; | |||||
$errors = array(); | |||||
$delete_header = ($request->getInt('delete') == 1); | |||||
if ($request->isFormPost()) { | |||||
if ($request->getFileExists('header')) { | |||||
$file = PhabricatorFile::newFromPHPUpload( | |||||
$_FILES['header'], | |||||
array( | |||||
'authorPHID' => $viewer->getPHID(), | |||||
'canCDN' => true, | |||||
)); | |||||
} else if (!$delete_header) { | |||||
$e_file = pht('Required'); | |||||
$errors[] = pht( | |||||
'You must choose a file when uploading a new blog header.'); | |||||
} | |||||
if (!$errors && !$delete_header) { | |||||
if (!$file->isTransformableImage()) { | |||||
$e_file = pht('Not Supported'); | |||||
$errors[] = pht( | |||||
'This server only supports these image formats: %s.', | |||||
implode(', ', $supported_formats)); | |||||
} | |||||
} | |||||
if (!$errors) { | |||||
if ($delete_header) { | |||||
$blog->setHeaderImagePHID(null); | |||||
} else { | |||||
$blog->setHeaderImagePHID($file->getPHID()); | |||||
$file->attachToObject($blog->getPHID()); | |||||
} | |||||
$blog->save(); | |||||
return id(new AphrontRedirectResponse())->setURI($blog_uri); | |||||
} | |||||
} | |||||
$title = pht('Edit Blog Header'); | |||||
Done Inline ActionsThis should become a transaction at some point, PhabricatorProjectTransaction::TYPE_IMAGE starting in PhabricatorProjectEditPictureController is an example, I think. But I may modularize all of these under T9789 while doing the custom domain stuff anyway, and swapping this for a transaction is easy to do in a followup. epriestley: This should become a transaction at some point, `PhabricatorProjectTransaction::TYPE_IMAGE`… | |||||
$upload_form = id(new AphrontFormView()) | |||||
->setUser($viewer) | |||||
->setEncType('multipart/form-data') | |||||
->appendChild( | |||||
id(new AphrontFormFileControl()) | |||||
->setName('header') | |||||
->setLabel(pht('Upload Header')) | |||||
->setError($e_file) | |||||
->setCaption( | |||||
pht('Supported formats: %s', implode(', ', $supported_formats)))) | |||||
->appendChild( | |||||
id(new AphrontFormCheckboxControl()) | |||||
->setName('delete') | |||||
->setLabel(pht('Delete Header')) | |||||
->addCheckbox( | |||||
'delete', | |||||
1, | |||||
null, | |||||
null)) | |||||
->appendChild( | |||||
id(new AphrontFormSubmitControl()) | |||||
->addCancelButton($blog_uri) | |||||
->setValue(pht('Upload Header'))); | |||||
$upload_box = id(new PHUIObjectBoxView()) | |||||
->setHeaderText(pht('Upload New Header')) | |||||
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | |||||
->setForm($upload_form); | |||||
$crumbs = $this->buildApplicationCrumbs(); | |||||
$crumbs->addTextCrumb( | |||||
pht('Blogs'), | |||||
$this->getApplicationURI('blog/')); | |||||
$crumbs->addTextCrumb( | |||||
$blog->getName(), | |||||
$this->getApplicationURI('blog/view/'.$id)); | |||||
$crumbs->addTextCrumb(pht('Blog Header')); | |||||
$crumbs->setBorder(true); | |||||
$header = id(new PHUIHeaderView()) | |||||
->setHeader(pht('Edit Blog Header')) | |||||
->setHeaderIcon('fa-camera'); | |||||
$view = id(new PHUITwoColumnView()) | |||||
->setHeader($header) | |||||
->setFooter(array( | |||||
$upload_box, | |||||
)); | |||||
return $this->newPage() | |||||
->setTitle($title) | |||||
->setCrumbs($crumbs) | |||||
->appendChild( | |||||
array( | |||||
$view, | |||||
)); | |||||
} | |||||
} |
You should be able to get rid of this method, this should be the default behavior.