X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2FContact.php;h=ab74a2f866d4e77119b2fe0b7c45e0f2a06321dd;hb=fd3cf1cd02b57e9796e5537dbee468d1c8048a48;hp=86ef4a30fa1c015a55f435c0b1c6e080c0212445;hpb=aac9caab2d39980c80ea3ae31b24b27561c4f646;p=friendica.git diff --git a/include/Contact.php b/include/Contact.php index 86ef4a30fa..ab74a2f866 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -45,10 +45,10 @@ function user_remove($uid) { // don't delete yet, will be done later when contacts have deleted my stuff // q("DELETE FROM `user` WHERE `uid` = %d", intval($uid)); q("UPDATE `user` SET `account_removed` = 1, `account_expires_on` = UTC_TIMESTAMP() WHERE `uid` = %d", intval($uid)); - proc_run('php', "include/notifier.php", "removeme", $uid); + proc_run(PRIORITY_HIGH, "include/notifier.php", "removeme", $uid); // Send an update to the directory - proc_run('php', "include/directory.php", $r[0]['url']); + proc_run(PRIORITY_LOW, "include/directory.php", $r[0]['url']); if($uid == local_user()) { unset($_SESSION['authenticated']); @@ -208,22 +208,22 @@ function get_contact_details_by_url($url, $uid = -1, $default = array()) { $uid = local_user(); // Fetch contact data from the contact table for the given user - $r = q("SELECT `id`, `id` AS `cid`, 0 AS `gid`, 0 AS `zid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, - `keywords`, `gender`, `photo`, `thumb`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `bd` AS `birthday`, `self` + $r = q("SELECT `id`, `id` AS `cid`, 0 AS `gid`, 0 AS `zid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`, + `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, `self` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d", dbesc(normalise_link($url)), intval($uid)); // Fetch the data from the contact table with "uid=0" (which is filled automatically) if (!$r) - $r = q("SELECT `id`, 0 AS `cid`, `id` AS `zid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, - `keywords`, `gender`, `photo`, `thumb`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `bd` AS `birthday`, 0 AS `self` + $r = q("SELECT `id`, 0 AS `cid`, `id` AS `zid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`, + `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self` FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0", dbesc(normalise_link($url))); // Fetch the data from the gcontact table if (!$r) - $r = q("SELECT 0 AS `id`, 0 AS `cid`, `id` AS `gid`, 0 AS `zid`, 0 AS `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, - `keywords`, `gender`, `photo`, `photo` AS `thumb`, `community` AS `forum`, 0 AS `prv`, `community`, `birthday`, 0 AS `self` + $r = q("SELECT 0 AS `id`, 0 AS `cid`, `id` AS `gid`, 0 AS `zid`, 0 AS `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, '' AS `xmpp`, + `keywords`, `gender`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, `community` AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self` FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($url))); @@ -255,15 +255,27 @@ function get_contact_details_by_url($url, $uid = -1, $default = array()) { $profile["bd"] = (++$current_year)."-".$month."-".$day; } else $profile["bd"] = "0000-00-00"; - } else { + } else $profile = $default; - if (!isset($profile["thumb"]) AND isset($profile["photo"])) - $profile["thumb"] = $profile["photo"]; - } + + if (($profile["photo"] == "") AND isset($default["photo"])) + $profile["photo"] = $default["photo"]; + + if (($profile["name"] == "") AND isset($default["name"])) + $profile["name"] = $default["name"]; + + if (($profile["network"] == "") AND isset($default["network"])) + $profile["network"] = $default["network"]; + + if (($profile["thumb"] == "") AND isset($profile["photo"])) + $profile["thumb"] = $profile["photo"]; + + if (($profile["micro"] == "") AND isset($profile["thumb"])) + $profile["micro"] = $profile["thumb"]; if ((($profile["addr"] == "") OR ($profile["name"] == "")) AND ($profile["gid"] != 0) AND in_array($profile["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) - proc_run('php',"include/update_gcontact.php", $profile["gid"]); + proc_run(PRIORITY_LOW, "include/update_gcontact.php", $profile["gid"]); // Show contact details of Diaspora contacts only if connected if (($profile["cid"] == 0) AND ($profile["network"] == NETWORK_DIASPORA)) { @@ -451,17 +463,27 @@ function get_contact($url, $uid = 0) { $data = probe_url($url); // Does this address belongs to a valid network? - if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA))) - return 0; + if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA))) { + if ($uid != 0) + return 0; + + // Get data from the gcontact table + $r = q("SELECT `name`, `nick`, `url`, `photo`, `addr`, `alias`, `network` FROM `gcontact` WHERE `nurl` = '%s'", + dbesc(normalise_link($url))); + if (!$r) + return 0; + + $data = $r[0]; + } $url = $data["url"]; if ($contactid == 0) { q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`, `name`, `nick`, `photo`, `network`, `pubkey`, `rel`, `priority`, - `batch`, `request`, `confirm`, `poco`, + `batch`, `request`, `confirm`, `poco`, `name-date`, `uri-date`, `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)", + VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', 1, 0, 0, 0)", intval($uid), dbesc(datetime_convert()), dbesc($data["url"]), @@ -480,7 +502,9 @@ function get_contact($url, $uid = 0) { dbesc($data["batch"]), dbesc($data["request"]), dbesc($data["confirm"]), - dbesc($data["poco"]) + dbesc($data["poco"]), + dbesc(datetime_convert()), + dbesc(datetime_convert()) ); $contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d ORDER BY `id` LIMIT 2", @@ -490,6 +514,16 @@ function get_contact($url, $uid = 0) { return 0; $contactid = $contact[0]["id"]; + + // Update the newly created contact from data in the gcontact table + $r = q("SELECT `location`, `about`, `keywords`, `gender` FROM `gcontact` WHERE `nurl` = '%s'", + dbesc(normalise_link($data["url"]))); + if ($r) { + logger("Update contact ".$data["url"]); + q("UPDATE `contact` SET `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `id` = %d", + dbesc($r["location"]), dbesc($r["about"]), dbesc($r["keywords"]), + dbesc($r["gender"]), intval($contactid)); + } } if ((count($contact) > 1) AND ($uid == 0) AND ($contactid != 0) AND ($url != "")) @@ -501,16 +535,27 @@ function get_contact($url, $uid = 0) { update_contact_avatar($data["photo"],$uid,$contactid); - q("UPDATE `contact` SET `addr` = '%s', `alias` = '%s', `name` = '%s', `nick` = '%s', - `name-date` = '%s', `uri-date` = '%s' WHERE `id` = %d", - dbesc($data["addr"]), - dbesc($data["alias"]), - dbesc($data["name"]), - dbesc($data["nick"]), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - intval($contactid) - ); + $r = q("SELECT `addr`, `alias`, `name`, `nick` FROM `contact` WHERE `id` = %d", intval($contactid)); + + // This condition should always be true + if (!dbm::is_result($r)) + return $contactid; + + // Only update if there had something been changed + if (($data["addr"] != $r[0]["addr"]) OR + ($data["alias"] != $r[0]["alias"]) OR + ($data["name"] != $r[0]["name"]) OR + ($data["nick"] != $r[0]["nick"])) + q("UPDATE `contact` SET `addr` = '%s', `alias` = '%s', `name` = '%s', `nick` = '%s', + `name-date` = '%s', `uri-date` = '%s' WHERE `id` = %d", + dbesc($data["addr"]), + dbesc($data["alias"]), + dbesc($data["name"]), + dbesc($data["nick"]), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + intval($contactid) + ); return $contactid; } @@ -599,11 +644,11 @@ function posts_from_contact($a, $contact_id) { $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`, `author-name` AS `name`, `owner-avatar` AS `photo`, `owner-link` AS `url`, `owner-avatar` AS `thumb` - FROM `item` FORCE INDEX (`uid_contactid_created`) + FROM `item` FORCE INDEX (`uid_contactid_id`) WHERE `item`.`uid` = %d AND `contact-id` = %d AND `author-link` IN ('%s', '%s') AND NOT `deleted` AND NOT `moderated` AND `visible` - ORDER BY `item`.`created` DESC LIMIT %d, %d", + ORDER BY `item`.`id` DESC LIMIT %d, %d", intval(local_user()), intval($contact_id), dbesc(str_replace("https://", "http://", $contact["url"])), @@ -651,4 +696,50 @@ function formatted_location($profile) { return $location; } + +/** + * @brief Returns the account type name + * + * The function can be called with either the user or the contact array + * + * @param array $contact contact or user array + */ +function account_type($contact) { + + // There are several fields that indicate that the contact or user is a forum + // "page-flags" is a field in the user table, + // "forum" and "prv" are used in the contact table. They stand for PAGE_COMMUNITY and PAGE_PRVGROUP. + // "community" is used in the gcontact table and is true if the contact is PAGE_COMMUNITY or PAGE_PRVGROUP. + if((isset($contact['page-flags']) && (intval($contact['page-flags']) == PAGE_COMMUNITY)) + || (isset($contact['page-flags']) && (intval($contact['page-flags']) == PAGE_PRVGROUP)) + || (isset($contact['forum']) && intval($contact['forum'])) + || (isset($contact['prv']) && intval($contact['prv'])) + || (isset($contact['community']) && intval($contact['community']))) + $type = ACCOUNT_TYPE_COMMUNITY; + else + $type = ACCOUNT_TYPE_PERSON; + + // The "contact-type" (contact table) and "account-type" (user table) are more general then the chaos from above. + if (isset($contact["contact-type"])) + $type = $contact["contact-type"]; + if (isset($contact["account-type"])) + $type = $contact["account-type"]; + + switch($type) { + case ACCOUNT_TYPE_ORGANISATION: + $account_type = t("Organisation"); + break; + case ACCOUNT_TYPE_NEWS: + $account_type = t('News'); + break; + case ACCOUNT_TYPE_COMMUNITY: + $account_type = t("Forum"); + break; + default: + $account_type = ""; + break; + } + + return $account_type; +} ?>