Merge pull request #3471 from annando/issue-3309

Issue 3309: Avatar update should work now
This commit is contained in:
Hypolite Petovan 2017-05-17 12:42:34 -04:00 committed by GitHub
commit 173372eda5
3 changed files with 46 additions and 13 deletions

View File

@ -778,8 +778,7 @@ function guess_image_type($filename, $fromcurl=false) {
* @return array Returns array of the different avatar sizes
*/
function update_contact_avatar($avatar, $uid, $cid, $force = false) {
$r = q("SELECT `avatar`, `photo`, `thumb`, `micro` FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid));
$r = q("SELECT `avatar`, `photo`, `thumb`, `micro`, `nurl` FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid));
if (!dbm::is_result($r)) {
return false;
} else {
@ -793,6 +792,15 @@ function update_contact_avatar($avatar, $uid, $cid, $force = false) {
q("UPDATE `contact` SET `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' WHERE `id` = %d",
dbesc($avatar), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]),
dbesc(datetime_convert()), intval($cid));
// Update the public contact (contact id = 0)
if ($uid != 0) {
$pcontact = dba::select('contact', array('id'), array('nurl' => $r[0]['nurl']), array('limit' => 1));
if (dbm::is_result($pcontact)) {
update_contact_avatar($avatar, 0, $pcontact['id'], $force);
}
}
return $photos;
}
}
@ -847,9 +855,30 @@ function import_profile_photo($photo, $uid, $cid, $quit_on_error = false) {
$photo_failure = true;
}
$photo = App::get_baseurl() . '/photo/' . $hash . '-4.' . $img->getExt();
$thumb = App::get_baseurl() . '/photo/' . $hash . '-5.' . $img->getExt();
$micro = App::get_baseurl() . '/photo/' . $hash . '-6.' . $img->getExt();
$suffix = '?ts='.time();
$photo = App::get_baseurl() . '/photo/' . $hash . '-4.' . $img->getExt() . $suffix;
$thumb = App::get_baseurl() . '/photo/' . $hash . '-5.' . $img->getExt() . $suffix;
$micro = App::get_baseurl() . '/photo/' . $hash . '-6.' . $img->getExt() . $suffix;
// Remove the cached photo
$a = get_app();
$basepath = $a->get_basepath();
if (is_dir($basepath."/photo")) {
$filename = $basepath.'/photo/'.$hash.'-4.'.$img->getExt();
if (file_exists($filename)) {
unlink($filename);
}
$filename = $basepath.'/photo/'.$hash.'-5.'.$img->getExt();
if (file_exists($filename)) {
unlink($filename);
}
$filename = $basepath.'/photo/'.$hash.'-6.'.$img->getExt();
if (file_exists($filename)) {
unlink($filename);
}
}
} else {
$photo_failure = true;
}

View File

@ -152,7 +152,9 @@ function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0) {
if ($profile) {
$profile_int = intval($profile);
$r = q("SELECT `contact`.`id` AS `contact_id`, `profile`.`uid` AS `profile_uid`, `profile`.*,
$r = q("SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` AS `contact_photo`,
`contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
`profile`.`uid` AS `profile_uid`, `profile`.*,
`contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.*
FROM `profile`
INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
@ -163,7 +165,9 @@ function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0) {
);
}
if (!dbm::is_result($r)) {
$r = q("SELECT `contact`.`id` AS `contact_id`, `profile`.`uid` AS `profile_uid`, `profile`.*,
$r = q("SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` as `contact_photo`,
`contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
`profile`.`uid` AS `profile_uid`, `profile`.*,
`contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.*
FROM `profile`
INNER JOIN `contact` ON `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
@ -365,9 +369,9 @@ function profile_sidebar($profile, $block = 0) {
'fullname' => $profile['name'],
'firstname' => $firstname,
'lastname' => $lastname,
'photo300' => App::get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg',
'photo100' => App::get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg',
'photo50' => App::get_baseurl() . '/photo/custom/50/' . $profile['uid'] . '.jpg',
'photo300' => $profile['contact_photo'],
'photo100' => $profile['contact_thumb'],
'photo50' => $profile['contact_micro'],
);
else
$diaspora = false;
@ -410,9 +414,9 @@ function profile_sidebar($profile, $block = 0) {
else
$p["address"] = bbcode($p["location"]);
if (isset($p["photo"]))
if (isset($p["photo"])) {
$p["photo"] = proxy_url($p["photo"], false, PROXY_SIZE_SMALL);
}
if ($a->theme['template_engine'] === 'internal')
$location = template_escape($location);

View File

@ -307,7 +307,7 @@ function _contact_update_profile($contact_id) {
);
// Update the entry in the contact table
update_contact_avatar($data['photo'], local_user(), $contact_id);
update_contact_avatar($data['photo'], local_user(), $contact_id, true);
// Update the entry in the gcontact table
update_gcontact_from_probe($data["url"]);