本文整理汇总了PHP中PhabricatorFile::newFromPHPUpload方法的典型用法代码示例。如果您正苦于以下问题:PHP PhabricatorFile::newFromPHPUpload方法的具体用法?PHP PhabricatorFile::newFromPHPUpload怎么用?PHP PhabricatorFile::newFromPHPUpload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhabricatorFile
的用法示例。
在下文中一共展示了PhabricatorFile::newFromPHPUpload方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleRequest
public function handleRequest(AphrontRequest $request)
{
$viewer = $request->getUser();
$file = PhabricatorFile::initializeNewFile();
$e_file = true;
$errors = array();
if ($request->isFormPost()) {
$view_policy = $request->getStr('viewPolicy');
if (!$request->getFileExists('file')) {
$e_file = pht('Required');
$errors[] = pht('You must select a file to upload.');
} else {
$file = PhabricatorFile::newFromPHPUpload(idx($_FILES, 'file'), array('name' => $request->getStr('name'), 'authorPHID' => $viewer->getPHID(), 'viewPolicy' => $view_policy, 'isExplicitUpload' => true));
}
if (!$errors) {
return id(new AphrontRedirectResponse())->setURI($file->getInfoURI());
}
$file->setViewPolicy($view_policy);
}
$support_id = celerity_generate_unique_node_id();
$instructions = id(new AphrontFormMarkupControl())->setControlID($support_id)->setControlStyle('display: none')->setValue(hsprintf('<br /><br /><strong>%s</strong> %s<br /><br />', pht('Drag and Drop:'), pht('You can also upload files by dragging and dropping them from your ' . 'desktop onto this page or the Phabricator home page.')));
$policies = id(new PhabricatorPolicyQuery())->setViewer($viewer)->setObject($file)->execute();
$form = id(new AphrontFormView())->setUser($viewer)->setEncType('multipart/form-data')->appendChild(id(new AphrontFormFileControl())->setLabel(pht('File'))->setName('file')->setError($e_file))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Name'))->setName('name')->setValue($request->getStr('name')))->appendChild(id(new AphrontFormPolicyControl())->setUser($viewer)->setCapability(PhabricatorPolicyCapability::CAN_VIEW)->setPolicyObject($file)->setPolicies($policies)->setName('viewPolicy'))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Upload'))->addCancelButton('/file/'))->appendChild($instructions);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Upload'), $request->getRequestURI());
$crumbs->setBorder(true);
$title = pht('Upload File');
$global_upload = id(new PhabricatorGlobalUploadTargetView())->setUser($viewer)->setShowIfSupportedID($support_id);
$form_box = id(new PHUIObjectBoxView())->setHeaderText(pht('File'))->setFormErrors($errors)->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setForm($form);
$header = id(new PHUIHeaderView())->setHeader($title)->setHeaderIcon('fa-upload');
$view = id(new PHUITwoColumnView())->setHeader($header)->setFooter(array($form_box, $global_upload));
return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view);
}
示例2: processRequest
public function processRequest()
{
// No CSRF for SendGrid.
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
$request = $this->getRequest();
$user = $request->getUser();
$raw_headers = $request->getStr('headers');
$raw_headers = explode("\n", rtrim($raw_headers));
$raw_dict = array();
foreach (array_filter($raw_headers) as $header) {
list($name, $value) = explode(':', $header, 2);
$raw_dict[$name] = ltrim($value);
}
$headers = array('to' => $request->getStr('to'), 'from' => $request->getStr('from'), 'subject' => $request->getStr('subject')) + $raw_dict;
$received = new PhabricatorMetaMTAReceivedMail();
$received->setHeaders($headers);
$received->setBodies(array('text' => $request->getStr('text'), 'html' => $request->getStr('from')));
$file_phids = array();
foreach ($_FILES as $file_raw) {
try {
$file = PhabricatorFile::newFromPHPUpload($file_raw, array('authorPHID' => $user->getPHID()));
$file_phids[] = $file->getPHID();
} catch (Exception $ex) {
phlog($ex);
}
}
$received->setAttachments($file_phids);
$received->save();
$received->processReceivedMail();
$response = new AphrontWebpageResponse();
$response->setContent("Got it! Thanks, SendGrid!\n");
return $response;
}
示例3: readRequest
public function readRequest(PhabricatorConfigOption $option, AphrontRequest $request)
{
$viewer = $request->getViewer();
$view_policy = PhabricatorPolicies::POLICY_PUBLIC;
if ($request->getBool('removeLogo')) {
$logo_image_phid = null;
} else {
if ($request->getFileExists('logoImage')) {
$logo_image = PhabricatorFile::newFromPHPUpload(idx($_FILES, 'logoImage'), array('name' => 'logo', 'authorPHID' => $viewer->getPHID(), 'viewPolicy' => $view_policy, 'canCDN' => true, 'isExplicitUpload' => true));
$logo_image_phid = $logo_image->getPHID();
} else {
$logo_image_phid = self::getLogoImagePHID();
}
}
$wordmark_text = $request->getStr('wordmarkText');
$value = array('logoImagePHID' => $logo_image_phid, 'wordmarkText' => $wordmark_text);
$errors = array();
$e_value = null;
try {
$this->validateOption($option, $value);
} catch (Exception $ex) {
$e_value = pht('Invalid');
$errors[] = $ex->getMessage();
$value = array();
}
return array($e_value, $errors, $value, phutil_json_encode($value));
}
示例4: handleRequest
public function handleRequest(AphrontRequest $request)
{
// No CSRF for Mailgun.
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
if (!$this->verifyMessage()) {
throw new Exception(pht('Mail signature is not valid. Check your Mailgun API key.'));
}
$user = $request->getUser();
$raw_headers = $request->getStr('headers');
$raw_headers = explode("\n", rtrim($raw_headers));
$raw_dict = array();
foreach (array_filter($raw_headers) as $header) {
list($name, $value) = explode(':', $header, 2);
$raw_dict[$name] = ltrim($value);
}
$headers = array('to' => $request->getStr('recipient'), 'from' => $request->getStr('from'), 'subject' => $request->getStr('subject')) + $raw_dict;
$received = new PhabricatorMetaMTAReceivedMail();
$received->setHeaders($headers);
$received->setBodies(array('text' => $request->getStr('stripped-text'), 'html' => $request->getStr('stripped-html')));
$file_phids = array();
foreach ($_FILES as $file_raw) {
try {
$file = PhabricatorFile::newFromPHPUpload($file_raw, array('viewPolicy' => PhabricatorPolicies::POLICY_NOONE));
$file_phids[] = $file->getPHID();
} catch (Exception $ex) {
phlog($ex);
}
}
$received->setAttachments($file_phids);
$received->save();
$received->processReceivedMail();
$response = new AphrontWebpageResponse();
$response->setContent(pht("Got it! Thanks, Mailgun!\n"));
return $response;
}
示例5: processRequest
public function processRequest()
{
if ($this->id) {
$macro = id(new PhabricatorFileImageMacro())->load($this->id);
if (!$macro) {
return new Aphront404Response();
}
} else {
$macro = new PhabricatorFileImageMacro();
}
$errors = array();
$e_name = true;
$request = $this->getRequest();
$user = $request->getUser();
if ($request->isFormPost()) {
$macro->setName($request->getStr('name'));
if (!strlen($macro->getName())) {
$errors[] = 'Macro name is required.';
$e_name = 'Required';
} else {
if (!preg_match('/^[a-z0-9_-]{3,}$/', $macro->getName())) {
$errors[] = 'Macro must be at least three characters long and contain ' . 'only lowercase letters, digits, hyphen and underscore.';
$e_name = 'Invalid';
} else {
$e_name = null;
}
}
if (!$errors) {
$file = PhabricatorFile::newFromPHPUpload(idx($_FILES, 'file'), array('name' => $request->getStr('name'), 'authorPHID' => $user->getPHID()));
$macro->setFilePHID($file->getPHID());
try {
$macro->save();
return id(new AphrontRedirectResponse())->setURI('/file/macro/');
} catch (AphrontQueryDuplicateKeyException $ex) {
$errors[] = 'Macro name is not unique!';
$e_name = 'Duplicate';
}
}
}
if ($errors) {
$error_view = new AphrontErrorView();
$error_view->setTitle('Form Errors');
$error_view->setErrors($errors);
} else {
$error_view = null;
}
$form = new AphrontFormView();
$form->setAction('/file/macro/edit/');
$form->setUser($request->getUser());
$form->setEncType('multipart/form-data')->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($macro->getName())->setCaption('This word or phrase will be replaced with the image.')->setError($e_name))->appendChild(id(new AphrontFormFileControl())->setLabel('File')->setName('file')->setError(true))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save Image Macro')->addCancelButton('/file/macro/'));
$panel = new AphrontPanelView();
if ($macro->getID()) {
$panel->setHeader('Edit Image Macro');
} else {
$panel->setHeader('Create Image Macro');
}
$panel->appendChild($form);
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Edit Image Macro'));
}
示例6: handleRequest
public function handleRequest(AphrontRequest $request)
{
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$this->requireApplicationCapability(PhabricatorMacroManageCapability::CAPABILITY);
$macro = id(new PhabricatorMacroQuery())->setViewer($viewer)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW))->withIDs(array($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(PhabricatorMacroTransaction::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(PhabricatorMacroTransaction::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: %s', $macro->getName());
$crumb = pht('Edit Audio');
$crumbs->addTextCrumb(pht('Macro "%s"', $macro->getName()), $view_uri);
$crumbs->addTextCrumb($crumb, $request->getRequestURI());
$crumbs->setBorder(true);
$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'))->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setForm($upload_form);
$form_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Behavior'))->setFormErrors($errors)->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setForm($form);
$header = id(new PHUIHeaderView())->setHeader($title)->setHeaderIcon('fa-pencil');
$view = id(new PHUITwoColumnView())->setHeader($header)->setFooter(array($form_box, $upload));
return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view);
}
示例7: handleRequest
public function handleRequest(AphrontRequest $request)
{
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$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) {
$new_value = null;
} else {
$file->attachToObject($blog->getPHID());
$new_value = $file->getPHID();
}
$xactions = array();
$xactions[] = id(new PhameBlogTransaction())->setTransactionType(PhameBlogTransaction::TYPE_HEADERIMAGE)->setNewValue($new_value);
$editor = id(new PhameBlogEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnMissingFields(true)->setContinueOnNoEffect(true);
$editor->applyTransactions($blog, $xactions);
return id(new AphrontRedirectResponse())->setURI($blog_uri);
}
}
$title = pht('Edit Blog Header');
$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));
}
示例8: processRequest
public function processRequest()
{
$request = $this->getRequest();
$user = $request->getUser();
if ($request->isFormPost()) {
$file = PhabricatorFile::newFromPHPUpload(idx($_FILES, 'file'), array('name' => $request->getStr('name'), 'authorPHID' => $user->getPHID()));
return id(new AphrontRedirectResponse())->setURI($file->getBestURI());
}
$panel = new PhabricatorFileUploadView();
$panel->setUser($user);
return $this->buildStandardPageResponse(array($panel), array('title' => 'Upload File'));
}
示例9: handleRequest
public function handleRequest(AphrontRequest $request)
{
// No CSRF for Mailgun.
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
if (!$this->verifyMessage()) {
throw new Exception(pht('Mail signature is not valid. Check your Mailgun API key.'));
}
$raw_headers = $request->getStr('message-headers');
$raw_dict = array();
if (strlen($raw_headers)) {
$raw_headers = phutil_json_decode($raw_headers);
foreach ($raw_headers as $raw_header) {
list($name, $value) = $raw_header;
$raw_dict[$name] = $value;
}
}
$headers = array('to' => $request->getStr('recipient'), 'from' => $request->getStr('from'), 'subject' => $request->getStr('subject')) + $raw_dict;
$received = new PhabricatorMetaMTAReceivedMail();
$received->setHeaders($headers);
$received->setBodies(array('text' => $request->getStr('stripped-text'), 'html' => $request->getStr('stripped-html')));
$file_phids = array();
foreach ($_FILES as $file_raw) {
try {
$file = PhabricatorFile::newFromPHPUpload($file_raw, array('viewPolicy' => PhabricatorPolicies::POLICY_NOONE));
$file_phids[] = $file->getPHID();
} catch (Exception $ex) {
phlog($ex);
}
}
$received->setAttachments($file_phids);
try {
$received->save();
$received->processReceivedMail();
} catch (Exception $ex) {
// We can get exceptions here in two cases.
// First, saving the message may throw if we have already received a
// message with the same Message ID. In this case, we're declining to
// process a duplicate message, so failing silently is correct.
// Second, processing the message may throw (for example, if it contains
// an invalid !command). This will generate an email as a side effect,
// so we don't need to explicitly handle the exception here.
// In these cases, we want to return HTTP 200. If we do not, MailGun will
// re-transmit the message later.
phlog($ex);
}
$response = new AphrontWebpageResponse();
$response->setContent(pht("Got it! Thanks, Mailgun!\n"));
return $response;
}
示例10: processRequest
public function processRequest()
{
$request = $this->getRequest();
$user = $request->getUser();
if ($request->isFormPost()) {
$file = PhabricatorFile::newFromPHPUpload(idx($_FILES, 'file'), array('name' => $request->getStr('name'), 'authorPHID' => $user->getPHID()));
return id(new AphrontRedirectResponse())->setURI($file->getBestURI());
}
$form = new AphrontFormView();
$form->setAction('/file/upload/');
$form->setUser($request->getUser());
$form->setEncType('multipart/form-data')->appendChild(id(new AphrontFormFileControl())->setLabel('File')->setName('file')->setError(true))->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setCaption('Optional file display name.'))->appendChild(id(new AphrontFormSubmitControl())->setValue('Upload')->addCancelButton('/file/'));
$panel = new AphrontPanelView();
$panel->setHeader('Upload File');
$panel->appendChild($form);
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
return $this->buildStandardPageResponse(array($panel), array('title' => 'Upload File'));
}
示例11: getParameterValue
protected function getParameterValue(AphrontRequest $request, $key)
{
$value = $request->getStrList($key);
if ($value) {
return head($value);
}
// NOTE: At least for now, we'll attempt to read a direct upload if we
// miss on a PHID. Currently, PHUIFormFileControl does a client-side
// upload on workflow forms (which is good) but doesn't have a hook for
// non-workflow forms (which isn't as good). Giving it a hook is desirable,
// but complicated. Even if we do hook it, it may be reasonable to keep
// this code around as a fallback if the client-side JS goes awry.
$file_key = $this->getFileKey($key);
if (!$request->getFileExists($file_key)) {
return null;
}
$viewer = $this->getViewer();
$file = PhabricatorFile::newFromPHPUpload(idx($_FILES, $file_key), array('authorPHID' => $viewer->getPHID(), 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE));
return $file->getPHID();
}
示例12: processRequest
public function processRequest()
{
$request = $this->getRequest();
$viewer = $request->getUser();
$project = id(new PhabricatorProjectQuery())->setViewer($viewer)->withIDs(array($this->id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
if (!$project) {
return new Aphront404Response();
}
$edit_uri = $this->getApplicationURI('edit/' . $project->getID() . '/');
$view_uri = $this->getApplicationURI('view/' . $project->getID() . '/');
$supported_formats = PhabricatorFile::getTransformableImageFormats();
$e_file = true;
$errors = array();
if ($request->isFormPost()) {
$phid = $request->getStr('phid');
$is_default = false;
if ($phid == PhabricatorPHIDConstants::PHID_VOID) {
$phid = null;
$is_default = true;
} else {
if ($phid) {
$file = id(new PhabricatorFileQuery())->setViewer($viewer)->withPHIDs(array($phid))->executeOne();
} else {
if ($request->getFileExists('picture')) {
$file = PhabricatorFile::newFromPHPUpload($_FILES['picture'], array('authorPHID' => $viewer->getPHID(), 'canCDN' => true));
} else {
$e_file = pht('Required');
$errors[] = pht('You must choose a file when uploading a new project picture.');
}
}
}
if (!$errors && !$is_default) {
if (!$file->isTransformableImage()) {
$e_file = pht('Not Supported');
$errors[] = pht('This server only supports these image formats: %s.', implode(', ', $supported_formats));
} else {
$xformer = new PhabricatorImageTransformer();
$xformed = $xformer->executeProfileTransform($file, $width = 50, $min_height = 50, $max_height = 50);
}
}
if (!$errors) {
if ($is_default) {
$new_value = null;
} else {
$new_value = $xformed->getPHID();
}
$xactions = array();
$xactions[] = id(new PhabricatorProjectTransaction())->setTransactionType(PhabricatorProjectTransaction::TYPE_IMAGE)->setNewValue($new_value);
$editor = id(new PhabricatorProjectTransactionEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnMissingFields(true)->setContinueOnNoEffect(true);
$editor->applyTransactions($project, $xactions);
return id(new AphrontRedirectResponse())->setURI($edit_uri);
}
}
$title = pht('Edit Project Picture');
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($project->getName(), $view_uri);
$crumbs->addTextCrumb(pht('Edit'), $edit_uri);
$crumbs->addTextCrumb(pht('Picture'));
$form = id(new PHUIFormLayoutView())->setUser($viewer);
$default_image = PhabricatorFile::loadBuiltin($viewer, 'project.png');
$images = array();
$current = $project->getProfileImagePHID();
$has_current = false;
if ($current) {
$files = id(new PhabricatorFileQuery())->setViewer($viewer)->withPHIDs(array($current))->execute();
if ($files) {
$file = head($files);
if ($file->isTransformableImage()) {
$has_current = true;
$images[$current] = array('uri' => $file->getBestURI(), 'tip' => pht('Current Picture'));
}
}
}
$images[PhabricatorPHIDConstants::PHID_VOID] = array('uri' => $default_image->getBestURI(), 'tip' => pht('Default Picture'));
require_celerity_resource('people-profile-css');
Javelin::initBehavior('phabricator-tooltips', array());
$buttons = array();
foreach ($images as $phid => $spec) {
$button = javelin_tag('button', array('class' => 'grey profile-image-button', 'sigil' => 'has-tooltip', 'meta' => array('tip' => $spec['tip'], 'size' => 300)), phutil_tag('img', array('height' => 50, 'width' => 50, 'src' => $spec['uri'])));
$button = array(phutil_tag('input', array('type' => 'hidden', 'name' => 'phid', 'value' => $phid)), $button);
$button = phabricator_form($viewer, array('class' => 'profile-image-form', 'method' => 'POST'), $button);
$buttons[] = $button;
}
if ($has_current) {
$form->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Current Picture'))->setValue(array_shift($buttons)));
}
$form->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Use Picture'))->setValue($buttons));
$launch_id = celerity_generate_unique_node_id();
$input_id = celerity_generate_unique_node_id();
Javelin::initBehavior('launch-icon-composer', array('launchID' => $launch_id, 'inputID' => $input_id));
$compose_button = javelin_tag('button', array('class' => 'grey', 'id' => $launch_id, 'sigil' => 'icon-composer'), pht('Choose Icon and Color...'));
$compose_input = javelin_tag('input', array('type' => 'hidden', 'id' => $input_id, 'name' => 'phid'));
$compose_form = phabricator_form($viewer, array('class' => 'profile-image-form', 'method' => 'POST'), array($compose_input, $compose_button));
$form->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Quick Create'))->setValue($compose_form));
$upload_form = id(new AphrontFormView())->setUser($viewer)->setEncType('multipart/form-data')->appendChild(id(new AphrontFormFileControl())->setName('picture')->setLabel(pht('Upload Picture'))->setError($e_file)->setCaption(pht('Supported formats: %s', implode(', ', $supported_formats))))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($edit_uri)->setValue(pht('Upload Picture')));
$form_box = id(new PHUIObjectBoxView())->setHeaderText($title)->setFormErrors($errors)->setForm($form);
$upload_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Upload New Picture'))->setForm($upload_form);
return $this->buildApplicationPage(array($crumbs, $form_box, $upload_box), array('title' => $title));
}
示例13: handleRequest
public function handleRequest(AphrontRequest $request)
{
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$conpherence = id(new ConpherenceThreadQuery())->setViewer($viewer)->withIDs(array($id))->needProfileImage(true)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
if (!$conpherence) {
return new Aphront404Response();
}
$monogram = $conpherence->getMonogram();
$supported_formats = PhabricatorFile::getTransformableImageFormats();
$e_file = true;
$errors = array();
if ($request->isFormPost()) {
$phid = $request->getStr('phid');
$is_default = false;
if ($phid == PhabricatorPHIDConstants::PHID_VOID) {
$phid = null;
$is_default = true;
} else {
if ($phid) {
$file = id(new PhabricatorFileQuery())->setViewer($viewer)->withPHIDs(array($phid))->executeOne();
} else {
if ($request->getFileExists('picture')) {
$file = PhabricatorFile::newFromPHPUpload($_FILES['picture'], array('authorPHID' => $viewer->getPHID(), 'canCDN' => true));
} else {
$e_file = pht('Required');
$errors[] = pht('You must choose a file when uploading a new room picture.');
}
}
}
if (!$errors && !$is_default) {
if (!$file->isTransformableImage()) {
$e_file = pht('Not Supported');
$errors[] = pht('This server only supports these image formats: %s.', implode(', ', $supported_formats));
} else {
$xform = PhabricatorFileTransform::getTransformByKey(PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE);
$xformed = $xform->executeTransform($file);
}
}
if (!$errors) {
if ($is_default) {
$new_value = null;
} else {
$xformed->attachToObject($conpherence->getPHID());
$new_value = $xformed->getPHID();
}
$xactions = array();
$xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransaction::TYPE_PICTURE)->setNewValue($new_value);
$editor = id(new ConpherenceEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnMissingFields(true)->setContinueOnNoEffect(true);
$editor->applyTransactions($conpherence, $xactions);
return id(new AphrontRedirectResponse())->setURI('/' . $monogram);
}
}
$title = pht('Edit Room Picture');
$form = id(new PHUIFormLayoutView())->setUser($viewer);
$default_image = PhabricatorFile::loadBuiltin($viewer, 'conpherence.png');
$images = array();
$current = $conpherence->getProfileImagePHID();
$has_current = false;
if ($current) {
$file = id(new PhabricatorFileQuery())->setViewer($viewer)->withPHIDs(array($current))->executeOne();
if ($file) {
if ($file->isTransformableImage()) {
$has_current = true;
$images[$current] = array('uri' => $file->getBestURI(), 'tip' => pht('Current Picture'));
}
}
}
$images[PhabricatorPHIDConstants::PHID_VOID] = array('uri' => $default_image->getBestURI(), 'tip' => pht('Default Picture'));
require_celerity_resource('people-profile-css');
Javelin::initBehavior('phabricator-tooltips', array());
$buttons = array();
foreach ($images as $phid => $spec) {
$button = javelin_tag('button', array('class' => 'grey profile-image-button', 'sigil' => 'has-tooltip', 'meta' => array('tip' => $spec['tip'], 'size' => 300)), phutil_tag('img', array('height' => 50, 'width' => 50, 'src' => $spec['uri'])));
$button = array(phutil_tag('input', array('type' => 'hidden', 'name' => 'phid', 'value' => $phid)), $button);
$button = phabricator_form($viewer, array('class' => 'profile-image-form', 'method' => 'POST'), $button);
$buttons[] = $button;
}
if ($has_current) {
$form->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Current Picture'))->setValue(array_shift($buttons)));
}
$form->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Use Picture'))->setValue($buttons));
$form_box = id(new PHUIObjectBoxView())->setHeaderText($title)->setFormErrors($errors)->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setForm($form);
$upload_form = id(new AphrontFormView())->setUser($viewer)->setEncType('multipart/form-data')->appendChild(id(new AphrontFormFileControl())->setName('picture')->setLabel(pht('Upload Picture'))->setError($e_file)->setCaption(pht('Supported formats: %s', implode(', ', $supported_formats))))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton('/' . $monogram)->setValue(pht('Upload Picture')));
$upload_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Upload New Picture'))->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setForm($upload_form);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($conpherence->getTitle(), '/' . $monogram);
$crumbs->addTextCrumb(pht('Room Picture'));
$crumbs->setBorder(true);
$header = id(new PHUIHeaderView())->setHeader(pht('Edit Room Picture'))->setHeaderIcon('fa-camera');
$view = id(new PHUITwoColumnView())->setHeader($header)->setFooter(array($form_box, $upload_box));
return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild(array($view));
}
示例14: processRequest
public function processRequest()
{
$this->requireApplicationCapability(PhabricatorMacroManageCapability::CAPABILITY);
$request = $this->getRequest();
$user = $request->getUser();
if ($this->id) {
$macro = id(new PhabricatorMacroQuery())->setViewer($user)->withIDs(array($this->id))->needFiles(true)->executeOne();
if (!$macro) {
return new Aphront404Response();
}
} else {
$macro = new PhabricatorFileImageMacro();
$macro->setAuthorPHID($user->getPHID());
}
$errors = array();
$e_name = true;
$e_file = null;
$file = null;
$can_fetch = PhabricatorEnv::getEnvConfig('security.allow-outbound-http');
if ($request->isFormPost()) {
$original = clone $macro;
$new_name = null;
if ($request->getBool('name_form') || !$macro->getID()) {
$new_name = $request->getStr('name');
$macro->setName($new_name);
if (!strlen($macro->getName())) {
$errors[] = pht('Macro name is required.');
$e_name = pht('Required');
} else {
if (!preg_match('/^[a-z0-9:_-]{3,}\\z/', $macro->getName())) {
$errors[] = pht('Macro must be at least three characters long and contain only ' . 'lowercase letters, digits, hyphens, colons and underscores.');
$e_name = pht('Invalid');
} else {
$e_name = null;
}
}
}
$file = null;
if ($request->getFileExists('file')) {
$file = PhabricatorFile::newFromPHPUpload($_FILES['file'], array('name' => $request->getStr('name'), 'authorPHID' => $user->getPHID(), 'isExplicitUpload' => true, 'canCDN' => true));
} else {
if ($request->getStr('url')) {
try {
$file = PhabricatorFile::newFromFileDownload($request->getStr('url'), array('name' => $request->getStr('name'), 'authorPHID' => $user->getPHID(), 'isExplicitUpload' => true, 'canCDN' => true));
} catch (Exception $ex) {
$errors[] = pht('Could not fetch URL: %s', $ex->getMessage());
}
} else {
if ($request->getStr('phid')) {
$file = id(new PhabricatorFileQuery())->setViewer($user)->withPHIDs(array($request->getStr('phid')))->executeOne();
}
}
}
if ($file) {
if (!$file->isViewableInBrowser()) {
$errors[] = pht('You must upload an image.');
$e_file = pht('Invalid');
} else {
$macro->setFilePHID($file->getPHID());
$macro->attachFile($file);
$e_file = null;
}
}
if (!$macro->getID() && !$file) {
$errors[] = pht('You must upload an image to create a macro.');
$e_file = pht('Required');
}
if (!$errors) {
try {
$xactions = array();
if ($new_name !== null) {
$xactions[] = id(new PhabricatorMacroTransaction())->setTransactionType(PhabricatorMacroTransactionType::TYPE_NAME)->setNewValue($new_name);
}
if ($file) {
$xactions[] = id(new PhabricatorMacroTransaction())->setTransactionType(PhabricatorMacroTransactionType::TYPE_FILE)->setNewValue($file->getPHID());
}
$editor = id(new PhabricatorMacroEditor())->setActor($user)->setContinueOnNoEffect(true)->setContentSourceFromRequest($request);
$xactions = $editor->applyTransactions($original, $xactions);
$view_uri = $this->getApplicationURI('/view/' . $original->getID() . '/');
return id(new AphrontRedirectResponse())->setURI($view_uri);
} catch (AphrontDuplicateKeyQueryException $ex) {
throw $ex;
$errors[] = pht('Macro name is not unique!');
$e_name = pht('Duplicate');
}
}
}
$current_file = null;
if ($macro->getFilePHID()) {
$current_file = $macro->getFile();
}
$form = new AphrontFormView();
$form->addHiddenInput('name_form', 1);
$form->setUser($request->getUser());
$form->setEncType('multipart/form-data')->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Name'))->setName('name')->setValue($macro->getName())->setCaption(pht('This word or phrase will be replaced with the image.'))->setError($e_name));
if (!$macro->getID()) {
if ($current_file) {
$current_file_view = id(new PhabricatorFileLinkView())->setFilePHID($current_file->getPHID())->setFileName($current_file->getName())->setFileViewable(true)->setFileViewURI($current_file->getBestURI())->render();
$form->addHiddenInput('phid', $current_file->getPHID());
$form->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Selected File'))->setValue($current_file_view));
//.........这里部分代码省略.........
示例15: handleRequest
public function handleRequest(AphrontRequest $request)
{
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$this->requireApplicationCapability(PhabricatorMacroManageCapability::CAPABILITY);
if ($id) {
$macro = id(new PhabricatorMacroQuery())->setViewer($viewer)->withIDs(array($id))->needFiles(true)->executeOne();
if (!$macro) {
return new Aphront404Response();
}
} else {
$macro = new PhabricatorFileImageMacro();
$macro->setAuthorPHID($viewer->getPHID());
}
$errors = array();
$e_name = true;
$e_file = null;
$file = null;
if ($request->isFormPost()) {
$original = clone $macro;
$new_name = null;
if ($request->getBool('name_form') || !$macro->getID()) {
$new_name = $request->getStr('name');
$macro->setName($new_name);
if (!strlen($macro->getName())) {
$errors[] = pht('Macro name is required.');
$e_name = pht('Required');
} else {
if (!preg_match('/^[a-z0-9:_-]{3,}\\z/', $macro->getName())) {
$errors[] = pht('Macro must be at least three characters long and contain only ' . 'lowercase letters, digits, hyphens, colons and underscores.');
$e_name = pht('Invalid');
} else {
$e_name = null;
}
}
}
$uri = $request->getStr('url');
$engine = new PhabricatorDestructionEngine();
$file = null;
if ($request->getFileExists('file')) {
$file = PhabricatorFile::newFromPHPUpload($_FILES['file'], array('name' => $request->getStr('name'), 'authorPHID' => $viewer->getPHID(), 'isExplicitUpload' => true, 'canCDN' => true));
} else {
if ($uri) {
try {
// Rate limit outbound fetches to make this mechanism less useful for
// scanning networks and ports.
PhabricatorSystemActionEngine::willTakeAction(array($viewer->getPHID()), new PhabricatorFilesOutboundRequestAction(), 1);
$file = PhabricatorFile::newFromFileDownload($uri, array('name' => $request->getStr('name'), 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE, 'isExplicitUpload' => true, 'canCDN' => true));
if (!$file->isViewableInBrowser()) {
$mime_type = $file->getMimeType();
$engine->destroyObject($file);
$file = null;
throw new Exception(pht('The URI "%s" does not correspond to a valid image file, got ' . 'a file with MIME type "%s". You must specify the URI of a ' . 'valid image file.', $uri, $mime_type));
} else {
$file->setAuthorPHID($viewer->getPHID())->save();
}
} catch (HTTPFutureHTTPResponseStatus $status) {
$errors[] = pht('The URI "%s" could not be loaded, got %s error.', $uri, $status->getStatusCode());
} catch (Exception $ex) {
$errors[] = $ex->getMessage();
}
} else {
if ($request->getStr('phid')) {
$file = id(new PhabricatorFileQuery())->setViewer($viewer)->withPHIDs(array($request->getStr('phid')))->executeOne();
}
}
}
if ($file) {
if (!$file->isViewableInBrowser()) {
$errors[] = pht('You must upload an image.');
$e_file = pht('Invalid');
} else {
$macro->setFilePHID($file->getPHID());
$macro->attachFile($file);
$e_file = null;
}
}
if (!$macro->getID() && !$file) {
$errors[] = pht('You must upload an image to create a macro.');
$e_file = pht('Required');
}
if (!$errors) {
try {
$xactions = array();
if ($new_name !== null) {
$xactions[] = id(new PhabricatorMacroTransaction())->setTransactionType(PhabricatorMacroTransaction::TYPE_NAME)->setNewValue($new_name);
}
if ($file) {
$xactions[] = id(new PhabricatorMacroTransaction())->setTransactionType(PhabricatorMacroTransaction::TYPE_FILE)->setNewValue($file->getPHID());
}
$editor = id(new PhabricatorMacroEditor())->setActor($viewer)->setContinueOnNoEffect(true)->setContentSourceFromRequest($request);
$xactions = $editor->applyTransactions($original, $xactions);
$view_uri = $this->getApplicationURI('/view/' . $original->getID() . '/');
return id(new AphrontRedirectResponse())->setURI($view_uri);
} catch (AphrontDuplicateKeyQueryException $ex) {
throw $ex;
$errors[] = pht('Macro name is not unique!');
$e_name = pht('Duplicate');
}
}
//.........这里部分代码省略.........