Aliases are now handled correctly. The public item copy gets a "real" contact id as well.

This commit is contained in:
Michael Vogel 2015-02-01 13:32:05 +01:00
parent e02b982f77
commit b95d34f9db
3 changed files with 82 additions and 48 deletions

View file

@ -297,6 +297,7 @@ function get_contact($url, $uid = 0) {
require_once("include/Scrape.php"); require_once("include/Scrape.php");
$data = array(); $data = array();
$contactid = 0;
// is it an address in the format user@server.tld? // is it an address in the format user@server.tld?
if (!strstr($url, "http") OR strstr($url, "@")) { if (!strstr($url, "http") OR strstr($url, "@")) {
@ -306,11 +307,24 @@ function get_contact($url, $uid = 0) {
return 0; return 0;
} }
$contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d", $contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
dbesc(normalise_link($url)), dbesc(normalise_link($url)),
intval($uid)); intval($uid));
if ($contact)
return($contact[0]["id"]); if (!$contact)
$contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `alias` = '%s' AND `uid` = %d",
dbesc(normalise_link($url)),
intval($uid));
if ($contact) {
$contactid = $contact[0]["id"];
//$update_photo = ($contact[0]['avatar-date'] < datetime_convert('','','now -2 days'));
$update_photo = ($contact[0]['avatar-date'] < datetime_convert('','','now -12 hours'));
if (!$update_photo)
return($contactid);
}
if (!count($data)) if (!count($data))
$data = probe_url($url); $data = probe_url($url);
@ -319,51 +333,65 @@ function get_contact($url, $uid = 0) {
if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA))) if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
return 0; return 0;
q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`, // tempory programming. Can be deleted after 2015-02-07
`name`, `nick`, `photo`, `network`, `pubkey`, `rel`, `priority`, if (($data["alias"] == "") AND (normalise_link($data["url"]) != normalise_link($url)))
`batch`, `request`, `confirm`, `poco`, $data["alias"] = normalise_link($url);
`writable`, `blocked`, `readonly`, `pending`)
VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', '%s', 1, 0, 0, 0)",
intval($uid),
dbesc(datetime_convert()),
dbesc($data["url"]),
dbesc(normalise_link($data["url"])),
dbesc($data["addr"]),
dbesc($data["alias"]),
dbesc($data["notify"]),
dbesc($data["poll"]),
dbesc($data["name"]),
dbesc($data["nick"]),
dbesc($data["photo"]),
dbesc($data["network"]),
dbesc($data["pubkey"]),
intval(CONTACT_IS_SHARING),
intval($data["priority"]),
dbesc($data["batch"]),
dbesc($data["request"]),
dbesc($data["confirm"]),
dbesc($data["poco"])
);
$contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d", if ($contactid == 0) {
dbesc(normalise_link($url)), q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`,
intval($uid)); `name`, `nick`, `photo`, `network`, `pubkey`, `rel`, `priority`,
if (!$contact) `batch`, `request`, `confirm`, `poco`,
return 0; `writable`, `blocked`, `readonly`, `pending`)
VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', '%s', 1, 0, 0, 0)",
intval($uid),
dbesc(datetime_convert()),
dbesc($data["url"]),
dbesc(normalise_link($data["url"])),
dbesc($data["addr"]),
dbesc($data["alias"]),
dbesc($data["notify"]),
dbesc($data["poll"]),
dbesc($data["name"]),
dbesc($data["nick"]),
dbesc($data["photo"]),
dbesc($data["network"]),
dbesc($data["pubkey"]),
intval(CONTACT_IS_SHARING),
intval($data["priority"]),
dbesc($data["batch"]),
dbesc($data["request"]),
dbesc($data["confirm"]),
dbesc($data["poco"])
);
$contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
dbesc(normalise_link($data["url"])),
intval($uid));
if (!$contact)
return 0;
$contactid = $contact[0]["id"];
}
require_once("Photo.php"); require_once("Photo.php");
$photos = import_profile_photo($data["photo"],$uid,$contact[0]["id"]); $photos = import_profile_photo($data["photo"],$uid,$contactid);
q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s', `name-date` = '%s', `uri-date` = '%s', `avatar-date` = '%s' WHERE `id` = %d", q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s',
`addr` = '%s', `alias` = '%s', `name` = '%s', `nick` = '%s',
`name-date` = '%s', `uri-date` = '%s', `avatar-date` = '%s' WHERE `id` = %d",
dbesc($photos[0]), dbesc($photos[0]),
dbesc($photos[1]), dbesc($photos[1]),
dbesc($photos[2]), dbesc($photos[2]),
dbesc($data["addr"]),
dbesc($data["alias"]),
dbesc($data["name"]),
dbesc($data["nick"]),
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc(datetime_convert()), dbesc(datetime_convert()),
intval($contact[0]["id"]) intval($contactid)
); );
return $contact[0]["id"]; return $contactid;
} }

View file

@ -448,6 +448,10 @@ function probe_url($url, $mode = PROBE_NORMAL) {
} }
} }
} }
// If the profile is different from the url then the url is abviously an alias
if (($alias == "") AND ($profile != "") AND !$at_addr AND (normalise_link($profile) != normalise_link($url)))
$alias = $url;
} }
elseif($mode == PROBE_NORMAL) { elseif($mode == PROBE_NORMAL) {

View file

@ -66,9 +66,11 @@ function add_thread($itemid, $onlyshadow = false) {
if (!$r) { if (!$r) {
// Preparing public shadow (removing user specific data) // Preparing public shadow (removing user specific data)
require_once("include/items.php"); require_once("include/items.php");
require_once("include/Contact.php");
unset($item[0]['id']); unset($item[0]['id']);
$item[0]['uid'] = 0; $item[0]['uid'] = 0;
$item[0]['contact-id'] = 0; $item[0]['contact-id'] = get_contact($item[0]['author-link'], 0);
$public_shadow = item_store($item[0], false, false, true); $public_shadow = item_store($item[0], false, false, true);
logger("add_thread: Stored public shadow for post ".$itemid." under id ".$public_shadow, LOGGER_DEBUG); logger("add_thread: Stored public shadow for post ".$itemid." under id ".$public_shadow, LOGGER_DEBUG);