New central function to store avatar data in contacts

This commit is contained in:
Michael Vogel 2016-01-28 11:09:08 +01:00
parent 6f662b8c74
commit 78e79de7c9
11 changed files with 32 additions and 172 deletions

View file

@ -486,22 +486,16 @@ function get_contact($url, $uid = 0) {
require_once("Photo.php"); require_once("Photo.php");
$photos = import_profile_photo($data["photo"],$uid,$contactid); update_contact_avatar($data["photo"],$uid,$contactid);
q("UPDATE `contact` SET `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', q("UPDATE `contact` SET `addr` = '%s', `alias` = '%s', `name` = '%s', `nick` = '%s',
`addr` = '%s', `alias` = '%s', `name` = '%s', `nick` = '%s', `name-date` = '%s', `uri-date` = '%s' WHERE `id` = %d",
`name-date` = '%s', `uri-date` = '%s', `avatar-date` = '%s' WHERE `id` = %d",
dbesc($data["photo"]),
dbesc($photos[0]),
dbesc($photos[1]),
dbesc($photos[2]),
dbesc($data["addr"]), dbesc($data["addr"]),
dbesc($data["alias"]), dbesc($data["alias"]),
dbesc($data["name"]), dbesc($data["name"]),
dbesc($data["nick"]), dbesc($data["nick"]),
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc(datetime_convert()),
intval($contactid) intval($contactid)
); );

View file

