4 use Friendica\Network\Probe;
6 // Included here for completeness, but this is a very dangerous operation.
7 // It is the caller's responsibility to confirm the requestor's intent and
8 // authorisation to do this.
10 function user_remove($uid) {
13 logger('Removing user: ' . $uid);
15 $r = q("select * from user where uid = %d limit 1", intval($uid));
17 call_hooks('remove_user',$r[0]);
19 // save username (actually the nickname as it is guaranteed
20 // unique), so it cannot be re-registered in the future.
22 q("insert into userd ( username ) values ( '%s' )",
26 // The user and related data will be deleted in "cron_expire_and_remove_users" (cronjobs.php)
27 q("UPDATE `user` SET `account_removed` = 1, `account_expires_on` = UTC_TIMESTAMP() WHERE `uid` = %d", intval($uid));
28 proc_run(PRIORITY_HIGH, "include/notifier.php", "removeme", $uid);
30 // Send an update to the directory
31 proc_run(PRIORITY_LOW, "include/directory.php", $r[0]['url']);
33 if($uid == local_user()) {
34 unset($_SESSION['authenticated']);
35 unset($_SESSION['uid']);
36 goaway(App::get_baseurl());
41 function contact_remove($id) {
43 // We want just to make sure that we don't delete our "self" contact
44 $r = q("SELECT `uid` FROM `contact` WHERE `id` = %d AND NOT `self` LIMIT 1",
47 if (!dbm::is_result($r) || !intval($r[0]['uid'])) {
51 $archive = get_pconfig($r[0]['uid'], 'system','archive_removed_contacts');
53 q("update contact set `archive` = 1, `network` = 'none', `writable` = 0 where id = %d",
59 q("DELETE FROM `contact` WHERE `id` = %d", intval($id));
61 // Delete the rest in the background
62 proc_run(PRIORITY_LOW, 'include/remove_contact.php', $id);
66 // sends an unfriend message. Does not remove the contact
68 function terminate_friendship($user,$self,$contact) {
70 /// @TODO Get rid of this, include/datetime.php should care about it by itself
73 require_once 'include/datetime.php';
75 if ($contact['network'] === NETWORK_OSTATUS) {
77 require_once 'include/ostatus.php';
79 // create an unfollow slap
81 $item['verb'] = NAMESPACE_OSTATUS."/unfollow";
82 $item['follow'] = $contact["url"];
83 $slap = ostatus::salmon($item, $user);
85 if ((x($contact,'notify')) && (strlen($contact['notify']))) {
86 require_once 'include/salmon.php';
87 slapper($user,$contact['notify'],$slap);
89 } elseif ($contact['network'] === NETWORK_DIASPORA) {
90 require_once 'include/diaspora.php';
91 Diaspora::send_unshare($user,$contact);
92 } elseif ($contact['network'] === NETWORK_DFRN) {
93 require_once 'include/dfrn.php';
94 dfrn::deliver($user,$contact,'placeholder', 1);
100 // Contact has refused to recognise us as a friend. We will start a countdown.
101 // If they still don't recognise us in 32 days, the relationship is over,
102 // and we won't waste any more time trying to communicate with them.
103 // This provides for the possibility that their database is temporarily messed
104 // up or some other transient event and that there's a possibility we could recover from it.
106 function mark_for_death($contact) {
108 if($contact['archive'])
111 if ($contact['term-date'] <= NULL_DATE) {
112 q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d",
113 dbesc(datetime_convert()),
114 intval($contact['id'])
117 if ($contact['url'] != '') {
118 q("UPDATE `contact` SET `term-date` = '%s'
119 WHERE `nurl` = '%s' AND `term-date` <= '1000-00-00'",
120 dbesc(datetime_convert()),
121 dbesc(normalise_link($contact['url']))
127 /// We really should send a notification to the owner after 2-3 weeks
128 /// so they won't be surprised when the contact vanishes and can take
129 /// remedial action if this was a serious mistake or glitch
132 /// Check for contact vitality via probing
134 $expiry = $contact['term-date'] . ' + 32 days ';
135 if(datetime_convert() > datetime_convert('UTC','UTC',$expiry)) {
137 // relationship is really truly dead.
138 // archive them rather than delete
139 // though if the owner tries to unarchive them we'll start the whole process over again
141 q("UPDATE `contact` SET `archive` = 1 WHERE `id` = %d",
142 intval($contact['id'])
145 if ($contact['url'] != '') {
146 q("UPDATE `contact` SET `archive` = 1 WHERE `nurl` = '%s'",
147 dbesc(normalise_link($contact['url']))
155 function unmark_for_death($contact) {
157 $r = q("SELECT `term-date` FROM `contact` WHERE `id` = %d AND `term-date` > '%s'",
158 intval($contact['id']),
159 dbesc('1000-00-00 00:00:00')
162 // We don't need to update, we never marked this contact as dead
163 if (!dbm::is_result($r)) {
167 // It's a miracle. Our dead contact has inexplicably come back to life.
168 q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d",
170 intval($contact['id'])
173 if ($contact['url'] != '') {
174 q("UPDATE `contact` SET `term-date` = '%s' WHERE `nurl` = '%s'",
176 dbesc(normalise_link($contact['url']))
182 * @brief Get contact data for a given profile link
184 * The function looks at several places (contact table and gcontact table) for the contact
185 * It caches its result for the same script execution to prevent duplicate calls
187 * @param string $url The profile link
188 * @param int $uid User id
189 * @param array $default If not data was found take this data as default value
191 * @return array Contact data
193 function get_contact_details_by_url($url, $uid = -1, $default = array()) {
194 static $cache = array();
204 if (isset($cache[$url][$uid])) {
205 return $cache[$url][$uid];
208 // Fetch contact data from the contact table for the given user
209 $r = q("SELECT `id`, `id` AS `cid`, 0 AS `gid`, 0 AS `zid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
210 `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, `self`
211 FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
212 dbesc(normalise_link($url)), intval($uid));
214 // Fetch the data from the contact table with "uid=0" (which is filled automatically)
215 if (!dbm::is_result($r))
216 $r = q("SELECT `id`, 0 AS `cid`, `id` AS `zid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
217 `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self`
218 FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0",
219 dbesc(normalise_link($url)));
221 // Fetch the data from the gcontact table
222 if (!dbm::is_result($r))
223 $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`,
224 `keywords`, `gender`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, `community` AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self`
225 FROM `gcontact` WHERE `nurl` = '%s'",
226 dbesc(normalise_link($url)));
228 if (dbm::is_result($r)) {
229 // If there is more than one entry we filter out the connector networks
231 foreach ($r AS $id => $result) {
232 if ($result["network"] == NETWORK_STATUSNET) {
238 $profile = array_shift($r);
240 // "bd" always contains the upcoming birthday of a contact.
241 // "birthday" might contain the birthday including the year of birth.
242 if ($profile["birthday"] > '0001-01-01') {
243 $bd_timestamp = strtotime($profile["birthday"]);
244 $month = date("m", $bd_timestamp);
245 $day = date("d", $bd_timestamp);
247 $current_timestamp = time();
248 $current_year = date("Y", $current_timestamp);
249 $current_month = date("m", $current_timestamp);
250 $current_day = date("d", $current_timestamp);
252 $profile["bd"] = $current_year."-".$month."-".$day;
253 $current = $current_year."-".$current_month."-".$current_day;
255 if ($profile["bd"] < $current) {
256 $profile["bd"] = (++$current_year)."-".$month."-".$day;
259 $profile["bd"] = '0001-01-01';
265 if (($profile["photo"] == "") && isset($default["photo"])) {
266 $profile["photo"] = $default["photo"];
269 if (($profile["name"] == "") && isset($default["name"])) {
270 $profile["name"] = $default["name"];
273 if (($profile["network"] == "") && isset($default["network"])) {
274 $profile["network"] = $default["network"];
277 if (($profile["thumb"] == "") && isset($profile["photo"])) {
278 $profile["thumb"] = $profile["photo"];
281 if (($profile["micro"] == "") && isset($profile["thumb"])) {
282 $profile["micro"] = $profile["thumb"];
285 if ((($profile["addr"] == "") || ($profile["name"] == "")) && ($profile["gid"] != 0) &&
286 in_array($profile["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) {
287 proc_run(PRIORITY_LOW, "include/update_gcontact.php", $profile["gid"]);
290 // Show contact details of Diaspora contacts only if connected
291 if (($profile["cid"] == 0) && ($profile["network"] == NETWORK_DIASPORA)) {
292 $profile["location"] = "";
293 $profile["about"] = "";
294 $profile["gender"] = "";
295 $profile["birthday"] = '0001-01-01';
298 $cache[$url][$uid] = $profile;
304 * @brief Get contact data for a given address
306 * The function looks at several places (contact table and gcontact table) for the contact
308 * @param string $addr The profile link
309 * @param int $uid User id
311 * @return array Contact data
313 function get_contact_details_by_addr($addr, $uid = -1) {
314 static $cache = array();
324 // Fetch contact data from the contact table for the given user
325 $r = q("SELECT `id`, `id` AS `cid`, 0 AS `gid`, 0 AS `zid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
326 `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, `self`
327 FROM `contact` WHERE `addr` = '%s' AND `uid` = %d",
328 dbesc($addr), intval($uid));
330 // Fetch the data from the contact table with "uid=0" (which is filled automatically)
331 if (!dbm::is_result($r))
332 $r = q("SELECT `id`, 0 AS `cid`, `id` AS `zid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
333 `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self`
334 FROM `contact` WHERE `addr` = '%s' AND `uid` = 0",
337 // Fetch the data from the gcontact table
338 if (!dbm::is_result($r))
339 $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`,
340 `keywords`, `gender`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, `community` AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self`
341 FROM `gcontact` WHERE `addr` = '%s'",
344 if (!dbm::is_result($r)) {
345 $data = Probe::uri($addr);
347 $profile = get_contact_details_by_url($data['url'], $uid);
355 if (! function_exists('contact_photo_menu')) {
356 function contact_photo_menu($contact, $uid = 0)
365 $contact_drop_link = '';
372 if ($contact['uid'] != $uid) {
374 $profile_link = zrl($contact['url']);
375 $menu = Array('profile' => array(t('View Profile'), $profile_link, true));
380 $r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `network` = '%s' AND `uid` = %d",
381 dbesc($contact['nurl']), dbesc($contact['network']), intval($uid));
383 return contact_photo_menu($r[0], $uid);
385 $profile_link = zrl($contact['url']);
386 $connlnk = 'follow/?url='.$contact['url'];
388 'profile' => array(t('View Profile'), $profile_link, true),
389 'follow' => array(t('Connect/Follow'), $connlnk, true)
397 if ($contact['network'] === NETWORK_DFRN) {
399 $profile_link = App::get_baseurl() . '/redir/' . $contact['id'];
401 $profile_link = $contact['url'];
404 if ($profile_link === 'mailbox') {
409 $status_link = $profile_link . '?url=status';
410 $photos_link = $profile_link . '?url=photos';
411 $profile_link = $profile_link . '?url=profile';
414 if (in_array($contact['network'], array(NETWORK_DFRN, NETWORK_DIASPORA))) {
415 $pm_url = App::get_baseurl() . '/message/new/' . $contact['id'];
418 if ($contact['network'] == NETWORK_DFRN) {
419 $poke_link = App::get_baseurl() . '/poke/?f=&c=' . $contact['id'];
422 $contact_url = App::get_baseurl() . '/contacts/' . $contact['id'];
424 $posts_link = App::get_baseurl() . '/contacts/' . $contact['id'] . '/posts';
425 $contact_drop_link = App::get_baseurl() . '/contacts/' . $contact['id'] . '/drop?confirm=1';
429 * "name" => [ "Label", "link", (bool)Should the link opened in a new tab? ]
432 'status' => array(t("View Status"), $status_link, true),
433 'profile' => array(t("View Profile"), $profile_link, true),
434 'photos' => array(t("View Photos"), $photos_link, true),
435 'network' => array(t("Network Posts"), $posts_link, false),
436 'edit' => array(t("View Contact"), $contact_url, false),
437 'drop' => array(t("Drop Contact"), $contact_drop_link, false),
438 'pm' => array(t("Send PM"), $pm_url, false),
439 'poke' => array(t("Poke"), $poke_link, false),
443 $args = array('contact' => $contact, 'menu' => &$menu);
445 call_hooks('contact_photo_menu', $args);
447 $menucondensed = array();
449 foreach ($menu AS $menuname => $menuitem) {
450 if ($menuitem[1] != '') {
451 $menucondensed[$menuname] = $menuitem;
455 return $menucondensed;
459 function random_profile() {
460 $r = q("SELECT `url` FROM `gcontact` WHERE `network` = '%s'
461 AND `last_contact` >= `last_failure`
462 AND `updated` > UTC_TIMESTAMP - INTERVAL 1 MONTH
463 ORDER BY rand() LIMIT 1",
464 dbesc(NETWORK_DFRN));
466 if (dbm::is_result($r))
467 return dirname($r[0]['url']);
472 function contacts_not_grouped($uid,$start = 0,$count = 0) {
475 $r = q("select count(*) as total from contact where uid = %d and self = 0 and id not in (select distinct(`contact-id`) from group_member where uid = %d) ",
485 $r = q("select * from contact where uid = %d and self = 0 and id not in (select distinct(`contact-id`) from group_member where uid = %d) and blocked = 0 and pending = 0 limit %d, %d",
496 * @brief Fetch the contact id for a given url and user
498 * First lookup in the contact table to find a record matching either `url`, `nurl`,
501 * If there's no record and we aren't looking for a public contact, we quit.
502 * If there's one, we check that it isn't time to update the picture else we
503 * directly return the found contact id.
505 * Second, we probe the provided $url wether it's http://server.tld/profile or
506 * nick@server.tld. We quit if we can't get any info back.
508 * Third, we create the contact record if it doesn't exist
510 * Fourth, we update the existing record with the new data (avatar, alias, nick)
511 * if there's any updates
513 * @param string $url Contact URL
514 * @param integer $uid The user id for the contact (0 = public contact)
515 * @param boolean $no_update Don't update the contact
517 * @return integer Contact ID
519 function get_contact($url, $uid = 0, $no_update = false) {
520 logger("Get contact data for url ".$url." and user ".$uid." - ".App::callstack(), LOGGER_DEBUG);
529 // We first try the nurl (http://server.tld/nick), most common case
530 $contact = dba::select('contact', array('id', 'avatar-date'), array('nurl' => normalise_link($url), 'uid' => $uid), array('limit' => 1));
532 // Then the addr (nick@server.tld)
533 if (!dbm::is_result($contact)) {
534 $contact = dba::select('contact', array('id', 'avatar-date'), array('addr' => $url, 'uid' => $uid), array('limit' => 1));
537 // Then the alias (which could be anything)
538 if (!dbm::is_result($contact)) {
539 $r = dba::p("SELECT `id`, `avatar-date` FROM `contact` WHERE `alias` IN (?, ?) AND `uid` = ? LIMIT 1",
540 $url, normalise_link($url), $uid);
541 $contact = dba::fetch($r);
545 if (dbm::is_result($contact)) {
546 $contact_id = $contact["id"];
548 // Update the contact every 7 days
549 $update_contact = ($contact['avatar-date'] < datetime_convert('','','now -7 days'));
551 if (!$update_contact || $no_update) {
554 } elseif ($uid != 0) {
555 // Non-existing user-specific contact, exiting
559 $data = Probe::uri($url);
561 // Last try in gcontact for unsupported networks
562 if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_PUMPIO))) {
567 // Get data from the gcontact table
568 $gcontacts = dba::select('gcontact', array('name', 'nick', 'url', 'photo', 'addr', 'alias', 'network'),
569 array('nurl' => normalise_link($url)), array('limit' => 1));
570 if (!dbm::is_result($gcontacts)) {
574 $data = array_merge($data, $gcontacts);
579 dba::insert('contact', array('uid' => $uid, 'created' => datetime_convert(), 'url' => $data["url"],
580 'nurl' => normalise_link($data["url"]), 'addr' => $data["addr"],
581 'alias' => $data["alias"], 'notify' => $data["notify"], 'poll' => $data["poll"],
582 'name' => $data["name"], 'nick' => $data["nick"], 'photo' => $data["photo"],
583 'keywords' => $data["keywords"], 'location' => $data["location"], 'about' => $data["about"],
584 'network' => $data["network"], 'pubkey' => $data["pubkey"],
585 'rel' => CONTACT_IS_SHARING, 'priority' => $data["priority"],
586 'batch' => $data["batch"], 'request' => $data["request"],
587 'confirm' => $data["confirm"], 'poco' => $data["poco"],
588 'name-date' => datetime_convert(), 'uri-date' => datetime_convert(),
589 'avatar-date' => datetime_convert(), 'writable' => 1, 'blocked' => 0,
590 'readonly' => 0, 'pending' => 0));
592 $contacts = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d ORDER BY `id` LIMIT 2",
593 dbesc(normalise_link($data["url"])),
595 if (!dbm::is_result($contacts)) {
599 $contact_id = $contacts[0]["id"];
601 // Update the newly created contact from data in the gcontact table
602 $gcontact = dba::select('gcontact', array('location', 'about', 'keywords', 'gender'),
603 array('nurl' => normalise_link($data["url"])), array('limit' => 1));
604 if (dbm::is_result($gcontact)) {
605 // Only use the information when the probing hadn't fetched these values
606 if ($data['keywords'] != '') {
607 unset($gcontact['keywords']);
609 if ($data['location'] != '') {
610 unset($gcontact['location']);
612 if ($data['about'] != '') {
613 unset($gcontact['about']);
615 dba::update('contact', $gcontact, array('id' => $contact_id));
618 if (count($contacts) > 1 && $uid == 0 && $contact_id != 0 && $data["url"] != "") {
619 dba::e("DELETE FROM `contact` WHERE `nurl` = ? AND `uid` = 0 AND `id` != ? AND NOT `self`",
620 normalise_link($data["url"]), $contact_id);
624 require_once "Photo.php";
626 update_contact_avatar($data["photo"], $uid, $contact_id);
628 $contact = dba::select('contact', array('addr', 'alias', 'name', 'nick', 'keywords', 'location', 'about', 'avatar-date'),
629 array('id' => $contact_id), array('limit' => 1));
631 // This condition should always be true
632 if (!dbm::is_result($contact)) {
636 $updated = array('addr' => $data['addr'],
637 'alias' => $data['alias'],
638 'name' => $data['name'],
639 'nick' => $data['nick']);
641 if ($data['keywords'] != '') {
642 $updated['keywords'] = $data['keywords'];
644 if ($data['location'] != '') {
645 $updated['location'] = $data['location'];
647 if ($data['about'] != '') {
648 $updated['about'] = $data['about'];
651 if (($data["addr"] != $contact["addr"]) || ($data["alias"] != $contact["alias"])) {
652 $updated['uri-date'] = datetime_convert();
654 if (($data["name"] != $contact["name"]) || ($data["nick"] != $contact["nick"])) {
655 $updated['name-date'] = datetime_convert();
658 $updated['avatar-date'] = datetime_convert();
660 dba::update('contact', $updated, array('id' => $contact_id), $contact);
666 * @brief Returns posts from a given gcontact
668 * @param App $a argv application class
669 * @param int $gcontact_id Global contact
671 * @return string posts in HTML
673 function posts_from_gcontact(App $a, $gcontact_id) {
675 require_once 'include/conversation.php';
677 // There are no posts with "uid = 0" with connector networks
678 // This speeds up the query a lot
679 $r = q("SELECT `network` FROM `gcontact` WHERE `id` = %d", dbesc($gcontact_id));
680 if (in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, "")))
681 $sql = "(`item`.`uid` = 0 OR (`item`.`uid` = %d AND `item`.`private`))";
683 $sql = "`item`.`uid` = %d";
685 $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
686 `author-name` AS `name`, `owner-avatar` AS `photo`,
687 `owner-link` AS `url`, `owner-avatar` AS `thumb`
689 WHERE `gcontact-id` = %d AND $sql AND
690 NOT `deleted` AND NOT `moderated` AND `visible`
691 ORDER BY `item`.`created` DESC LIMIT %d, %d",
692 intval($gcontact_id),
693 intval(local_user()),
694 intval($a->pager['start']),
695 intval($a->pager['itemspage'])
698 $o = conversation($a, $r, 'community', false);
700 $o .= alt_pager($a, count($r));
705 * @brief Returns posts from a given contact url
707 * @param App $a argv application class
708 * @param string $contact_url Contact URL
710 * @return string posts in HTML
712 function posts_from_contact_url(App $a, $contact_url) {
714 require_once 'include/conversation.php';
716 // There are no posts with "uid = 0" with connector networks
717 // This speeds up the query a lot
718 $r = q("SELECT `network`, `id` AS `author-id` FROM `contact`
719 WHERE `contact`.`nurl` = '%s' AND `contact`.`uid` = 0",
720 dbesc(normalise_link($contact_url)));
721 if (in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, ""))) {
722 $sql = "(`item`.`uid` = 0 OR (`item`.`uid` = %d AND `item`.`private`))";
724 $sql = "`item`.`uid` = %d";
727 if (!dbm::is_result($r)) {
731 $author_id = intval($r[0]["author-id"]);
733 $r = q(item_query()." AND `item`.`author-id` = %d AND ".$sql.
734 " ORDER BY `item`.`created` DESC LIMIT %d, %d",
736 intval(local_user()),
737 intval($a->pager['start']),
738 intval($a->pager['itemspage'])
741 $o = conversation($a, $r, 'community', false);
743 $o .= alt_pager($a, count($r));
749 * @brief Returns a formatted location string from the given profile array
751 * @param array $profile Profile array (Generated from the "profile" table)
753 * @return string Location string
755 function formatted_location($profile) {
758 if($profile['locality'])
759 $location .= $profile['locality'];
761 if($profile['region'] && ($profile['locality'] != $profile['region'])) {
765 $location .= $profile['region'];
768 if($profile['country-name']) {
772 $location .= $profile['country-name'];
779 * @brief Returns the account type name
781 * The function can be called with either the user or the contact array
783 * @param array $contact contact or user array
785 function account_type($contact) {
787 // There are several fields that indicate that the contact or user is a forum
788 // "page-flags" is a field in the user table,
789 // "forum" and "prv" are used in the contact table. They stand for PAGE_COMMUNITY and PAGE_PRVGROUP.
790 // "community" is used in the gcontact table and is true if the contact is PAGE_COMMUNITY or PAGE_PRVGROUP.
791 if((isset($contact['page-flags']) && (intval($contact['page-flags']) == PAGE_COMMUNITY))
792 || (isset($contact['page-flags']) && (intval($contact['page-flags']) == PAGE_PRVGROUP))
793 || (isset($contact['forum']) && intval($contact['forum']))
794 || (isset($contact['prv']) && intval($contact['prv']))
795 || (isset($contact['community']) && intval($contact['community'])))
796 $type = ACCOUNT_TYPE_COMMUNITY;
798 $type = ACCOUNT_TYPE_PERSON;
800 // The "contact-type" (contact table) and "account-type" (user table) are more general then the chaos from above.
801 if (isset($contact["contact-type"]))
802 $type = $contact["contact-type"];
803 if (isset($contact["account-type"]))
804 $type = $contact["account-type"];
807 case ACCOUNT_TYPE_ORGANISATION:
808 $account_type = t("Organisation");
810 case ACCOUNT_TYPE_NEWS:
811 $account_type = t('News');
813 case ACCOUNT_TYPE_COMMUNITY:
814 $account_type = t("Forum");
821 return $account_type;