Merge pull request #2830 from annando/1610-account_type
The account type is now read and displayed
This commit is contained in:
commit
fa33f94b29
16 changed files with 85 additions and 59 deletions
|
@ -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`,
|
||||
`xmpp`, `keywords`, `gender`, `photo`, `thumb`, `micro`, `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`,
|
||||
`xmpp`, `keywords`, `gender`, `photo`, `thumb`, `micro`, `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`,
|
||||
'' AS `xmpp`, `keywords`, `gender`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, `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`, 0 AS `contact-type`, `birthday`, 0 AS `self`
|
||||
FROM `gcontact` WHERE `nurl` = '%s'",
|
||||
dbesc(normalise_link($url)));
|
||||
|
||||
|
@ -683,4 +683,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;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -2492,7 +2492,19 @@ class dfrn {
|
|||
|
||||
logger("Import DFRN message for user ".$importer["uid"]." from contact ".$importer["id"], LOGGER_DEBUG);
|
||||
|
||||
// is it a public forum? Private forums aren't supported by now with this method
|
||||
// The account type is new since 3.5.1
|
||||
if ($xpath->query("/atom:feed/dfrn:account_type")->length > 0) {
|
||||
$accounttype = intval($xpath->evaluate("/atom:feed/dfrn:account_type/text()", $context)->item(0)->nodeValue);
|
||||
|
||||
if ($accounttype != $importer["contact-type"])
|
||||
q("UPDATE `contact` SET `contact-type` = %d WHERE `id` = %d",
|
||||
intval($accounttype),
|
||||
intval($importer["id"])
|
||||
);
|
||||
}
|
||||
|
||||
// is it a public forum? Private forums aren't supported with this method
|
||||
// This is deprecated since 3.5.1
|
||||
$forum = intval($xpath->evaluate("/atom:feed/dfrn:community/text()", $context)->item(0)->nodeValue);
|
||||
|
||||
if ($forum != $importer["forum"])
|
||||
|
|
|
@ -310,15 +310,8 @@ function profile_sidebar($profile, $block = 0) {
|
|||
);
|
||||
}
|
||||
|
||||
// check if profile is a forum
|
||||
if((intval($profile['page-flags']) == PAGE_COMMUNITY)
|
||||
|| (intval($profile['page-flags']) == PAGE_PRVGROUP)
|
||||
|| (isset($profile['forum']) && intval($profile['forum']))
|
||||
|| (isset($profile['prv']) && intval($profile['prv']))
|
||||
|| (isset($profile['community']) && intval($profile['community'])))
|
||||
$account_type = t('Forum');
|
||||
else
|
||||
$account_type = "";
|
||||
// Fetch the account type
|
||||
$account_type = account_type($profile);
|
||||
|
||||
if((x($profile,'address') == 1)
|
||||
|| (x($profile,'location') == 1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue