Skip to content
Snippets Groups Projects
Commit a58d2706 authored by Christopher Schäpers's avatar Christopher Schäpers
Browse files

Load avatar from path, if one's provided

parent 2bfe6622
No related branches found
No related tags found
No related merge requests found
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment