Better naming than "ava" & "data", cache timeout, use OC.Router.registerLoadedCallback()
This commit is contained in:
parent
8de9e3d85e
commit
f44cd944e0
|
@ -41,25 +41,25 @@ class OC_Core_Avatar_Controller {
|
||||||
if (isset($_POST['path'])) {
|
if (isset($_POST['path'])) {
|
||||||
$path = stripslashes($_POST['path']);
|
$path = stripslashes($_POST['path']);
|
||||||
$view = new \OC\Files\View('/'.$user.'/files');
|
$view = new \OC\Files\View('/'.$user.'/files');
|
||||||
$avatar = $view->file_get_contents($path);
|
$newAvatar = $view->file_get_contents($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($_FILES)) {
|
if (!empty($_FILES)) {
|
||||||
$files = $_FILES['files'];
|
$files = $_FILES['files'];
|
||||||
if ($files['error'][0] === 0) {
|
if ($files['error'][0] === 0) {
|
||||||
$avatar = file_get_contents($files['tmp_name'][0]);
|
$newAvatar = file_get_contents($files['tmp_name'][0]);
|
||||||
unlink($files['tmp_name'][0]);
|
unlink($files['tmp_name'][0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$ava = new \OC_Avatar();
|
$avatar = new \OC_Avatar();
|
||||||
$ava->set($user, $avatar);
|
$avatar->set($user, $newAvatar);
|
||||||
\OC_JSON::success();
|
\OC_JSON::success();
|
||||||
} catch (\OC\NotSquareException $e) {
|
} catch (\OC\NotSquareException $e) {
|
||||||
$image = new \OC_Image($avatar);
|
$image = new \OC_Image($newAvatar);
|
||||||
|
|
||||||
\OC_Cache::set('tmpavatar', $image->data());
|
\OC_Cache::set('tmpavatar', $image->data(), 7200);
|
||||||
\OC_JSON::error(array("data" => array("message" => "notsquare") ));
|
\OC_JSON::error(array("data" => array("message" => "notsquare") ));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
\OC_JSON::error(array("data" => array("message" => $e->getMessage()) ));
|
\OC_JSON::error(array("data" => array("message" => $e->getMessage()) ));
|
||||||
|
|
|
@ -3,7 +3,7 @@ $(document).ready(function(){
|
||||||
// Personal settings
|
// Personal settings
|
||||||
$('#avatar .avatardiv').avatar(OC.currentUser, 128);
|
$('#avatar .avatardiv').avatar(OC.currentUser, 128);
|
||||||
// User settings
|
// User settings
|
||||||
$.each($('td.avatar .avatardiv'), function(i, data) {
|
$.each($('td.avatar .avatardiv'), function(i, element) {
|
||||||
$(data).avatar($(data).parent().parent().data('uid'), 32);
|
$(element).avatar($(element).parent().parent().data('uid'), 32);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -61,13 +61,15 @@
|
||||||
|
|
||||||
var $div = this;
|
var $div = this;
|
||||||
|
|
||||||
var url = OC.router_base_url+'/avatar/'+user+'/'+size // FIXME routes aren't loaded yet, so OC.Router.generate() doesn't work
|
OC.Router.registerLoadedCallback(function() {
|
||||||
$.get(url, function(result) {
|
var url = OC.Router.generate('core_avatar_get', {user: user, size: size});
|
||||||
if (typeof(result) === 'object') {
|
$.get(url, function(result) {
|
||||||
$div.placeholder(result.user);
|
if (typeof(result) === 'object') {
|
||||||
} else {
|
$div.placeholder(result.user);
|
||||||
$div.html('<img src="'+url+'">');
|
} else {
|
||||||
}
|
$div.html('<img src="'+url+'">');
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}(jQuery));
|
}(jQuery));
|
||||||
|
|
Loading…
Reference in New Issue