@ -728,7 +728,7 @@ function diaspora_request($importer,$xml) {
require_once('include/Photo.php'); require_once('include/Photo.php');
$photos = import_profile_photo($contact_record['photo'],$importer['uid'],$contact_record['id']); update_contact_avatar($contact_record['photo'],$importer['uid'],$contact_record['id']);
// technically they are sharing with us (CONTACT_IS_SHARING), // technically they are sharing with us (CONTACT_IS_SHARING),
// but if our page-type is PAGE_COMMUNITY or PAGE_SOAPBOX // but if our page-type is PAGE_COMMUNITY or PAGE_SOAPBOX
@ -739,28 +739,17 @@ function diaspora_request($importer,$xml) {
else else
$new_relation = CONTACT_IS_FOLLOWER; $new_relation = CONTACT_IS_FOLLOWER;
$r = q("UPDATE `contact` SET $r = q("UPDATE `contact` SET `rel` = %d,
`avatar` = '%s',
`photo` = '%s',
`thumb` = '%s',
`micro` = '%s',
`rel` = %d,
`name-date` = '%s', `name-date` = '%s',
`uri-date` = '%s', `uri-date` = '%s',
`avatar-date` = '%s',
`blocked` = 0, `blocked` = 0,
`pending` = 0, `pending` = 0,
`writable` = 1 `writable` = 1
WHERE `id` = %d WHERE `id` = %d
", ",
dbesc($contact_record['photo']),
dbesc($photos[0]),
dbesc($photos[1]),
dbesc($photos[2]),
intval($new_relation), intval($new_relation),
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc(datetime_convert()),
intval($contact_record['id']) intval($contact_record['id'])
); );
@ -2475,7 +2464,7 @@ function diaspora_profile($importer,$xml,$msg) {
require_once('include/Photo.php'); require_once('include/Photo.php');
$images = import_profile_photo($image_url,$importer['uid'],$contact['id']); update_contact_avatar($image_url,$importer['uid'],$contact['id']);
// Generic birthday. We don't know the timezone. The year is irrelevant. // Generic birthday. We don't know the timezone. The year is irrelevant.
@ -2493,18 +2482,12 @@ function diaspora_profile($importer,$xml,$msg) {
/// @TODO Update name on item['author-name'] if the name changed. See consume_feed() /// @TODO Update name on item['author-name'] if the name changed. See consume_feed()
/// (Not doing this currently because D* protocol is scheduled for revision soon). /// (Not doing this currently because D* protocol is scheduled for revision soon).
$r = q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `name-date` = '%s', $r = q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `name-date` = '%s', `bd` = '%s',
`avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' , `bd` = '%s',
`location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `id` = %d AND `uid` = %d", `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `id` = %d AND `uid` = %d",
dbesc($name), dbesc($name),
dbesc($nick), dbesc($nick),
dbesc($diaspora_handle), dbesc($diaspora_handle),
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc($image_url),
dbesc($images[0]),
dbesc($images[1]),
dbesc($images[2]),
dbesc(datetime_convert()),
dbesc($birthday), dbesc($birthday),
dbesc($location), dbesc($location),
dbesc($about), dbesc($about),
@ -2521,7 +2504,7 @@ function diaspora_profile($importer,$xml,$msg) {
} }
update_gcontact(array("url" => $contact['url'], "network" => NETWORK_DIASPORA, "generation" => 2, update_gcontact(array("url" => $contact['url'], "network" => NETWORK_DIASPORA, "generation" => 2,
"avatar" => $image_url, "name" => $name, "location" => $location, "photo" => $image_url, "name" => $name, "location" => $location,
"about" => $about, "birthday" => $birthday, "gender" => $gender, "about" => $about, "birthday" => $birthday, "gender" => $gender,
"addr" => $diaspora_handle, "nick" => $nick, "keywords" => $keywords, "addr" => $diaspora_handle, "nick" => $nick, "keywords" => $keywords,
"hide" => !$searchable, "nsfw" => $nsfw)); "hide" => !$searchable, "nsfw" => $nsfw));

View file

@ -222,7 +222,6 @@ function gs_search_user($search) {
$contact = probe_url($user->site_address."/".$user->name); $contact = probe_url($user->site_address."/".$user->name);
if ($contact["network"] != NETWORK_PHANTOM) { if ($contact["network"] != NETWORK_PHANTOM) {
$contact["about"] = $user->description; $contact["about"] = $user->description;
$contact["avatar"] = $contact["photo"];
update_gcontact($contact); update_gcontact($contact);
} }
} }

View file

@ -264,27 +264,8 @@ function new_contact($uid,$url,$interactive = false) {
require_once("include/Photo.php"); require_once("include/Photo.php");
$photos = import_profile_photo($ret['photo'],$uid,$contact_id); // Update the avatar
update_contact_avatar($ret['photo'],$uid,$contact_id);
$r = q("UPDATE `contact` SET
`avatar` = '%s',
`photo` = '%s',
`thumb` = '%s',
`micro` = '%s',
`name-date` = '%s',
`uri-date` = '%s',
`avatar-date` = '%s'
WHERE `id` = %d",
dbesc($ret['photo']),
dbesc($photos[0]),
dbesc($photos[1]),
dbesc($photos[2]),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
intval($contact_id)
);
// pull feed and consume it, which should subscribe to the hub. // pull feed and consume it, which should subscribe to the hub.

View file

@ -58,10 +58,8 @@ function gprobe_run(&$argv, &$argc){
if (is_null($result)) if (is_null($result))
Cache::set("gprobe:".$urlparts["host"],serialize($arr)); Cache::set("gprobe:".$urlparts["host"],serialize($arr));
if (!in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) { if (!in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM)))
$arr["avatar"] = $arr["photo"];
update_gcontact($arr); update_gcontact($arr);
}
$r = q("SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1", $r = q("SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
dbesc(normalise_link($url)) dbesc(normalise_link($url))

View file

@ -127,7 +127,8 @@ function ostatus_fetchauthor($xpath, $context, $importer, &$contact, $onlyfetch)
$author["owner-link"] = $author["author-link"]; $author["owner-link"] = $author["author-link"];
$author["owner-avatar"] = $author["author-avatar"]; $author["owner-avatar"] = $author["author-avatar"];
if ($r AND !$onlyfetch) { // Only update the contacts if it is an OStatus contact
if ($r AND !$onlyfetch AND ($contact["network"] == NETWORK_OSTATUS)) {
// Update contact data // Update contact data
$value = $xpath->query("atom:link[@rel='salmon']", $context)->item(0)->nodeValue; $value = $xpath->query("atom:link[@rel='salmon']", $context)->item(0)->nodeValue;
@ -158,9 +159,9 @@ function ostatus_fetchauthor($xpath, $context, $importer, &$contact, $onlyfetch)
logger("Update contact data for contact ".$contact["id"], LOGGER_DEBUG); logger("Update contact data for contact ".$contact["id"], LOGGER_DEBUG);
q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `about` = '%s', `location` = '%s', `name-date` = '%s' WHERE `id` = %d AND `network` = '%s'", q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `about` = '%s', `location` = '%s', `name-date` = '%s' WHERE `id` = %d",
dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["about"]), dbesc($contact["location"]), dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["about"]), dbesc($contact["location"]),
dbesc(datetime_convert()), intval($contact["id"]), dbesc(NETWORK_OSTATUS)); dbesc(datetime_convert()), intval($contact["id"]));
poco_check($contact["url"], $contact["name"], $contact["network"], $author["author-avatar"], $contact["about"], $contact["location"], poco_check($contact["url"], $contact["name"], $contact["network"], $author["author-avatar"], $contact["about"], $contact["location"],
"", "", "", datetime_convert(), 2, $contact["id"], $contact["uid"]); "", "", "", datetime_convert(), 2, $contact["id"], $contact["uid"]);
@ -169,21 +170,15 @@ function ostatus_fetchauthor($xpath, $context, $importer, &$contact, $onlyfetch)
if (isset($author["author-avatar"]) AND ($author["author-avatar"] != $r[0]['avatar'])) { if (isset($author["author-avatar"]) AND ($author["author-avatar"] != $r[0]['avatar'])) {
logger("Update profile picture for contact ".$contact["id"], LOGGER_DEBUG); logger("Update profile picture for contact ".$contact["id"], LOGGER_DEBUG);
$photos = import_profile_photo($author["author-avatar"], $importer["uid"], $contact["id"]); update_contact_avatar($author["author-avatar"], $importer["uid"], $contact["id"]);
q("UPDATE `contact` SET `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' WHERE `id` = %d AND `network` = '%s'",
dbesc($author["author-avatar"]), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]),
dbesc(datetime_convert()), intval($contact["id"]), dbesc(NETWORK_OSTATUS));
} }
// Only update the global contact if it is an OStatus contact
if ($contact["network"] == NETWORK_OSTATUS) {
/// @todo Add the "addr" field /// @todo Add the "addr" field
$contact["generation"] = 2; $contact["generation"] = 2;
$contact["avatar"] = $author["author-avatar"]; $contact["photo"] = $author["author-avatar"];
update_gcontact($contact); update_gcontact($contact);
} }
}
return($author); return($author);
} }

