ALTER TABLE wcf1_user_group_option ADD usersOnly TINYINT(1) NOT NULL DEFAULT 0;
+ALTER TABLE wcf1_user ADD gravatarFileExtension VARCHAR(3) NOT NULL DEFAULT '';
+
/* truncate table to ensure consistency */
DELETE FROM wcf1_user_notification;
use wcf\system\exception\IllegalLinkException;
use wcf\system\exception\SystemException;
use wcf\util\FileUtil;
+use wcf\util\HTTPRequest;
/**
* Downloads and caches gravatars.
parent::execute();
if ($this->user->enableGravatar) {
+ $fileExtension = ($this->user->gravatarFileExtension ?: 'png');
+
// try to use cached gravatar
- $cachedFilename = sprintf(Gravatar::GRAVATAR_CACHE_LOCATION, md5(mb_strtolower($this->user->email)), $this->size);
+ $cachedFilename = sprintf(Gravatar::GRAVATAR_CACHE_LOCATION, md5(mb_strtolower($this->user->email)), $this->size, $fileExtension);
if (file_exists(WCF_DIR.$cachedFilename) && filemtime(WCF_DIR.$cachedFilename) > (TIME_NOW - (Gravatar::GRAVATAR_CACHE_EXPIRE * 86400))) {
@header('Content-Type: image/png');
@readfile(WCF_DIR.$cachedFilename);
// try to download new version
$gravatarURL = sprintf(Gravatar::GRAVATAR_BASE, md5(mb_strtolower($this->user->email)), $this->size, GRAVATAR_DEFAULT_TYPE);
try {
- $tmpFile = FileUtil::downloadFileFromHttp($gravatarURL, 'gravatar');
- copy($tmpFile, WCF_DIR.$cachedFilename);
- @unlink($tmpFile);
+ $request = new HTTPRequest($gravatarURL);
+ $request->execute();
+ $reply = $request->getReply();
+
+ // get mime type and file extension
+ $fileExtension = 'png';
+ $mimeType = 'image/png';
+ if (isset($reply['headers']['Content-Type'])) {
+ switch ($reply['headers']['Content-Type']) {
+ case 'image/jpeg':
+ $mimeType = 'image/jpeg';
+ $fileExtension = 'jpg';
+ break;
+ case 'image/gif':
+ $mimeType = 'image/gif';
+ $fileExtension = 'gif';
+ break;
+ }
+ }
+
+ // save file
+ $cachedFilename = sprintf(Gravatar::GRAVATAR_CACHE_LOCATION, md5(mb_strtolower($this->user->email)), $this->size, $fileExtension);
+ file_put_contents(WCF_DIR.$cachedFilename, $reply['body']);
FileUtil::makeWritable(WCF_DIR.$cachedFilename);
- @header('Content-Type: image/png');
+ // file file extension
+ if ($fileExtension != $this->user->gravatarFileExtension) {
+ $editor = new UserEditor($this->user);
+ $editor->update(array(
+ 'gravatarFileExtension' => $fileExtension
+ ));
+ }
+
+ @header('Content-Type: '.$mimeType);
@readfile(WCF_DIR.$cachedFilename);
exit;
}
}
}
else if (MODULE_GRAVATAR && $this->enableGravatar) {
- $this->avatar = new Gravatar($this->userID, $this->email);
+ $this->avatar = new Gravatar($this->userID, $this->email, ($this->gravatarFileExtension ?: 'png'));
}
}
}
* gravatar local cache location
* @var string
*/
- const GRAVATAR_CACHE_LOCATION = 'images/avatars/gravatars/%s-%s.png';
+ const GRAVATAR_CACHE_LOCATION = 'images/avatars/gravatars/%s-%s.%s';
/**
* gravatar expire time (days)
*/
public $gravatar = '';
+ /**
+ * file extension of the gravatar image
+ * @var string
+ */
+ public $fileExtension = 'png';
+
/**
* urls of this gravatar
* @var array<string>
* @param integer $userID
* @param string $gravatar
*/
- public function __construct($userID, $gravatar) {
+ public function __construct($userID, $gravatar, $fileExtension = 'png') {
$this->userID = $userID;
$this->gravatar = $gravatar;
+ $this->fileExtension = $fileExtension;
}
/**
if (!isset($this->url[$size])) {
// try to use cached gravatar
- $cachedFilename = sprintf(self::GRAVATAR_CACHE_LOCATION, md5(mb_strtolower($this->gravatar)), $size);
+ $cachedFilename = sprintf(self::GRAVATAR_CACHE_LOCATION, md5(mb_strtolower($this->gravatar)), $size, $this->fileExtension);
if (file_exists(WCF_DIR.$cachedFilename) && filemtime(WCF_DIR.$cachedFilename) > (TIME_NOW - (self::GRAVATAR_CACHE_EXPIRE * 86400))) {
$this->url[$size] = WCF::getPath().$cachedFilename;
}
public function __construct() {
parent::__construct();
- $this->sqlSelects .= "user_table.username, user_table.email, user_table.disableAvatar, user_table.enableGravatar";
+ $this->sqlSelects .= "user_table.username, user_table.email, user_table.disableAvatar, user_table.enableGravatar, user_table.gravatarFileExtension";
$this->sqlSelects .= ", user_avatar.*";
$this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_user user_table ON (user_table.userID = user_follow.userID)";
public function __construct() {
parent::__construct();
- $this->sqlSelects .= "user_table.username, user_table.email, user_table.disableAvatar, user_table.enableGravatar";
+ $this->sqlSelects .= "user_table.username, user_table.email, user_table.disableAvatar, user_table.enableGravatar, user_table.gravatarFileExtension";
$this->sqlSelects .= ", user_avatar.*";
$this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_user user_table ON (user_table.userID = user_profile_visitor.userID)";
disableAvatarReason TEXT,
disableAvatarExpires INT(10) NOT NULL DEFAULT 0,
enableGravatar TINYINT(1) NOT NULL DEFAULT 0,
+ gravatarFileExtension VARCHAR(3) NOT NULL DEFAULT '',
signature TEXT,
signatureEnableBBCodes TINYINT(1) NOT NULL DEFAULT 1,
signatureEnableHtml TINYINT(1) NOT NULL DEFAULT 0,