diff --git a/src/applications/files/storage/PhabricatorFile.php b/src/applications/files/storage/PhabricatorFile.php index 56fdbbf38b..8a9f486644 100644 --- a/src/applications/files/storage/PhabricatorFile.php +++ b/src/applications/files/storage/PhabricatorFile.php @@ -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); $protocol = $uri->getProtocol(); @@ -286,12 +286,11 @@ final class PhabricatorFile extends PhabricatorFileDAO $timeout = 5; - $file_data = HTTPSFuture::loadContent($uri, $timeout); - if ($file_data === false) { - return null; - } + list($file_data) = id(new HTTPSFuture($uri)) + ->setTimeout($timeout) + ->resolvex(); - return self::newFromFileData($file_data, array('name' => $name)); + return self::newFromFileData($file_data, $params); } public static function normalizeFileName($file_name) { diff --git a/src/applications/macro/storage/PhabricatorFileImageMacro.php b/src/applications/macro/storage/PhabricatorFileImageMacro.php index 2575ffe3e2..9c59f9699f 100644 --- a/src/applications/macro/storage/PhabricatorFileImageMacro.php +++ b/src/applications/macro/storage/PhabricatorFileImageMacro.php @@ -19,21 +19,6 @@ final class PhabricatorFileImageMacro extends PhabricatorFileDAO 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) { return false; } diff --git a/src/applications/settings/panel/PhabricatorSettingsPanelProfile.php b/src/applications/settings/panel/PhabricatorSettingsPanelProfile.php index 3eb398aa4b..75cc676da2 100644 --- a/src/applications/settings/panel/PhabricatorSettingsPanelProfile.php +++ b/src/applications/settings/panel/PhabricatorSettingsPanelProfile.php @@ -46,42 +46,57 @@ final class PhabricatorSettingsPanelProfile $user->setTranslation($request->getStr('translation')); $default_image = $request->getExists('default_image'); + $gravatar_email = $request->getStr('gravatar'); if ($default_image) { $profile->setProfileImagePHID(null); $user->setProfileImagePHID(null); - } else if (!empty($_FILES['image'])) { - $err = idx($_FILES['image'], 'error'); - if ($err != UPLOAD_ERR_NO_FILE) { + } else if (!empty($gravatar_email) || $request->getFileExists('image')) { + $file = null; + 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( $_FILES['image'], array( 'authorPHID' => $user->getPHID(), )); - $okay = $file->isTransformableImage(); - if ($okay) { - $xformer = new PhabricatorImageTransformer(); + } - // Generate the large picture for the profile page. - $large_xformed = $xformer->executeProfileTransform( - $file, - $width = 280, - $min_height = 140, - $max_height = 420); - $profile->setProfileImagePHID($large_xformed->getPHID()); + $okay = $file->isTransformableImage(); + if ($okay) { + $xformer = new PhabricatorImageTransformer(); - // Generate the small picture for comments, etc. - $small_xformed = $xformer->executeProfileTransform( - $file, - $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).'.'; - } + // Generate the large picture for the profile page. + $large_xformed = $xformer->executeProfileTransform( + $file, + $width = 280, + $min_height = 140, + $max_height = 420); + $profile->setProfileImagePHID($large_xformed->getPHID()); + + // Generate the small picture for comments, etc. + $small_xformed = $xformer->executeProfileTransform( + $file, + $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') ->setError($e_image) ->setCaption('Supported formats: '.implode(', ', $supported_formats))) + ->appendChild( + id(new AphrontFormTextControl()) + ->setLabel('Import Gravatar') + ->setName('gravatar') + ->setError($e_image) + ->setCaption('Enter gravatar email address')) ->appendChild( id(new AphrontFormSubmitControl()) ->setValue('Save')