2013-09-28 01:01:37 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorMacroAudioController
|
|
|
|
extends PhabricatorMacroController {
|
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = idx($data, 'id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
2013-10-16 19:35:52 +02:00
|
|
|
|
|
|
|
$this->requireApplicationCapability(
|
|
|
|
PhabricatorMacroCapabilityManage::CAPABILITY);
|
|
|
|
|
2013-09-28 01:01:37 +02:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
|
|
|
$macro = id(new PhabricatorMacroQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
))
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->executeOne();
|
|
|
|
|
|
|
|
if (!$macro) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$errors = array();
|
|
|
|
$view_uri = $this->getApplicationURI('/view/'.$macro->getID().'/');
|
|
|
|
|
|
|
|
$e_file = null;
|
|
|
|
$file = null;
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$xactions = array();
|
|
|
|
|
|
|
|
if ($request->getBool('behaviorForm')) {
|
|
|
|
$xactions[] = id(new PhabricatorMacroTransaction())
|
|
|
|
->setTransactionType(
|
|
|
|
PhabricatorMacroTransactionType::TYPE_AUDIO_BEHAVIOR)
|
|
|
|
->setNewValue($request->getStr('audioBehavior'));
|
|
|
|
} else {
|
|
|
|
$file = null;
|
|
|
|
if ($request->getFileExists('file')) {
|
|
|
|
$file = PhabricatorFile::newFromPHPUpload(
|
|
|
|
$_FILES['file'],
|
|
|
|
array(
|
|
|
|
'name' => $request->getStr('name'),
|
|
|
|
'authorPHID' => $viewer->getPHID(),
|
|
|
|
'isExplicitUpload' => true,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($file) {
|
|
|
|
if (!$file->isAudio()) {
|
|
|
|
$errors[] = pht('You must upload audio.');
|
|
|
|
$e_file = pht('Invalid');
|
|
|
|
} else {
|
|
|
|
$xactions[] = id(new PhabricatorMacroTransaction())
|
|
|
|
->setTransactionType(PhabricatorMacroTransactionType::TYPE_AUDIO)
|
|
|
|
->setNewValue($file->getPHID());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$errors[] = pht('You must upload an audio file.');
|
|
|
|
$e_file = pht('Required');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$errors) {
|
|
|
|
id(new PhabricatorMacroEditor())
|
|
|
|
->setActor($viewer)
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->applyTransactions($macro, $xactions);
|
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($view_uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->addHiddenInput('behaviorForm', 1)
|
|
|
|
->setUser($viewer);
|
|
|
|
|
|
|
|
$options = id(new AphrontFormRadioButtonControl())
|
|
|
|
->setLabel(pht('Audio Behavior'))
|
|
|
|
->setName('audioBehavior')
|
|
|
|
->setValue(
|
|
|
|
nonempty(
|
|
|
|
$macro->getAudioBehavior(),
|
|
|
|
PhabricatorFileImageMacro::AUDIO_BEHAVIOR_NONE));
|
|
|
|
|
|
|
|
$options->addButton(
|
|
|
|
PhabricatorFileImageMacro::AUDIO_BEHAVIOR_NONE,
|
|
|
|
pht('Do Not Play'),
|
|
|
|
pht('Do not play audio.'));
|
|
|
|
|
|
|
|
$options->addButton(
|
|
|
|
PhabricatorFileImageMacro::AUDIO_BEHAVIOR_ONCE,
|
|
|
|
pht('Play Once'),
|
|
|
|
pht('Play audio once, when the viewer looks at the macro.'));
|
|
|
|
|
|
|
|
$options->addButton(
|
|
|
|
PhabricatorFileImageMacro::AUDIO_BEHAVIOR_LOOP,
|
|
|
|
pht('Play Continuously'),
|
|
|
|
pht(
|
|
|
|
'Play audio continuously, treating the macro as an audio source. '.
|
|
|
|
'Best for ambient sounds.'));
|
|
|
|
|
|
|
|
$form->appendChild($options);
|
|
|
|
|
|
|
|
$form
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->setValue(pht('Save Audio Behavior'))
|
|
|
|
->addCancelButton($view_uri));
|
|
|
|
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
|
|
|
|
$title = pht('Edit Audio Behavior');
|
|
|
|
$crumb = pht('Edit Audio');
|
|
|
|
|
2013-12-19 02:47:34 +01:00
|
|
|
$crumbs->addTextCrumb(pht('Macro "%s"', $macro->getName()), $view_uri);
|
|
|
|
$crumbs->addTextCrumb($crumb, $request->getRequestURI());
|
2013-09-28 01:01:37 +02:00
|
|
|
|
|
|
|
$upload_form = id(new AphrontFormView())
|
|
|
|
->setEncType('multipart/form-data')
|
|
|
|
->setUser($viewer)
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormFileControl())
|
|
|
|
->setLabel(pht('Audio File'))
|
|
|
|
->setName('file'))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->setValue(pht('Upload File')));
|
|
|
|
|
|
|
|
$upload = id(new PHUIObjectBoxView())
|
|
|
|
->setHeaderText(pht('Upload New Audio'))
|
|
|
|
->setForm($upload_form);
|
|
|
|
|
|
|
|
$form_box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeaderText($title)
|
2014-01-10 18:17:37 +01:00
|
|
|
->setFormErrors($errors)
|
2013-09-28 01:01:37 +02:00
|
|
|
->setForm($form);
|
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
|
|
|
$form_box,
|
|
|
|
$upload,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => $title,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|