mirror of
https://github.com/nextcloud/server.git
synced 2026-06-03 13:58:55 -04:00
Load avatar from path, if one's provided
This commit is contained in:
parent
2bfe662235
commit
a58d270684
2 changed files with 9 additions and 13 deletions
|
|
@ -42,21 +42,21 @@ class OC_Avatar {
|
|||
/**
|
||||
* @brief sets the users local avatar
|
||||
* @param $user string user to set the avatar for
|
||||
* @param $img mixed imagedata to set a new avatar, or false to delete the current avatar
|
||||
* @param $data mixed imagedata or path to set a new avatar, or false to delete the current avatar
|
||||
* @throws Exception if the provided file is not a jpg or png image
|
||||
* @throws Exception if the provided image is not valid, or not a square
|
||||
* @return true on success
|
||||
*/
|
||||
public static function setLocalAvatar ($user, $img) {
|
||||
public static function setLocalAvatar ($user, $data) {
|
||||
$view = new \OC\Files\View('/'.$user);
|
||||
|
||||
if ($img === false) {
|
||||
if ($data === false) {
|
||||
$view->unlink('avatar.jpg');
|
||||
$view->unlink('avatar.png');
|
||||
return true;
|
||||
} else {
|
||||
$img = new OC_Image($img);
|
||||
// FIXME this always says "image/png"
|
||||
$img = new OC_Image($data);
|
||||
// FIXME this always says "image/png", when loading from data
|
||||
$type = substr($img->mimeType(), -3);
|
||||
if ($type === 'peg') { $type = 'jpg'; }
|
||||
if ($type !== 'jpg' && $type !== 'png') {
|
||||
|
|
@ -69,7 +69,7 @@ class OC_Avatar {
|
|||
|
||||
$view->unlink('avatar.jpg');
|
||||
$view->unlink('avatar.png');
|
||||
$view->file_put_contents('avatar.'.$type, $img);
|
||||
$view->file_put_contents('avatar.'.$type, $data);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,16 +5,12 @@ OC_JSON::callCheck();
|
|||
$user = OC_User::getUser();
|
||||
|
||||
if(isset($_POST['path'])) {
|
||||
$path = $_POST['path'];
|
||||
if ($path === "false") { // delete avatar
|
||||
if ($_POST['path'] === "false") { // delete avatar
|
||||
\OC_Avatar::setLocalAvatar($user, false);
|
||||
} else { // select an image from own files
|
||||
$view = new \OC\Files\View('/'.$user.'/files');
|
||||
$img = $view->file_get_contents($path);
|
||||
|
||||
$type = substr($path, -3);
|
||||
try {
|
||||
\OC_Avatar::setLocalAvatar($user, $img);
|
||||
$path = OC::$SERVERROOT.'/data/'.$user.'/files'.$_POST['path'];
|
||||
\OC_Avatar::setLocalAvatar($user, $path);
|
||||
OC_JSON::success();
|
||||
} catch (Exception $e) {
|
||||
OC_JSON::error();
|
||||
|
|
|
|||
Loading…
Reference in a new issue