mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 01:02:42 +01:00
Implement import profile picture from Gravatar
Summary: Add a field where you can put the gravatar email address to pull an image for the profile picture from Test Plan: Tried uploading a file, replacing with default, and various combinations and they all still work. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2105 Differential Revision: https://secure.phabricator.com/D4809
This commit is contained in:
parent
22d5eee82a
commit
1322e9eda2
3 changed files with 52 additions and 47 deletions
|
@ -271,7 +271,7 @@ final class PhabricatorFile extends PhabricatorFileDAO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function newFromFileDownload($uri, $name) {
|
public static function newFromFileDownload($uri, array $params) {
|
||||||
$uri = new PhutilURI($uri);
|
$uri = new PhutilURI($uri);
|
||||||
|
|
||||||
$protocol = $uri->getProtocol();
|
$protocol = $uri->getProtocol();
|
||||||
|
@ -286,12 +286,11 @@ final class PhabricatorFile extends PhabricatorFileDAO
|
||||||
|
|
||||||
$timeout = 5;
|
$timeout = 5;
|
||||||
|
|
||||||
$file_data = HTTPSFuture::loadContent($uri, $timeout);
|
list($file_data) = id(new HTTPSFuture($uri))
|
||||||
if ($file_data === false) {
|
->setTimeout($timeout)
|
||||||
return null;
|
->resolvex();
|
||||||
}
|
|
||||||
|
|
||||||
return self::newFromFileData($file_data, array('name' => $name));
|
return self::newFromFileData($file_data, $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function normalizeFileName($file_name) {
|
public static function normalizeFileName($file_name) {
|
||||||
|
|
|
@ -19,21 +19,6 @@ final class PhabricatorFileImageMacro extends PhabricatorFileDAO
|
||||||
PhabricatorPHIDConstants::PHID_TYPE_MCRO);
|
PhabricatorPHIDConstants::PHID_TYPE_MCRO);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function newFromImageURI($uri, $file_name, $image_macro_name) {
|
|
||||||
$file = PhabricatorFile::newFromFileDownload($uri, $file_name);
|
|
||||||
|
|
||||||
if (!$file) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$image_macro = new PhabricatorFileImageMacro();
|
|
||||||
$image_macro->setName($image_macro_name);
|
|
||||||
$image_macro->setFilePHID($file->getPHID());
|
|
||||||
$image_macro->save();
|
|
||||||
|
|
||||||
return $image_macro;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isAutomaticallySubscribed($phid) {
|
public function isAutomaticallySubscribed($phid) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,42 +46,57 @@ final class PhabricatorSettingsPanelProfile
|
||||||
$user->setTranslation($request->getStr('translation'));
|
$user->setTranslation($request->getStr('translation'));
|
||||||
|
|
||||||
$default_image = $request->getExists('default_image');
|
$default_image = $request->getExists('default_image');
|
||||||
|
$gravatar_email = $request->getStr('gravatar');
|
||||||
if ($default_image) {
|
if ($default_image) {
|
||||||
$profile->setProfileImagePHID(null);
|
$profile->setProfileImagePHID(null);
|
||||||
$user->setProfileImagePHID(null);
|
$user->setProfileImagePHID(null);
|
||||||
} else if (!empty($_FILES['image'])) {
|
} else if (!empty($gravatar_email) || $request->getFileExists('image')) {
|
||||||
$err = idx($_FILES['image'], 'error');
|
$file = null;
|
||||||
if ($err != UPLOAD_ERR_NO_FILE) {
|
if (!empty($gravatar_email)) {
|
||||||
|
// These steps recommended by:
|
||||||
|
// https://en.gravatar.com/site/implement/hash/
|
||||||
|
$trimmed = trim($gravatar_email);
|
||||||
|
$lower_cased = strtolower($trimmed);
|
||||||
|
$hash = md5($lower_cased);
|
||||||
|
$url = 'http://www.gravatar.com/avatar/'.($hash).'?s=200';
|
||||||
|
$file = PhabricatorFile::newFromFileDownload(
|
||||||
|
$url,
|
||||||
|
array(
|
||||||
|
'name' => 'gravatar',
|
||||||
|
'authorPHID' => $user->getPHID(),
|
||||||
|
));
|
||||||
|
} else if ($request->getFileExists('image')) {
|
||||||
$file = PhabricatorFile::newFromPHPUpload(
|
$file = PhabricatorFile::newFromPHPUpload(
|
||||||
$_FILES['image'],
|
$_FILES['image'],
|
||||||
array(
|
array(
|
||||||
'authorPHID' => $user->getPHID(),
|
'authorPHID' => $user->getPHID(),
|
||||||
));
|
));
|
||||||
$okay = $file->isTransformableImage();
|
}
|
||||||
if ($okay) {
|
|
||||||
$xformer = new PhabricatorImageTransformer();
|
|
||||||
|
|
||||||
// Generate the large picture for the profile page.
|
$okay = $file->isTransformableImage();
|
||||||
$large_xformed = $xformer->executeProfileTransform(
|
if ($okay) {
|
||||||
$file,
|
$xformer = new PhabricatorImageTransformer();
|
||||||
$width = 280,
|
|
||||||
$min_height = 140,
|
|
||||||
$max_height = 420);
|
|
||||||
$profile->setProfileImagePHID($large_xformed->getPHID());
|
|
||||||
|
|
||||||
// Generate the small picture for comments, etc.
|
// Generate the large picture for the profile page.
|
||||||
$small_xformed = $xformer->executeProfileTransform(
|
$large_xformed = $xformer->executeProfileTransform(
|
||||||
$file,
|
$file,
|
||||||
$width = 50,
|
$width = 280,
|
||||||
$min_height = 50,
|
$min_height = 140,
|
||||||
$max_height = 50);
|
$max_height = 420);
|
||||||
$user->setProfileImagePHID($small_xformed->getPHID());
|
$profile->setProfileImagePHID($large_xformed->getPHID());
|
||||||
} else {
|
|
||||||
$e_image = 'Not Supported';
|
// Generate the small picture for comments, etc.
|
||||||
$errors[] =
|
$small_xformed = $xformer->executeProfileTransform(
|
||||||
'This server only supports these image formats: '.
|
$file,
|
||||||
implode(', ', $supported_formats).'.';
|
$width = 50,
|
||||||
}
|
$min_height = 50,
|
||||||
|
$max_height = 50);
|
||||||
|
$user->setProfileImagePHID($small_xformed->getPHID());
|
||||||
|
} else {
|
||||||
|
$e_image = 'Not Supported';
|
||||||
|
$errors[] =
|
||||||
|
'This server only supports these image formats: '.
|
||||||
|
implode(', ', $supported_formats).'.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,6 +205,12 @@ final class PhabricatorSettingsPanelProfile
|
||||||
->setName('image')
|
->setName('image')
|
||||||
->setError($e_image)
|
->setError($e_image)
|
||||||
->setCaption('Supported formats: '.implode(', ', $supported_formats)))
|
->setCaption('Supported formats: '.implode(', ', $supported_formats)))
|
||||||
|
->appendChild(
|
||||||
|
id(new AphrontFormTextControl())
|
||||||
|
->setLabel('Import Gravatar')
|
||||||
|
->setName('gravatar')
|
||||||
|
->setError($e_image)
|
||||||
|
->setCaption('Enter gravatar email address'))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormSubmitControl())
|
id(new AphrontFormSubmitControl())
|
||||||
->setValue('Save')
|
->setValue('Save')
|
||||||
|
|
Loading…
Reference in a new issue