1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 09:12:41 +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:
Brennan Taylor 2013-02-04 15:28:09 -08:00 committed by epriestley
parent 22d5eee82a
commit 1322e9eda2
3 changed files with 52 additions and 47 deletions

View file

@ -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) {

View file

@ -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;
} }

View file

@ -46,17 +46,33 @@ 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(); $okay = $file->isTransformableImage();
if ($okay) { if ($okay) {
$xformer = new PhabricatorImageTransformer(); $xformer = new PhabricatorImageTransformer();
@ -83,7 +99,6 @@ final class PhabricatorSettingsPanelProfile
implode(', ', $supported_formats).'.'; implode(', ', $supported_formats).'.';
} }
} }
}
if (!$errors) { if (!$errors) {
$user->save(); $user->save();
@ -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')