public function render() { if (!$this->mock) { throw new PhutilInvalidStateException('setMock'); } $mock = $this->mock; $images_to_show = array(); $thumbnail = null; if (!empty($this->images)) { $images_to_show = array_intersect_key($this->mock->getImages(), array_flip($this->images)); } $xform = PhabricatorFileTransform::getTransformByKey(PhabricatorFileThumbnailTransform::TRANSFORM_PINBOARD); if ($images_to_show) { $image = head($images_to_show); $thumbfile = $image->getFile(); $header = 'M' . $mock->getID() . ' ' . $mock->getName() . ' (#' . $image->getID() . ')'; $uri = '/M' . $this->mock->getID() . '/' . $image->getID() . '/'; } else { $thumbfile = $mock->getCoverFile(); $header = 'M' . $mock->getID() . ' ' . $mock->getName(); $uri = '/M' . $this->mock->getID(); } $thumbnail = $thumbfile->getURIForTransform($xform); list($x, $y) = $xform->getTransformedDimensions($thumbfile); $item = id(new PHUIPinboardItemView())->setUser($this->getUser())->setObject($mock)->setHeader($header)->setURI($uri)->setImageURI($thumbnail)->setImageSize($x, $y)->setDisabled($mock->isClosed())->addIconCount('fa-picture-o', count($mock->getImages()))->addIconCount('fa-trophy', $mock->getTokenCount()); return $item; }
protected function renderResultList(array $macros, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($macros, 'PhabricatorFileImageMacro'); $viewer = $this->requireViewer(); $handles = $viewer->loadHandles(mpull($macros, 'getAuthorPHID')); $xform = PhabricatorFileTransform::getTransformByKey(PhabricatorFileThumbnailTransform::TRANSFORM_PINBOARD); $pinboard = new PHUIPinboardView(); foreach ($macros as $macro) { $file = $macro->getFile(); $item = id(new PHUIPinboardItemView())->setUser($viewer)->setObject($macro); if ($file) { $item->setImageURI($file->getURIForTransform($xform)); list($x, $y) = $xform->getTransformedDimensions($file); $item->setImageSize($x, $y); } if ($macro->getDateCreated()) { $datetime = phabricator_date($macro->getDateCreated(), $viewer); $item->appendChild(phutil_tag('div', array(), pht('Created on %s', $datetime))); } else { // Very old macros don't have a creation date. Rendering something // keeps all the pins at the same height and avoids flow issues. $item->appendChild(phutil_tag('div', array(), pht('Created in ages long past'))); } if ($macro->getAuthorPHID()) { $author_handle = $handles[$macro->getAuthorPHID()]; $item->appendChild(pht('Created by %s', $author_handle->renderLink())); } $item->setURI($this->getApplicationURI('/view/' . $macro->getID() . '/')); $item->setDisabled($macro->getisDisabled()); $item->setHeader($macro->getName()); $pinboard->addItem($item); } return $pinboard; }
public function render() { require_celerity_resource('pholio-edit-css'); $image = $this->image; $file = $image->getFile(); $phid = $file->getPHID(); $replaces_phid = $this->replacesPHID; $remove = $this->renderRemoveElement(); $title = id(new AphrontFormTextControl())->setName('title_' . $phid)->setValue($image->getName())->setSigil('image-title')->setLabel(pht('Title')); $description = id(new PhabricatorRemarkupControl())->setUser($this->getUser())->setName('description_' . $phid)->setValue($image->getDescription())->setSigil('image-description')->setLabel(pht('Description')); $xform = PhabricatorFileTransform::getTransformByKey(PhabricatorFileThumbnailTransform::TRANSFORM_PINBOARD); $thumbnail_uri = $file->getURIForTransform($xform); $thumb_frame = phutil_tag('div', array('class' => 'pholio-thumb-frame', 'style' => 'background-image: url(' . $thumbnail_uri . ');')); $handle = javelin_tag('div', array('class' => 'pholio-drag-handle', 'sigil' => 'pholio-drag-handle')); $content = hsprintf('<div class="pholio-thumb-box"> <div class="pholio-thumb-title"> %s <div class="pholio-thumb-name">%s</div> </div> %s </div> <div class="pholio-image-details"> %s %s </div>', $remove, $file->getName(), $thumb_frame, $title, $description); $input = phutil_tag('input', array('type' => 'hidden', 'name' => 'file_phids[]', 'value' => $phid)); $replaces_input = phutil_tag('input', array('type' => 'hidden', 'name' => 'replaces[' . $replaces_phid . ']', 'value' => $phid)); return javelin_tag('div', array('class' => 'pholio-uploaded-image', 'sigil' => 'pholio-drop-image', 'meta' => array('filePHID' => $file->getPHID(), 'replacesPHID' => $replaces_phid)), array($handle, $content, $input, $replaces_input)); }
private function renderThumbnail(PholioImage $image) { $thumbfile = $image->getFile(); $preview_key = PhabricatorFileThumbnailTransform::TRANSFORM_THUMBGRID; $xform = PhabricatorFileTransform::getTransformByKey($preview_key); Javelin::initBehavior('phabricator-tooltips'); $attributes = array('class' => 'pholio-mock-thumb-grid-image', 'src' => $thumbfile->getURIForTransform($xform)); if ($image->getFile()->isViewableImage()) { $dimensions = $xform->getTransformedDimensions($thumbfile); if ($dimensions) { list($x, $y) = $dimensions; $attributes += array('width' => $x, 'height' => $y, 'style' => 'top: ' . floor((100 - $y) / 2) . 'px'); } } else { // If this is a PDF or a text file or something, we'll end up using a // generic thumbnail which is always sized correctly. $attributes += array('width' => 100, 'height' => 100); } $tag = phutil_tag('img', $attributes); $classes = array('pholio-mock-thumb-grid-item'); if ($image->getIsObsolete()) { $classes[] = 'pholio-mock-thumb-grid-item-obsolete'; } $inline_count = null; if ($image->getInlineComments()) { $inline_count[] = phutil_tag('span', array('class' => 'pholio-mock-thumb-grid-comment-count'), pht('%s', new PhutilNumber(count($image->getInlineComments())))); } return javelin_tag('a', array('sigil' => 'mock-thumbnail has-tooltip', 'class' => implode(' ', $classes), 'href' => '#', 'meta' => array('imageID' => $image->getID(), 'tip' => $image->getName(), 'align' => 'N')), array($tag, $inline_count)); }
public function render() { $account = $this->externalAccount; $provider = $this->provider; require_celerity_resource('auth-css'); $content = array(); $dispname = $account->getDisplayName(); $username = $account->getUsername(); $realname = $account->getRealName(); $use_name = null; if (strlen($dispname)) { $use_name = $dispname; } else { if (strlen($username) && strlen($realname)) { $use_name = $username . ' (' . $realname . ')'; } else { if (strlen($username)) { $use_name = $username; } else { if (strlen($realname)) { $use_name = $realname; } else { $use_name = $account->getAccountID(); } } } } $content[] = phutil_tag('div', array('class' => 'auth-account-view-name'), $use_name); if ($provider) { $prov_name = pht('%s Account', $provider->getProviderName()); } else { $prov_name = pht('"%s" Account', $account->getProviderType()); } $content[] = phutil_tag('div', array('class' => 'auth-account-view-provider-name'), array($prov_name, " · ", $account->getAccountID())); $account_uri = $account->getAccountURI(); if (strlen($account_uri)) { // Make sure we don't link a "javascript:" URI if a user somehow // managed to get one here. if (PhabricatorEnv::isValidRemoteURIForLink($account_uri)) { $account_uri = phutil_tag('a', array('href' => $account_uri, 'target' => '_blank'), $account_uri); } $content[] = phutil_tag('div', array('class' => 'auth-account-view-account-uri'), $account_uri); } $image_file = $account->getProfileImageFile(); $xform = PhabricatorFileTransform::getTransformByKey(PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE); $image_uri = $image_file->getURIForTransform($xform); list($x, $y) = $xform->getTransformedDimensions($image_file); $profile_image = phutil_tag('div', array('class' => 'auth-account-view-profile-image', 'style' => 'background-image: url(' . $image_uri . ');')); return phutil_tag('div', array('class' => 'auth-account-view'), array($profile_image, $content)); }
public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $file = id(new PhabricatorFileQuery())->setViewer($viewer)->withIDs(array($request->getURIData('id')))->executeOne(); if (!$file) { return new Aphront404Response(); } $monogram = $file->getMonogram(); $xdst = id(new PhabricatorTransformedFile())->loadAllWhere('transformedPHID = %s', $file->getPHID()); $dst_rows = array(); foreach ($xdst as $source) { $dst_rows[] = array($source->getTransform(), $viewer->renderHandle($source->getOriginalPHID())); } $dst_table = id(new AphrontTableView($dst_rows))->setHeaders(array(pht('Key'), pht('Source')))->setColumnClasses(array('', 'wide'))->setNoDataString(pht('This file was not created by transforming another file.')); $xsrc = id(new PhabricatorTransformedFile())->loadAllWhere('originalPHID = %s', $file->getPHID()); $xsrc = mpull($xsrc, 'getTransformedPHID', 'getTransform'); $src_rows = array(); $xforms = PhabricatorFileTransform::getAllTransforms(); foreach ($xforms as $xform) { $dst_phid = idx($xsrc, $xform->getTransformKey()); if ($xform->canApplyTransform($file)) { $can_apply = pht('Yes'); $view_href = $file->getURIForTransform($xform); $view_href = new PhutilURI($view_href); $view_href->setQueryParam('regenerate', 'true'); $view_text = pht('Regenerate'); $view_link = phutil_tag('a', array('class' => 'small grey button', 'href' => $view_href), $view_text); } else { $can_apply = phutil_tag('em', array(), pht('No')); $view_link = phutil_tag('em', array(), pht('None')); } if ($dst_phid) { $dst_link = $viewer->renderHandle($dst_phid); } else { $dst_link = phutil_tag('em', array(), pht('None')); } $src_rows[] = array($xform->getTransformName(), $xform->getTransformKey(), $can_apply, $dst_link, $view_link); } $src_table = id(new AphrontTableView($src_rows))->setHeaders(array(pht('Name'), pht('Key'), pht('Supported'), pht('Transform'), pht('View')))->setColumnClasses(array('wide', '', '', '', 'action')); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb($monogram, '/' . $monogram); $crumbs->addTextCrumb(pht('Transforms')); $crumbs->setBorder(true); $dst_box = id(new PHUIObjectBoxView())->setHeaderText(pht('File Sources'))->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setTable($dst_table); $src_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Available Transforms'))->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setTable($src_table); $title = pht('%s Transforms', $file->getName()); $header = id(new PHUIHeaderView())->setHeader($title)->setHeaderIcon('fa-arrows-alt'); $view = id(new PHUITwoColumnView())->setHeader($header)->setFooter(array($dst_box, $src_box)); return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view); }
protected function renderResultList(array $mocks, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($mocks, 'PholioMock'); $viewer = $this->requireViewer(); $handles = $viewer->loadHandles(mpull($mocks, 'getAuthorPHID')); $xform = PhabricatorFileTransform::getTransformByKey(PhabricatorFileThumbnailTransform::TRANSFORM_PINBOARD); $board = new PHUIPinboardView(); foreach ($mocks as $mock) { $image = $mock->getCoverFile(); $image_uri = $image->getURIForTransform($xform); list($x, $y) = $xform->getTransformedDimensions($image); $header = 'M' . $mock->getID() . ' ' . $mock->getName(); $item = id(new PHUIPinboardItemView())->setUser($viewer)->setHeader($header)->setObject($mock)->setURI('/M' . $mock->getID())->setImageURI($image_uri)->setImageSize($x, $y)->setDisabled($mock->isClosed())->addIconCount('fa-picture-o', count($mock->getImages()))->addIconCount('fa-trophy', $mock->getTokenCount()); if ($mock->getAuthorPHID()) { $author_handle = $handles[$mock->getAuthorPHID()]; $datetime = phabricator_date($mock->getDateCreated(), $viewer); $item->appendChild(pht('By %s on %s', $author_handle->renderLink(), $datetime)); } $board->addItem($item); } return $board; }
public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $id = $request->getURIData('id'); $user = id(new PhabricatorPeopleQuery())->setViewer($viewer)->withIDs(array($id))->needProfileImage(true)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne(); if (!$user) { return new Aphront404Response(); } $this->setUser($user); $done_uri = $this->getApplicationURI("manage/{$id}/"); $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 profile 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) { $user->setProfileImagePHID(null); } else { $user->setProfileImagePHID($xformed->getPHID()); $xformed->attachToObject($user->getPHID()); } $user->save(); return id(new AphrontRedirectResponse())->setURI($done_uri); } } $title = pht('Edit Profile Picture'); $form = id(new PHUIFormLayoutView())->setUser($viewer); $default_image = PhabricatorFile::loadBuiltin($viewer, 'profile.png'); $images = array(); $current = $user->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')); } } } $builtins = array('user1.png', 'user2.png', 'user3.png', 'user4.png', 'user5.png', 'user6.png', 'user7.png', 'user8.png', 'user9.png'); foreach ($builtins as $builtin) { $file = PhabricatorFile::loadBuiltin($viewer, $builtin); $images[$file->getPHID()] = array('uri' => $file->getBestURI(), 'tip' => pht('Builtin Image')); } // Try to add external account images for any associated external accounts. $accounts = id(new PhabricatorExternalAccountQuery())->setViewer($viewer)->withUserPHIDs(array($user->getPHID()))->needImages(true)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->execute(); foreach ($accounts as $account) { $file = $account->getProfileImageFile(); if ($account->getProfileImagePHID() != $file->getPHID()) { // This is a default image, just skip it. continue; } $provider = PhabricatorAuthProvider::getEnabledProviderByKey($account->getProviderKey()); if ($provider) { $tip = pht('Picture From %s', $provider->getProviderName()); } else { $tip = pht('Picture From External Account'); } if ($file->isTransformableImage()) { $images[$file->getPHID()] = array('uri' => $file->getBestURI(), 'tip' => $tip); } } $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)->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($done_uri)->setValue(pht('Upload Picture'))); $upload_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Upload New Picture'))->setForm($upload_form); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Edit Profile Picture')); return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild(array($form_box, $upload_box)); }
private function renderImageFile(PhabricatorFile $file, PhabricatorObjectHandle $handle, array $options) { require_celerity_resource('lightbox-attachment-css'); $attrs = array(); $image_class = null; $use_size = true; if (!$options['size']) { $width = $this->parseDimension($options['width']); $height = $this->parseDimension($options['height']); if ($width || $height) { $use_size = false; $attrs += array('src' => $file->getBestURI(), 'width' => $width, 'height' => $height); } } if ($use_size) { switch ((string) $options['size']) { case 'full': $attrs += array('src' => $file->getBestURI(), 'height' => $file->getImageHeight(), 'width' => $file->getImageWidth()); $image_class = 'phabricator-remarkup-embed-image-full'; break; case 'thumb': default: $preview_key = PhabricatorFileThumbnailTransform::TRANSFORM_PREVIEW; $xform = PhabricatorFileTransform::getTransformByKey($preview_key); $attrs['src'] = $file->getURIForTransform($xform); $dimensions = $xform->getTransformedDimensions($file); if ($dimensions) { list($x, $y) = $dimensions; $attrs['width'] = $x; $attrs['height'] = $y; } $image_class = 'phabricator-remarkup-embed-image'; break; } } if (isset($options['alt'])) { $attrs['alt'] = $options['alt']; } $img = phutil_tag('img', $attrs); $embed = javelin_tag('a', array('href' => $file->getBestURI(), 'class' => $image_class, 'sigil' => 'lightboxable', 'meta' => array('phid' => $file->getPHID(), 'uri' => $file->getBestURI(), 'dUri' => $file->getDownloadURI(), 'viewable' => true)), $img); switch ($options['layout']) { case 'right': case 'center': case 'inline': case 'left': $layout_class = 'phabricator-remarkup-embed-layout-' . $options['layout']; break; default: $layout_class = 'phabricator-remarkup-embed-layout-left'; break; } if ($options['float']) { switch ($options['layout']) { case 'center': case 'inline': break; case 'right': $layout_class .= ' phabricator-remarkup-embed-float-right'; break; case 'left': default: $layout_class .= ' phabricator-remarkup-embed-float-left'; break; } } return phutil_tag($options['layout'] == 'inline' ? 'span' : 'div', array('class' => $layout_class), $embed); }
private function loadProfilePicture(PhabricatorExternalAccount $account) { $phid = $account->getProfileImagePHID(); if (!$phid) { return null; } // NOTE: Use of omnipotent user is okay here because the registering user // can not control the field value, and we can't use their user object to // do meaningful policy checks anyway since they have not registered yet. // Reaching this means the user holds the account secret key and the // registration secret key, and thus has permission to view the image. $file = id(new PhabricatorFileQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withPHIDs(array($phid))->executeOne(); if (!$file) { return null; } $xform = PhabricatorFileTransform::getTransformByKey(PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE); return $xform->executeTransform($file); }
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)); }
public function processRequest() { $request = $this->getRequest(); $viewer = $request->getUser(); $id = $request->getURIData('id'); $project = id(new PhabricatorProjectQuery())->setViewer($viewer)->withIDs(array($this->id))->needImages(true)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne(); if (!$project) { return new Aphront404Response(); } $edit_uri = $this->getApplicationURI('profile/' . $project->getID() . '/'); $view_uri = $this->getApplicationURI('profile/' . $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 { $xform = PhabricatorFileTransform::getTransformByKey(PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE); $xformed = $xform->executeTransform($file); } } 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'); $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)); $default_button = javelin_tag('button', array('class' => 'grey'), pht('Use Project Icon')); $default_input = javelin_tag('input', array('type' => 'hidden', 'name' => 'projectPHID', 'value' => $project->getPHID())); $default_form = phabricator_form($viewer, array('class' => 'profile-image-form', 'method' => 'POST', 'action' => '/file/compose/'), array($default_input, $default_button)); $form->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Use Default'))->setValue($default_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); $nav = $this->buildIconNavView($project); $nav->selectFilter("edit/{$id}/"); $nav->appendChild($form_box); $nav->appendChild($upload_box); return $this->buildApplicationPage($nav, array('title' => $title)); }
protected function applyCustomInternalTransaction(PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction) { switch ($xaction->getTransactionType()) { case ManiphestTransaction::TYPE_PRIORITY: return $object->setPriority($xaction->getNewValue()); case ManiphestTransaction::TYPE_STATUS: return $object->setStatus($xaction->getNewValue()); case ManiphestTransaction::TYPE_TITLE: return $object->setTitle($xaction->getNewValue()); case ManiphestTransaction::TYPE_DESCRIPTION: return $object->setDescription($xaction->getNewValue()); case ManiphestTransaction::TYPE_OWNER: $phid = $xaction->getNewValue(); // Update the "ownerOrdering" column to contain the full name of the // owner, if the task is assigned. $handle = null; if ($phid) { $handle = id(new PhabricatorHandleQuery())->setViewer($this->getActor())->withPHIDs(array($phid))->executeOne(); } if ($handle) { $object->setOwnerOrdering($handle->getName()); } else { $object->setOwnerOrdering(null); } return $object->setOwnerPHID($phid); case ManiphestTransaction::TYPE_SUBPRIORITY: $object->setSubpriority($xaction->getNewValue()); return; case ManiphestTransaction::TYPE_MERGED_INTO: $object->setStatus(ManiphestTaskStatus::getDuplicateStatus()); return; case ManiphestTransaction::TYPE_COVER_IMAGE: $file_phid = $xaction->getNewValue(); if ($file_phid) { $file = id(new PhabricatorFileQuery())->setViewer($this->getActor())->withPHIDs(array($file_phid))->executeOne(); } else { $file = null; } if (!$file || !$file->isTransformableImage()) { $object->setProperty('cover.filePHID', null); $object->setProperty('cover.thumbnailPHID', null); return; } $xform_key = PhabricatorFileThumbnailTransform::TRANSFORM_WORKCARD; $xform = PhabricatorFileTransform::getTransformByKey($xform_key)->executeTransform($file); $object->setProperty('cover.filePHID', $file->getPHID()); $object->setProperty('cover.thumbnailPHID', $xform->getPHID()); return; case ManiphestTransaction::TYPE_POINTS: $object->setPoints($xaction->getNewValue()); return; case ManiphestTransaction::TYPE_MERGED_FROM: case ManiphestTransaction::TYPE_PARENT: case PhabricatorTransactions::TYPE_COLUMNS: return; } }
<?php // Rebuild all Conpherence Room images to profile standards // $table = new ConpherenceThread(); $conn = $table->establishConnection('w'); $table_name = 'conpherence_thread'; foreach (new LiskRawMigrationIterator($conn, $table_name) as $row) { $images = phutil_json_decode($row['imagePHIDs']); if (!$images) { continue; } $file_phid = idx($images, 'original'); $file = id(new PhabricatorFileQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withPHIDs(array($file_phid))->executeOne(); $xform = PhabricatorFileTransform::getTransformByKey(PhabricatorFileThumbnailTransform::TRANSFORM_PROFILE); $xformed = $xform->executeTransform($file); $new_phid = $xformed->getPHID(); queryfx($conn, 'UPDATE %T SET profileImagePHID = %s WHERE id = %d', $table->getTableName(), $new_phid, $row['id']); }
public function getURIForTransform(PhabricatorFileTransform $transform) { return $this->getTransformedURI($transform->getTransformKey()); }
public function testGetAllTransforms() { PhabricatorFileTransform::getAllTransforms(); $this->assertTrue(true); }
public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); // NOTE: This is a public/CDN endpoint, and permission to see files is // controlled by knowing the secret key, not by authentication. $is_regenerate = $request->getBool('regenerate'); $source_phid = $request->getURIData('phid'); $file = id(new PhabricatorFileQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withPHIDs(array($source_phid))->executeOne(); if (!$file) { return new Aphront404Response(); } $secret_key = $request->getURIData('key'); if (!$file->validateSecretKey($secret_key)) { return new Aphront403Response(); } $transform = $request->getURIData('transform'); $xform = $this->loadTransform($source_phid, $transform); if ($xform) { if ($is_regenerate) { $this->destroyTransform($xform); } else { return $this->buildTransformedFileResponse($xform); } } $xforms = PhabricatorFileTransform::getAllTransforms(); if (!isset($xforms[$transform])) { return new Aphront404Response(); } $xform = $xforms[$transform]; // We're essentially just building a cache here and don't need CSRF // protection. $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); $xformed_file = null; if ($xform->canApplyTransform($file)) { try { $xformed_file = $xforms[$transform]->applyTransform($file); } catch (Exception $ex) { // In normal transform mode, we ignore failures and generate a // default transform below. If we're explicitly regenerating the // thumbnail, rethrow the exception. if ($is_regenerate) { throw $ex; } } } if (!$xformed_file) { $xformed_file = $xform->getDefaultTransform($file); } if (!$xformed_file) { return new Aphront400Response(); } $xform = id(new PhabricatorTransformedFile())->setOriginalPHID($source_phid)->setTransform($transform)->setTransformedPHID($xformed_file->getPHID()); try { $xform->save(); } catch (AphrontDuplicateKeyQueryException $ex) { // If we collide when saving, we've raced another endpoint which was // transforming the same file. Just throw our work away and use that // transform instead. $this->destroyTransform($xform); $xform = $this->loadTransform($source_phid, $transform); if (!$xform) { return new Aphront404Response(); } } return $this->buildTransformedFileResponse($xform); }