View file

@ -294,7 +294,7 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca
"alias" => $alias, "alias" => $alias,
"name" => $name, "name" => $name,
"network" => $network, "network" => $network,
"avatar" => $profile_photo, "photo" => $profile_photo,
"about" => $about, "about" => $about,
"location" => $location, "location" => $location,
"gender" => $gender, "gender" => $gender,
@ -1517,7 +1517,7 @@ function update_gcontact($contact) {
if (!$gcontact_id) if (!$gcontact_id)
return false; return false;
$r = q("SELECT `name`, `nick`, `avatar`, `photo`, `thumb`, `micro`, `location`, `about`, `addr`, `generation`, `birthday`, `gender`, `keywords`, $r = q("SELECT `name`, `nick`, `photo`, `location`, `about`, `addr`, `generation`, `birthday`, `gender`, `keywords`,
`hide`, `nsfw`, `network`, `alias`, `notify`, `server_url`, `connect`, `updated`, `url` `hide`, `nsfw`, `network`, `alias`, `notify`, `server_url`, `connect`, `updated`, `url`
FROM `gcontact` WHERE `id` = %d LIMIT 1", FROM `gcontact` WHERE `id` = %d LIMIT 1",
intval($gcontact_id)); intval($gcontact_id));
@ -1552,37 +1552,15 @@ function update_gcontact($contact) {
if ($contact["generation"] < $r[0]["generation"]) if ($contact["generation"] < $r[0]["generation"])
$update = true; $update = true;
if (isset($contact["avatar"]) AND (($contact["avatar"] != $r[0]["avatar"]) OR
($r[0]["photo"] == $r[0]["avatar"]) OR ($r[0]["thumb"] == "") OR ($r[0]["micro"] == ""))) {
$cid = get_contact($contact["url"]);
// We always store avatar picture with a contact-id.
// We don't have a contact-id when we use the gcontact table.
// Solution is to use a matching entry in the contact table. (Which is not totally clean)
if (($cid == 0) AND isset($contact["uid"]))
$cid = get_contact($contact["url"], $contact["uid"]);
$photos = update_contact_avatar($contact["avatar"], 0, $cid);
if ($photos) {
$contact["photo"] = $photos[0];
$contact["thumb"] = $photos[1];
$contact["micro"] = $photos[2];
}
}
if ($update) { if ($update) {
q("UPDATE `gcontact` SET `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', q("UPDATE `gcontact` SET `photo` = '%s', `name` = '%s', `nick` = '%s', `addr` = '%s', `network` = '%s',
`name` = '%s', `nick` = '%s', `addr` = '%s', `network` = '%s',
`birthday` = '%s', `gender` = '%s', `keywords` = %d, `hide` = %d, `nsfw` = %d, `birthday` = '%s', `gender` = '%s', `keywords` = %d, `hide` = %d, `nsfw` = %d,
`alias` = '%s', `notify` = '%s', `url` = '%s', `alias` = '%s', `notify` = '%s', `url` = '%s',
`location` = '%s', `about` = '%s', `generation` = %d, `updated` = '%s', `location` = '%s', `about` = '%s', `generation` = %d, `updated` = '%s',
`server_url` = '%s', `connect` = '%s' `server_url` = '%s', `connect` = '%s'
WHERE `nurl` = '%s' AND (`generation` = 0 OR `generation` >= %d)", WHERE `nurl` = '%s' AND (`generation` = 0 OR `generation` >= %d)",
dbesc($contact["avatar"]), dbesc($contact["photo"]), dbesc($contact["thumb"]), dbesc($contact["photo"]), dbesc($contact["name"]), dbesc($contact["nick"]),
dbesc($contact["micro"]), dbesc($contact["name"]), dbesc($contact["nick"]),
dbesc($contact["addr"]), dbesc($contact["network"]), dbesc($contact["birthday"]), dbesc($contact["addr"]), dbesc($contact["network"]), dbesc($contact["birthday"]),
dbesc($contact["gender"]), dbesc($contact["keywords"]), intval($contact["hide"]), dbesc($contact["gender"]), dbesc($contact["keywords"]), intval($contact["hide"]),
intval($contact["nsfw"]), dbesc($contact["alias"]), dbesc($contact["notify"]), intval($contact["nsfw"]), dbesc($contact["alias"]), dbesc($contact["notify"]),

View file

@ -293,26 +293,8 @@ function _contact_update_profile($contact_id) {
intval(local_user()) intval(local_user())
); );
$photos = import_profile_photo($data['photo'], local_user(), $contact_id); // Update the entry in the contact table
update_contact_avatar($data['photo'], local_user(), $contact_id);
$r = q("UPDATE `contact` SET
`avatar` = '%s',
`photo` = '%s',
`thumb` = '%s',
`micro` = '%s',
`name-date` = '%s',
`uri-date` = '%s',
`avatar-date` = '%s'
WHERE `id` = %d",
dbesc($data["photo"]),
dbesc($photos[0]),
dbesc($photos[1]),
dbesc($photos[2]),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
intval($contact_id)
);
// Update the entry in the gcontact table // Update the entry in the gcontact table
update_gcontact_from_probe($data["url"]); update_gcontact_from_probe($data["url"]);

View file

@ -80,27 +80,7 @@ function crepair_post(&$a) {
logger('mod-crepair: updating photo from ' . $photo); logger('mod-crepair: updating photo from ' . $photo);
require_once("include/Photo.php"); require_once("include/Photo.php");
$photos = import_profile_photo($photo,local_user(),$contact['id']); update_contact_avatar($photo,local_user(),$contact['id']);
$x = q("UPDATE `contact` SET
`avatar` = '%s',
`photo` = '%s',
`thumb` = '%s',
`micro` = '%s',
`name-date` = '%s',
`uri-date` = '%s',
`avatar-date` = '%s'
WHERE `id` = %d
",
dbesc($photo),
dbesc($photos[0]),
dbesc($photos[1]),
dbesc($photos[2]),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
intval($contact['id'])
);
} }
if($r) if($r)

View file

@ -315,7 +315,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
require_once('include/Photo.php'); require_once('include/Photo.php');
$photos = import_profile_photo($contact['photo'],$uid,$contact_id); update_contact_avatar($contact['photo'],$uid,$contact_id);
logger('dfrn_confirm: confirm - imported photos'); logger('dfrn_confirm: confirm - imported photos');
@ -328,29 +328,18 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
if(($relation == CONTACT_IS_SHARING) && ($duplex)) if(($relation == CONTACT_IS_SHARING) && ($duplex))
$duplex = 0; $duplex = 0;
$r = q("UPDATE `contact` SET $r = q("UPDATE `contact` SET `rel` = %d,
`avatar` = '%s',
`photo` = '%s',
`thumb` = '%s',
`micro` = '%s',
`rel` = %d,
`name-date` = '%s', `name-date` = '%s',
`uri-date` = '%s', `uri-date` = '%s',
`avatar-date` = '%s',
`blocked` = 0, `blocked` = 0,
`pending` = 0, `pending` = 0,
`duplex` = %d, `duplex` = %d,
`hidden` = %d, `hidden` = %d,
`network` = '%s' WHERE `id` = %d `network` = '%s' WHERE `id` = %d
", ",
dbesc($contact['photo']),
dbesc($photos[0]),
dbesc($photos[1]),
dbesc($photos[2]),
intval($new_relation), intval($new_relation),
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc(datetime_convert()),
intval($duplex), intval($duplex),
intval($hidden), intval($hidden),
dbesc(NETWORK_DFRN), dbesc(NETWORK_DFRN),
@ -396,12 +385,8 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
); );
$r = q("UPDATE `contact` SET `photo` = '%s', $r = q("UPDATE `contact` SET `name-date` = '%s',
`thumb` = '%s',
`micro` = '%s',
`name-date` = '%s',
`uri-date` = '%s', `uri-date` = '%s',
`avatar-date` = '%s',
`notify` = '%s', `notify` = '%s',
`poll` = '%s', `poll` = '%s',
`blocked` = 0, `blocked` = 0,
@ -412,10 +397,6 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
`rel` = %d `rel` = %d
WHERE `id` = %d WHERE `id` = %d
", ",
dbesc($photos[0]),
dbesc($photos[1]),
dbesc($photos[2]),
dbesc(datetime_convert()),
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc($notify), dbesc($notify),
@ -685,7 +666,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
require_once("include/Photo.php"); require_once("include/Photo.php");
$photos = import_profile_photo($photo,$local_uid,$dfrn_record); update_contact_avatar($photo,$local_uid,$dfrn_record);
logger('dfrn_confirm: request - photos imported'); logger('dfrn_confirm: request - photos imported');
@ -697,14 +678,9 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
$duplex = 0; $duplex = 0;
$r = q("UPDATE `contact` SET $r = q("UPDATE `contact` SET
`avatar` = '%s',
`photo` = '%s',
`thumb` = '%s',
`micro` = '%s',
`rel` = %d, `rel` = %d,
`name-date` = '%s', `name-date` = '%s',
`uri-date` = '%s', `uri-date` = '%s',
`avatar-date` = '%s',
`blocked` = 0, `blocked` = 0,
`pending` = 0, `pending` = 0,
`duplex` = %d, `duplex` = %d,
@ -712,14 +688,9 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
`prv` = %d, `prv` = %d,
`network` = '%s' WHERE `id` = %d `network` = '%s' WHERE `id` = %d
", ",
dbesc($photo),
dbesc($photos[0]),
dbesc($photos[1]),
dbesc($photos[2]),
intval($new_relation), intval($new_relation),
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc(datetime_convert()),
intval($duplex), intval($duplex),
intval($forum), intval($forum),
intval($prv), intval($prv),

View file

@ -1146,7 +1146,6 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo
if (!$r) { if (!$r) {
$probed = probe_url($name); $probed = probe_url($name);
if (isset($probed["url"])) { if (isset($probed["url"])) {
$probed["avatar"] = $probed["photo"];
update_gcontact($probed); update_gcontact($probed);
$r = q("SELECT `url`, `name`, `nick`, `network`, `alias`, `notify` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", $r = q("SELECT `url`, `name`, `nick`, `network`, `alias`, `notify` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
dbesc(normalise_link($probed["url"]))); dbesc(normalise_link($probed["url"])));