2013-01-25 02:23:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group conpherence
|
|
|
|
*/
|
|
|
|
final class ConpherenceUpdateController extends
|
|
|
|
ConpherenceController {
|
|
|
|
|
|
|
|
private $conpherenceID;
|
|
|
|
|
|
|
|
public function setConpherenceID($conpherence_id) {
|
|
|
|
$this->conpherenceID = $conpherence_id;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
public function getConpherenceID() {
|
|
|
|
return $this->conpherenceID;
|
|
|
|
}
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->setConpherenceID(idx($data, 'id'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
$conpherence_id = $this->getConpherenceID();
|
|
|
|
if (!$conpherence_id) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$conpherence = id(new ConpherenceThreadQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withIDs(array($conpherence_id))
|
|
|
|
->executeOne();
|
|
|
|
$supported_formats = PhabricatorFile::getTransformableImageFormats();
|
|
|
|
|
|
|
|
$updated = false;
|
|
|
|
$error_view = null;
|
2013-01-27 02:14:58 +01:00
|
|
|
$e_file = array();
|
2013-01-25 02:23:05 +01:00
|
|
|
$errors = array();
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$content_source = PhabricatorContentSource::newForSource(
|
|
|
|
PhabricatorContentSource::SOURCE_WEB,
|
|
|
|
array(
|
|
|
|
'ip' => $request->getRemoteAddr()
|
|
|
|
));
|
2013-01-27 04:56:39 +01:00
|
|
|
$editor = id(new ConpherenceEditor())
|
2013-01-30 01:53:57 +01:00
|
|
|
->setContinueOnNoEffect($request->isContinueRequest())
|
2013-01-27 04:56:39 +01:00
|
|
|
->setContentSource($content_source)
|
|
|
|
->setActor($user);
|
2013-01-25 02:23:05 +01:00
|
|
|
|
|
|
|
$action = $request->getStr('action');
|
|
|
|
switch ($action) {
|
|
|
|
case 'message':
|
|
|
|
$message = $request->getStr('text');
|
2013-01-27 04:56:39 +01:00
|
|
|
$xactions = $editor->generateTransactionsFromText(
|
|
|
|
$conpherence,
|
|
|
|
$message
|
|
|
|
);
|
2013-01-25 02:23:05 +01:00
|
|
|
break;
|
|
|
|
case 'metadata':
|
|
|
|
$xactions = array();
|
2013-01-27 02:14:58 +01:00
|
|
|
$images = $request->getArr('image');
|
|
|
|
if ($images) {
|
|
|
|
// just take the first one
|
|
|
|
$file_phid = reset($images);
|
|
|
|
$file = id(new PhabricatorFileQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withPHIDs(array($file_phid))
|
|
|
|
->executeOne();
|
|
|
|
$okay = $file->isTransformableImage();
|
|
|
|
if ($okay) {
|
|
|
|
$xformer = new PhabricatorImageTransformer();
|
|
|
|
$xformed = $xformer->executeThumbTransform(
|
|
|
|
$file,
|
|
|
|
$x = 50,
|
|
|
|
$y = 50);
|
|
|
|
$image_phid = $xformed->getPHID();
|
|
|
|
$xactions[] = id(new ConpherenceTransaction())
|
|
|
|
->setTransactionType(ConpherenceTransactionType::TYPE_PICTURE)
|
|
|
|
->setNewValue($image_phid);
|
|
|
|
} else {
|
|
|
|
$e_file[] = $file;
|
|
|
|
$errors[] =
|
|
|
|
pht('This server only supports these image formats: %s.',
|
2013-01-25 02:23:05 +01:00
|
|
|
implode(', ', $supported_formats));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$title = $request->getStr('title');
|
|
|
|
if ($title != $conpherence->getTitle()) {
|
|
|
|
$xactions[] = id(new ConpherenceTransaction())
|
|
|
|
->setTransactionType(ConpherenceTransactionType::TYPE_TITLE)
|
|
|
|
->setNewValue($title);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Exception('Unknown action: '.$action);
|
|
|
|
break;
|
|
|
|
}
|
2013-01-30 01:53:57 +01:00
|
|
|
if ($xactions) {
|
|
|
|
try {
|
|
|
|
$xactions = $editor->applyTransactions($conpherence, $xactions);
|
|
|
|
$updated = true;
|
|
|
|
} catch (PhabricatorApplicationTransactionNoEffectException $ex) {
|
|
|
|
return id(new PhabricatorApplicationTransactionNoEffectResponse())
|
|
|
|
->setCancelURI($this->getApplicationURI($conpherence_id.'/'))
|
|
|
|
->setException($ex);
|
|
|
|
}
|
|
|
|
} else if (empty($errors)) {
|
|
|
|
$errors[] = pht(
|
|
|
|
'That was a non-update. Try cancel.'
|
|
|
|
);
|
|
|
|
}
|
2013-01-25 02:23:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($updated) {
|
|
|
|
return id(new AphrontRedirectResponse())->setURI(
|
|
|
|
$this->getApplicationURI($conpherence_id.'/')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($errors) {
|
|
|
|
$error_view = id(new AphrontErrorView())
|
|
|
|
->setTitle(pht('Errors editing conpherence.'))
|
2013-01-27 02:14:58 +01:00
|
|
|
->setInsideDialogue(true)
|
2013-01-25 02:23:05 +01:00
|
|
|
->setErrors($errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
$form = id(new AphrontFormLayoutView())
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setLabel(pht('Title'))
|
|
|
|
->setName('title')
|
|
|
|
->setValue($conpherence->getTitle())
|
|
|
|
)
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormMarkupControl())
|
|
|
|
->setLabel(pht('Image'))
|
|
|
|
->setValue(phutil_render_tag(
|
|
|
|
'img',
|
|
|
|
array(
|
|
|
|
'src' => $conpherence->loadImageURI(),
|
|
|
|
))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
->appendChild(
|
2013-01-27 02:14:58 +01:00
|
|
|
id(new AphrontFormDragAndDropUploadControl())
|
2013-01-25 02:23:05 +01:00
|
|
|
->setLabel(pht('Change Image'))
|
|
|
|
->setName('image')
|
2013-01-27 02:14:58 +01:00
|
|
|
->setValue($e_file)
|
2013-01-25 02:23:05 +01:00
|
|
|
->setCaption('Supported formats: '.implode(', ', $supported_formats))
|
2013-01-27 02:14:58 +01:00
|
|
|
);
|
2013-01-25 02:23:05 +01:00
|
|
|
|
|
|
|
require_celerity_resource('conpherence-update-css');
|
2013-01-27 02:14:58 +01:00
|
|
|
return id(new AphrontDialogResponse())
|
|
|
|
->setDialog(
|
2013-01-25 02:23:05 +01:00
|
|
|
id(new AphrontDialogView())
|
|
|
|
->setUser($user)
|
|
|
|
->setTitle(pht('Update Conpherence'))
|
|
|
|
->setWidth(AphrontDialogView::WIDTH_FORM)
|
|
|
|
->setSubmitURI($this->getApplicationURI('update/'.$conpherence_id.'/'))
|
|
|
|
->addHiddenInput('action', 'metadata')
|
2013-01-27 02:14:58 +01:00
|
|
|
->appendChild($error_view)
|
2013-01-25 02:23:05 +01:00
|
|
|
->appendChild($form)
|
|
|
|
->addSubmitButton()
|
2013-01-27 02:14:58 +01:00
|
|
|
->addCancelButton($this->getApplicationURI($conpherence->getID().'/'))
|
|
|
|
);
|
2013-01-25 02:23:05 +01:00
|
|
|
}
|
|
|
|
}
|