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))
|
2013-02-06 23:03:52 +01:00
|
|
|
->needOrigPics(true)
|
|
|
|
->needHeaderPics(true)
|
2013-01-25 02:23:05 +01:00
|
|
|
->executeOne();
|
|
|
|
$supported_formats = PhabricatorFile::getTransformableImageFormats();
|
|
|
|
|
2013-03-08 19:40:06 +01:00
|
|
|
$action = $request->getStr('action', 'metadata');
|
2013-03-06 00:45:36 +01:00
|
|
|
$latest_transaction_id = null;
|
2013-03-08 19:40:06 +01:00
|
|
|
$fancy_ajax_style = true;
|
2013-01-25 02:23:05 +01:00
|
|
|
$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
|
|
|
|
|
|
|
switch ($action) {
|
|
|
|
case 'message':
|
|
|
|
$message = $request->getStr('text');
|
2013-03-06 00:45:36 +01:00
|
|
|
$latest_transaction_id = $request->getInt('latest_transaction_id');
|
2013-01-27 04:56:39 +01:00
|
|
|
$xactions = $editor->generateTransactionsFromText(
|
|
|
|
$conpherence,
|
2013-02-19 22:33:10 +01:00
|
|
|
$message);
|
2013-01-25 02:23:05 +01:00
|
|
|
break;
|
|
|
|
case 'metadata':
|
|
|
|
$xactions = array();
|
2013-02-06 23:03:52 +01:00
|
|
|
$top = $request->getInt('image_y');
|
|
|
|
$left = $request->getInt('image_x');
|
|
|
|
$file_id = $request->getInt('file_id');
|
2013-02-07 20:17:20 +01:00
|
|
|
$title = $request->getStr('title');
|
2013-03-08 19:40:06 +01:00
|
|
|
$updated = false;
|
2013-02-06 23:03:52 +01:00
|
|
|
if ($file_id) {
|
|
|
|
$orig_file = id(new PhabricatorFileQuery())
|
2013-01-27 02:14:58 +01:00
|
|
|
->setViewer($user)
|
2013-02-06 23:03:52 +01:00
|
|
|
->withIDs(array($file_id))
|
2013-01-27 02:14:58 +01:00
|
|
|
->executeOne();
|
2013-02-06 23:03:52 +01:00
|
|
|
$okay = $orig_file->isTransformableImage();
|
2013-01-27 02:14:58 +01:00
|
|
|
if ($okay) {
|
|
|
|
$xactions[] = id(new ConpherenceTransaction())
|
|
|
|
->setTransactionType(ConpherenceTransactionType::TYPE_PICTURE)
|
2013-02-06 23:03:52 +01:00
|
|
|
->setNewValue($orig_file->getPHID());
|
|
|
|
// do 2 transformations "crudely"
|
|
|
|
$xformer = new PhabricatorImageTransformer();
|
|
|
|
$header_file = $xformer->executeConpherenceTransform(
|
|
|
|
$orig_file,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
ConpherenceImageData::HEAD_WIDTH,
|
2013-02-19 22:33:10 +01:00
|
|
|
ConpherenceImageData::HEAD_HEIGHT);
|
2013-02-06 23:03:52 +01:00
|
|
|
// this is handled outside the editor for now. no particularly
|
|
|
|
// good reason to move it inside
|
|
|
|
$conpherence->setImagePHIDs(
|
|
|
|
array(
|
|
|
|
ConpherenceImageData::SIZE_HEAD => $header_file->getPHID(),
|
2013-02-19 22:33:10 +01:00
|
|
|
));
|
2013-02-06 23:03:52 +01:00
|
|
|
$conpherence->setImages(
|
|
|
|
array(
|
|
|
|
ConpherenceImageData::SIZE_HEAD => $header_file,
|
2013-02-19 22:33:10 +01:00
|
|
|
));
|
2013-01-27 02:14:58 +01:00
|
|
|
} else {
|
2013-02-06 23:03:52 +01:00
|
|
|
$e_file[] = $orig_file;
|
2013-01-27 02:14:58 +01:00
|
|
|
$errors[] =
|
|
|
|
pht('This server only supports these image formats: %s.',
|
2013-01-25 02:23:05 +01:00
|
|
|
implode(', ', $supported_formats));
|
|
|
|
}
|
2013-02-07 20:17:20 +01:00
|
|
|
// use the existing title in this image upload case
|
|
|
|
$title = $conpherence->getTitle();
|
2013-03-08 19:40:06 +01:00
|
|
|
$updated = true;
|
|
|
|
$fancy_ajax_style = false;
|
2013-02-06 23:03:52 +01:00
|
|
|
} else if ($top !== null || $left !== null) {
|
|
|
|
$file = $conpherence->getImage(ConpherenceImageData::SIZE_ORIG);
|
|
|
|
$xformer = new PhabricatorImageTransformer();
|
|
|
|
$xformed = $xformer->executeConpherenceTransform(
|
|
|
|
$file,
|
|
|
|
$top,
|
|
|
|
$left,
|
|
|
|
ConpherenceImageData::HEAD_WIDTH,
|
2013-02-19 22:33:10 +01:00
|
|
|
ConpherenceImageData::HEAD_HEIGHT);
|
2013-02-06 23:03:52 +01:00
|
|
|
$image_phid = $xformed->getPHID();
|
|
|
|
|
|
|
|
$xactions[] = id(new ConpherenceTransaction())
|
|
|
|
->setTransactionType(
|
2013-02-19 22:33:10 +01:00
|
|
|
ConpherenceTransactionType::TYPE_PICTURE_CROP)
|
2013-03-08 19:40:06 +01:00
|
|
|
->setNewValue($image_phid);
|
|
|
|
$updated = true;
|
2013-01-25 02:23:05 +01:00
|
|
|
}
|
|
|
|
if ($title != $conpherence->getTitle()) {
|
|
|
|
$xactions[] = id(new ConpherenceTransaction())
|
|
|
|
->setTransactionType(ConpherenceTransactionType::TYPE_TITLE)
|
|
|
|
->setNewValue($title);
|
2013-03-08 19:40:06 +01:00
|
|
|
$updated = true;
|
|
|
|
}
|
|
|
|
if (!$updated && $request->isContinueRequest()) {
|
|
|
|
$errors[] = pht(
|
|
|
|
'That was a non-update. Try cancel.');
|
2013-01-25 02:23:05 +01:00
|
|
|
}
|
|
|
|
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);
|
2013-03-08 19:40:06 +01:00
|
|
|
if ($fancy_ajax_style) {
|
|
|
|
$content = $this->loadAndRenderUpdates(
|
2013-03-06 00:45:36 +01:00
|
|
|
$conpherence_id,
|
|
|
|
$latest_transaction_id);
|
|
|
|
return id(new AphrontAjaxResponse())
|
|
|
|
->setContent($content);
|
|
|
|
} else {
|
2013-03-08 19:40:06 +01:00
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI($this->getApplicationURI($conpherence->getID().'/'));
|
2013-03-06 00:45:36 +01:00
|
|
|
}
|
2013-01-30 01:53:57 +01:00
|
|
|
} catch (PhabricatorApplicationTransactionNoEffectException $ex) {
|
|
|
|
return id(new PhabricatorApplicationTransactionNoEffectResponse())
|
|
|
|
->setCancelURI($this->getApplicationURI($conpherence_id.'/'))
|
|
|
|
->setException($ex);
|
|
|
|
}
|
|
|
|
}
|
2013-01-25 02:23:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-03-08 19:40:06 +01:00
|
|
|
switch ($action) {
|
|
|
|
case 'metadata':
|
|
|
|
default:
|
|
|
|
$dialogue = $this->renderMetadataDialogue($conpherence, $error_view);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())
|
|
|
|
->setDialog($dialogue
|
|
|
|
->setUser($user)
|
|
|
|
->setWidth(AphrontDialogView::WIDTH_FORM)
|
|
|
|
->setSubmitURI($this->getApplicationURI('update/'.$conpherence_id.'/'))
|
|
|
|
->addSubmitButton()
|
|
|
|
->addCancelButton($this->getApplicationURI($conpherence->getID().'/')));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderMetadataDialogue(
|
|
|
|
ConpherenceThread $conpherence,
|
|
|
|
$error_view) {
|
|
|
|
|
2013-01-25 02:23:05 +01:00
|
|
|
$form = id(new AphrontFormLayoutView())
|
2013-03-08 19:40:06 +01:00
|
|
|
->appendChild($error_view)
|
2013-01-25 02:23:05 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setLabel(pht('Title'))
|
|
|
|
->setName('title')
|
2013-02-19 22:33:10 +01:00
|
|
|
->setValue($conpherence->getTitle()));
|
2013-02-06 23:03:52 +01:00
|
|
|
|
|
|
|
$image = $conpherence->getImage(ConpherenceImageData::SIZE_ORIG);
|
|
|
|
if ($image) {
|
|
|
|
$form
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormMarkupControl())
|
|
|
|
->setLabel(pht('Image'))
|
|
|
|
->setValue(phutil_tag(
|
|
|
|
'img',
|
|
|
|
array(
|
|
|
|
'src' =>
|
|
|
|
$conpherence->loadImageURI(ConpherenceImageData::SIZE_HEAD),
|
2013-02-19 22:33:10 +01:00
|
|
|
))))
|
2013-03-08 19:40:06 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormCropControl())
|
|
|
|
->setLabel(pht('Crop Image'))
|
|
|
|
->setValue($image)
|
|
|
|
->setWidth(ConpherenceImageData::HEAD_WIDTH)
|
|
|
|
->setHeight(ConpherenceImageData::HEAD_HEIGHT))
|
|
|
|
->appendChild(
|
|
|
|
id(new ConpherenceFormDragAndDropUploadControl())
|
|
|
|
->setLabel(pht('Change Image')));
|
2013-02-06 23:03:52 +01:00
|
|
|
} else {
|
|
|
|
$form
|
|
|
|
->appendChild(
|
|
|
|
id(new ConpherenceFormDragAndDropUploadControl())
|
2013-02-19 22:33:10 +01:00
|
|
|
->setLabel(pht('Image')));
|
2013-02-06 23:03:52 +01:00
|
|
|
}
|
2013-01-25 02:23:05 +01:00
|
|
|
|
|
|
|
require_celerity_resource('conpherence-update-css');
|
2013-03-08 19:40:06 +01:00
|
|
|
return id(new AphrontDialogView())
|
|
|
|
->setTitle(pht('Update Conpherence'))
|
|
|
|
->addHiddenInput('action', 'metadata')
|
|
|
|
->addHiddenInput('__continue__', true)
|
|
|
|
->appendChild($form);
|
2013-01-25 02:23:05 +01:00
|
|
|
}
|
2013-03-06 00:45:36 +01:00
|
|
|
|
2013-03-08 19:40:06 +01:00
|
|
|
private function loadAndRenderUpdates(
|
2013-03-06 00:45:36 +01:00
|
|
|
$conpherence_id,
|
|
|
|
$latest_transaction_id) {
|
|
|
|
|
2013-03-08 19:40:06 +01:00
|
|
|
$user = $this->getRequest()->getUser();
|
|
|
|
$conpherence = id(new ConpherenceThreadQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->setAfterID($latest_transaction_id)
|
|
|
|
->needHeaderPics(true)
|
|
|
|
->needWidgetData(true)
|
|
|
|
->withIDs(array($conpherence_id))
|
|
|
|
->executeOne();
|
2013-03-06 00:45:36 +01:00
|
|
|
|
2013-03-08 19:40:06 +01:00
|
|
|
$data = $this->renderConpherenceTransactions($conpherence);
|
|
|
|
$rendered_transactions = $data['transactions'];
|
|
|
|
$new_latest_transaction_id = $data['latest_transaction_id'];
|
|
|
|
|
|
|
|
$selected = true;
|
|
|
|
$nav_item = $this->buildConpherenceMenuItem(
|
|
|
|
$conpherence,
|
|
|
|
'-nav-item',
|
|
|
|
$selected);
|
|
|
|
$menu_item = $this->buildConpherenceMenuItem(
|
|
|
|
$conpherence,
|
|
|
|
'-menu-item',
|
|
|
|
$selected);
|
|
|
|
|
|
|
|
$header = $this->buildHeaderPaneContent($conpherence);
|
|
|
|
|
|
|
|
$file_widget = id(new ConpherenceFileWidgetView())
|
|
|
|
->setConpherence($conpherence)
|
|
|
|
->setUpdateURI(
|
|
|
|
$this->getApplicationURI('update/'.$conpherence->getID().'/'));
|
2013-03-06 00:45:36 +01:00
|
|
|
|
2013-03-08 19:40:06 +01:00
|
|
|
$content = array(
|
|
|
|
'transactions' => $rendered_transactions,
|
|
|
|
'latest_transaction_id' => $new_latest_transaction_id,
|
|
|
|
'menu_item' => $menu_item->render(),
|
|
|
|
'nav_item' => $nav_item->render(),
|
|
|
|
'conpherence_phid' => $conpherence->getPHID(),
|
|
|
|
'header' => $header,
|
|
|
|
'file_widget' => $file_widget->render()
|
|
|
|
);
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|