From 11905c0bec823d7ceb657c99a1ab8d4180ccba51 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 13 Nov 2015 08:45:14 +0100 Subject: [PATCH 1/3] The avatar picture wasn't updated at the contact table --- include/items.php | 32 ++++++++++++++++++++++++++++++-- mod/profile_photo.php | 12 +++++++++--- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/include/items.php b/include/items.php index ebda49e9ad..3261e94683 100644 --- a/include/items.php +++ b/include/items.php @@ -2381,6 +2381,19 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) $contact_updated = $photo_timestamp; require_once("include/Photo.php"); + $photos = import_profile_photo($photo_url,$contact['uid'],$contact['id']); + + q("UPDATE `contact` SET `avatar-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s' + WHERE `uid` = %d AND `id` = %d", + dbesc(datetime_convert()), + dbesc($photos[0]), + dbesc($photos[1]), + dbesc($photos[2]), + intval($contact['uid']), + intval($contact['id']) + ); + + /* $photo_failure = false; $have_photo = false; @@ -2433,7 +2446,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) intval($contact['uid']), intval($contact['id']) ); - } + }*/ } if((is_array($contact)) && ($name_updated) && (strlen($new_name)) && ($name_updated > $contact['name-date'])) { @@ -3119,6 +3132,21 @@ function local_delivery($importer,$data) { logger('local_delivery: Updating photo for ' . $importer['name']); require_once("include/Photo.php"); + + $photos = import_profile_photo($photo_url,$importer['importer_uid'],$importer['id']); + + q("UPDATE `contact` SET `avatar-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s' + WHERE `uid` = %d AND `id` = %d", + dbesc(datetime_convert()), + dbesc($photos[0]), + dbesc($photos[1]), + dbesc($photos[2]), + intval($importer['importer_uid']), + intval($importer['id']) + ); + + + /* $photo_failure = false; $have_photo = false; @@ -3171,7 +3199,7 @@ function local_delivery($importer,$data) { intval($importer['importer_uid']), intval($importer['id']) ); - } + } */ } if(($name_updated) && (strlen($new_name)) && ($name_updated > $importer['name-date'])) { diff --git a/mod/profile_photo.php b/mod/profile_photo.php index aa88090597..b7e9340ce6 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -79,7 +79,7 @@ function profile_photo_post(&$a) { $im->scaleImage(80); $r = $im->store(local_user(), 0, $base_image['resource-id'],$base_image['filename'], t('Profile Photos'), 5, $is_default_profile); - + if($r === false) notice( sprintf(t('Image size reduction [%s] failed.'),"80") . EOL ); @@ -97,8 +97,14 @@ function profile_photo_post(&$a) { dbesc($base_image['resource-id']), intval(local_user()) ); - } - else { + + $r = q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s' WHERE `self` AND `uid` = %d", + dbesc($a->get_baseurl() . '/photo/' . $base_image['resource-id'] . '-4'), + dbesc($a->get_baseurl() . '/photo/' . $base_image['resource-id'] . '-5'), + dbesc($a->get_baseurl() . '/photo/' . $base_image['resource-id'] . '-6'), + intval(local_user()) + ); + } else { $r = q("update profile set photo = '%s', thumb = '%s' where id = %d and uid = %d", dbesc($a->get_baseurl() . '/photo/' . $base_image['resource-id'] . '-4'), dbesc($a->get_baseurl() . '/photo/' . $base_image['resource-id'] . '-5'), From c951123b764ada7f65b0319a2e1b1bf4b02202b0 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 13 Nov 2015 09:45:15 +0100 Subject: [PATCH 2/3] Cleaned code --- include/items.php | 111 ---------------------------------------------- 1 file changed, 111 deletions(-) diff --git a/include/items.php b/include/items.php index 3261e94683..7a4648872b 100644 --- a/include/items.php +++ b/include/items.php @@ -2392,61 +2392,6 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) intval($contact['uid']), intval($contact['id']) ); - - /* - $photo_failure = false; - $have_photo = false; - - $r = q("SELECT `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d LIMIT 1", - intval($contact['id']), - intval($contact['uid']) - ); - if(count($r)) { - $resource_id = $r[0]['resource-id']; - $have_photo = true; - } - else { - $resource_id = photo_new_resource(); - } - - $img_str = fetch_url($photo_url,true); - // guess mimetype from headers or filename - $type = guess_image_type($photo_url,true); - - - $img = new Photo($img_str, $type); - if($img->is_valid()) { - if($have_photo) { - q("DELETE FROM `photo` WHERE `resource-id` = '%s' AND `contact-id` = %d AND `uid` = %d", - dbesc($resource_id), - intval($contact['id']), - intval($contact['uid']) - ); - } - - $img->scaleImageSquare(175); - - $hash = $resource_id; - $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), 'Contact Photos', 4); - - $img->scaleImage(80); - $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), 'Contact Photos', 5); - - $img->scaleImage(48); - $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), 'Contact Photos', 6); - - $a = get_app(); - - q("UPDATE `contact` SET `avatar-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s' - WHERE `uid` = %d AND `id` = %d", - dbesc(datetime_convert()), - dbesc($a->get_baseurl() . '/photo/' . $hash . '-4.'.$img->getExt()), - dbesc($a->get_baseurl() . '/photo/' . $hash . '-5.'.$img->getExt()), - dbesc($a->get_baseurl() . '/photo/' . $hash . '-6.'.$img->getExt()), - intval($contact['uid']), - intval($contact['id']) - ); - }*/ } if((is_array($contact)) && ($name_updated) && (strlen($new_name)) && ($name_updated > $contact['name-date'])) { @@ -3144,62 +3089,6 @@ function local_delivery($importer,$data) { intval($importer['importer_uid']), intval($importer['id']) ); - - - /* - $photo_failure = false; - $have_photo = false; - - $r = q("SELECT `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d LIMIT 1", - intval($importer['id']), - intval($importer['importer_uid']) - ); - if(count($r)) { - $resource_id = $r[0]['resource-id']; - $have_photo = true; - } - else { - $resource_id = photo_new_resource(); - } - - $img_str = fetch_url($photo_url,true); - // guess mimetype from headers or filename - $type = guess_image_type($photo_url,true); - - - $img = new Photo($img_str, $type); - if($img->is_valid()) { - if($have_photo) { - q("DELETE FROM `photo` WHERE `resource-id` = '%s' AND `contact-id` = %d AND `uid` = %d", - dbesc($resource_id), - intval($importer['id']), - intval($importer['importer_uid']) - ); - } - - $img->scaleImageSquare(175); - - $hash = $resource_id; - $r = $img->store($importer['importer_uid'], $importer['id'], $hash, basename($photo_url), 'Contact Photos', 4); - - $img->scaleImage(80); - $r = $img->store($importer['importer_uid'], $importer['id'], $hash, basename($photo_url), 'Contact Photos', 5); - - $img->scaleImage(48); - $r = $img->store($importer['importer_uid'], $importer['id'], $hash, basename($photo_url), 'Contact Photos', 6); - - $a = get_app(); - - q("UPDATE `contact` SET `avatar-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s' - WHERE `uid` = %d AND `id` = %d", - dbesc(datetime_convert()), - dbesc($a->get_baseurl() . '/photo/' . $hash . '-4.'.$img->getExt()), - dbesc($a->get_baseurl() . '/photo/' . $hash . '-5.'.$img->getExt()), - dbesc($a->get_baseurl() . '/photo/' . $hash . '-6.'.$img->getExt()), - intval($importer['importer_uid']), - intval($importer['id']) - ); - } */ } if(($name_updated) && (strlen($new_name)) && ($name_updated > $importer['name-date'])) { From ab1edca0be8f60d86db4e4342e8bed3eae7f734e Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 13 Nov 2015 10:15:30 +0100 Subject: [PATCH 3/3] Profile photos are now having an extension --- mod/profile_photo.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mod/profile_photo.php b/mod/profile_photo.php index b7e9340ce6..4e8d279a97 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -99,15 +99,15 @@ function profile_photo_post(&$a) { ); $r = q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s' WHERE `self` AND `uid` = %d", - dbesc($a->get_baseurl() . '/photo/' . $base_image['resource-id'] . '-4'), - dbesc($a->get_baseurl() . '/photo/' . $base_image['resource-id'] . '-5'), - dbesc($a->get_baseurl() . '/photo/' . $base_image['resource-id'] . '-6'), + dbesc($a->get_baseurl() . '/photo/' . $base_image['resource-id'] . '-4.' . $im->getExt()), + dbesc($a->get_baseurl() . '/photo/' . $base_image['resource-id'] . '-5.' . $im->getExt()), + dbesc($a->get_baseurl() . '/photo/' . $base_image['resource-id'] . '-6.' . $im->getExt()), intval(local_user()) ); } else { $r = q("update profile set photo = '%s', thumb = '%s' where id = %d and uid = %d", - dbesc($a->get_baseurl() . '/photo/' . $base_image['resource-id'] . '-4'), - dbesc($a->get_baseurl() . '/photo/' . $base_image['resource-id'] . '-5'), + dbesc($a->get_baseurl() . '/photo/' . $base_image['resource-id'] . '-4.' . $im->getExt()), + dbesc($a->get_baseurl() . '/photo/' . $base_image['resource-id'] . '-5.' . $im->getExt()), intval($_REQUEST['profile']), intval(local_user()) );