3 // Included here for completeness, but this is a very dangerous operation.
4 // It is the caller's responsibility to confirm the requestor's intent and
5 // authorisation to do this.
7 function user_remove($uid) {
10 logger('Removing user: ' . $uid);
12 $r = q("select * from user where uid = %d limit 1", intval($uid));
14 call_hooks('remove_user',$r[0]);
16 // save username (actually the nickname as it is guaranteed
17 // unique), so it cannot be re-registered in the future.
19 q("insert into userd ( username ) values ( '%s' )",
23 /// @todo Should be done in a background job since this likely will run into a time out
24 // don't delete yet, will be done later when contacts have deleted my stuff
25 // q("DELETE FROM `contact` WHERE `uid` = %d", intval($uid));
26 q("DELETE FROM `gcign` WHERE `uid` = %d", intval($uid));
27 q("DELETE FROM `group` WHERE `uid` = %d", intval($uid));
28 q("DELETE FROM `group_member` WHERE `uid` = %d", intval($uid));
29 q("DELETE FROM `intro` WHERE `uid` = %d", intval($uid));
30 q("DELETE FROM `event` WHERE `uid` = %d", intval($uid));
31 q("DELETE FROM `item` WHERE `uid` = %d", intval($uid));
32 q("DELETE FROM `item_id` WHERE `uid` = %d", intval($uid));
33 q("DELETE FROM `mail` WHERE `uid` = %d", intval($uid));
34 q("DELETE FROM `mailacct` WHERE `uid` = %d", intval($uid));
35 q("DELETE FROM `manage` WHERE `uid` = %d", intval($uid));
36 q("DELETE FROM `notify` WHERE `uid` = %d", intval($uid));
37 q("DELETE FROM `photo` WHERE `uid` = %d", intval($uid));
38 q("DELETE FROM `attach` WHERE `uid` = %d", intval($uid));
39 q("DELETE FROM `profile` WHERE `uid` = %d", intval($uid));
40 q("DELETE FROM `profile_check` WHERE `uid` = %d", intval($uid));
41 q("DELETE FROM `pconfig` WHERE `uid` = %d", intval($uid));
42 q("DELETE FROM `search` WHERE `uid` = %d", intval($uid));
43 q("DELETE FROM `spam` WHERE `uid` = %d", intval($uid));
44 // don't delete yet, will be done later when contacts have deleted my stuff
45 // q("DELETE FROM `user` WHERE `uid` = %d", intval($uid));
46 q("UPDATE `user` SET `account_removed` = 1, `account_expires_on` = UTC_TIMESTAMP() WHERE `uid` = %d", intval($uid));
47 proc_run(PRIORITY_HIGH, "include/notifier.php", "removeme", $uid);
49 // Send an update to the directory
50 proc_run(PRIORITY_LOW, "include/directory.php", $r[0]['url']);
52 if($uid == local_user()) {
53 unset($_SESSION['authenticated']);
54 unset($_SESSION['uid']);
55 goaway(App::get_baseurl());
60 function contact_remove($id) {
62 // We want just to make sure that we don't delete our "self" contact
63 $r = q("SELECT `uid` FROM `contact` WHERE `id` = %d AND NOT `self` LIMIT 1",
66 if (!dbm::is_result($r) || !intval($r[0]['uid'])) {
70 $archive = get_pconfig($r[0]['uid'], 'system','archive_removed_contacts');
72 q("update contact set `archive` = 1, `network` = 'none', `writable` = 0 where id = %d",
78 q("DELETE FROM `contact` WHERE `id` = %d", intval($id));
80 // Delete the rest in the background
81 proc_run(PRIORITY_LOW, 'include/remove_contact.php', $id);
85 // sends an unfriend message. Does not remove the contact
87 function terminate_friendship($user,$self,$contact) {
89 /// @TODO Get rid of this, include/datetime.php should care about it by itself
92 require_once('include/datetime.php');
94 if ($contact['network'] === NETWORK_OSTATUS) {
96 require_once('include/ostatus.php');
98 // create an unfollow slap
100 $item['verb'] = NAMESPACE_OSTATUS."/unfollow";
101 $item['follow'] = $contact["url"];
102 $slap = ostatus::salmon($item, $user);
104 if ((x($contact,'notify')) && (strlen($contact['notify']))) {
105 require_once('include/salmon.php');
106 slapper($user,$contact['notify'],$slap);
108 } elseif ($contact['network'] === NETWORK_DIASPORA) {
109 require_once('include/diaspora.php');
110 Diaspora::send_unshare($user,$contact);
111 } elseif ($contact['network'] === NETWORK_DFRN) {
112 require_once('include/dfrn.php');
113 dfrn::deliver($user,$contact,'placeholder', 1);
119 // Contact has refused to recognise us as a friend. We will start a countdown.
120 // If they still don't recognise us in 32 days, the relationship is over,
121 // and we won't waste any more time trying to communicate with them.
122 // This provides for the possibility that their database is temporarily messed
123 // up or some other transient event and that there's a possibility we could recover from it.
125 function mark_for_death($contact) {
127 if($contact['archive'])
130 if ($contact['term-date'] <= NULL_DATE) {
131 q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d",
132 dbesc(datetime_convert()),
133 intval($contact['id'])
136 if ($contact['url'] != '') {
137 q("UPDATE `contact` SET `term-date` = '%s'
138 WHERE `nurl` = '%s' AND `term-date` <= '1000-00-00'",
139 dbesc(datetime_convert()),
140 dbesc(normalise_link($contact['url']))
146 /// We really should send a notification to the owner after 2-3 weeks
147 /// so they won't be surprised when the contact vanishes and can take
148 /// remedial action if this was a serious mistake or glitch
151 /// Check for contact vitality via probing
153 $expiry = $contact['term-date'] . ' + 32 days ';
154 if(datetime_convert() > datetime_convert('UTC','UTC',$expiry)) {
156 // relationship is really truly dead.
157 // archive them rather than delete
158 // though if the owner tries to unarchive them we'll start the whole process over again
160 q("UPDATE `contact` SET `archive` = 1 WHERE `id` = %d",
161 intval($contact['id'])
164 if ($contact['url'] != '') {
165 q("UPDATE `contact` SET `archive` = 1 WHERE `nurl` = '%s'",
166 dbesc(normalise_link($contact['url']))
174 function unmark_for_death($contact) {
176 $r = q("SELECT `term-date` FROM `contact` WHERE `id` = %d AND `term-date` > '%s'",
177 intval($contact['id']),
178 dbesc('1000-00-00 00:00:00')
181 // We don't need to update, we never marked this contact as dead
182 if (!dbm::is_result($r)) {
186 // It's a miracle. Our dead contact has inexplicably come back to life.
187 q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d",
189 intval($contact['id'])
192 if ($contact['url'] != '') {
193 q("UPDATE `contact` SET `term-date` = '%s' WHERE `nurl` = '%s'",
195 dbesc(normalise_link($contact['url']))
201 * @brief Get contact data for a given profile link
203 * The function looks at several places (contact table and gcontact table) for the contact
204 * It caches its result for the same script execution to prevent duplicate calls
206 * @param string $url The profile link
207 * @param int $uid User id
208 * @param array $default If not data was found take this data as default value
210 * @return array Contact data
212 function get_contact_details_by_url($url, $uid = -1, $default = array()) {
213 static $cache = array();
223 if (isset($cache[$url][$uid])) {
224 return $cache[$url][$uid];
227 // Fetch contact data from the contact table for the given user
228 $r = q("SELECT `id`, `id` AS `cid`, 0 AS `gid`, 0 AS `zid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
229 `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, `self`
230 FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
231 dbesc(normalise_link($url)), intval($uid));
233 // Fetch the data from the contact table with "uid=0" (which is filled automatically)
234 if (!dbm::is_result($r))
235 $r = q("SELECT `id`, 0 AS `cid`, `id` AS `zid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
236 `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self`
237 FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0",
238 dbesc(normalise_link($url)));
240 // Fetch the data from the gcontact table
241 if (!dbm::is_result($r))
242 $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`,
243 `keywords`, `gender`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, `community` AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self`
244 FROM `gcontact` WHERE `nurl` = '%s'",
245 dbesc(normalise_link($url)));
247 if (dbm::is_result($r)) {
248 // If there is more than one entry we filter out the connector networks
250 foreach ($r AS $id => $result) {
251 if ($result["network"] == NETWORK_STATUSNET) {
257 $profile = array_shift($r);
259 // "bd" always contains the upcoming birthday of a contact.
260 // "birthday" might contain the birthday including the year of birth.
261 if ($profile["birthday"] > '0001-01-01') {
262 $bd_timestamp = strtotime($profile["birthday"]);
263 $month = date("m", $bd_timestamp);
264 $day = date("d", $bd_timestamp);
266 $current_timestamp = time();
267 $current_year = date("Y", $current_timestamp);
268 $current_month = date("m", $current_timestamp);
269 $current_day = date("d", $current_timestamp);
271 $profile["bd"] = $current_year."-".$month."-".$day;
272 $current = $current_year."-".$current_month."-".$current_day;
274 if ($profile["bd"] < $current) {
275 $profile["bd"] = (++$current_year)."-".$month."-".$day;
278 $profile["bd"] = '0001-01-01';
284 if (($profile["photo"] == "") AND isset($default["photo"])) {
285 $profile["photo"] = $default["photo"];
288 if (($profile["name"] == "") AND isset($default["name"])) {
289 $profile["name"] = $default["name"];
292 if (($profile["network"] == "") AND isset($default["network"])) {
293 $profile["network"] = $default["network"];
296 if (($profile["thumb"] == "") AND isset($profile["photo"])) {
297 $profile["thumb"] = $profile["photo"];
300 if (($profile["micro"] == "") AND isset($profile["thumb"])) {
301 $profile["micro"] = $profile["thumb"];
304 if ((($profile["addr"] == "") OR ($profile["name"] == "")) AND ($profile["gid"] != 0) AND
305 in_array($profile["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) {
306 proc_run(PRIORITY_LOW, "include/update_gcontact.php", $profile["gid"]);
309 // Show contact details of Diaspora contacts only if connected
310 if (($profile["cid"] == 0) AND ($profile["network"] == NETWORK_DIASPORA)) {
311 $profile["location"] = "";
312 $profile["about"] = "";
313 $profile["gender"] = "";
314 $profile["birthday"] = '0001-01-01';
317 $cache[$url][$uid] = $profile;
323 * @brief Get contact data for a given address
325 * The function looks at several places (contact table and gcontact table) for the contact
327 * @param string $addr The profile link
328 * @param int $uid User id
330 * @return array Contact data
332 function get_contact_details_by_addr($addr, $uid = -1) {
333 static $cache = array();
343 // Fetch contact data from the contact table for the given user
344 $r = q("SELECT `id`, `id` AS `cid`, 0 AS `gid`, 0 AS `zid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
345 `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, `self`
346 FROM `contact` WHERE `addr` = '%s' AND `uid` = %d",
347 dbesc($addr), intval($uid));
349 // Fetch the data from the contact table with "uid=0" (which is filled automatically)
350 if (!dbm::is_result($r))
351 $r = q("SELECT `id`, 0 AS `cid`, `id` AS `zid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
352 `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self`
353 FROM `contact` WHERE `addr` = '%s' AND `uid` = 0",
356 // Fetch the data from the gcontact table
357 if (!dbm::is_result($r))
358 $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`,
359 `keywords`, `gender`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, `community` AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self`
360 FROM `gcontact` WHERE `addr` = '%s'",
363 if (!dbm::is_result($r)) {
364 require_once('include/Probe.php');
365 $data = Probe::uri($addr);
367 $profile = get_contact_details_by_url($data['url'], $uid);
375 if (! function_exists('contact_photo_menu')) {
376 function contact_photo_menu($contact, $uid = 0)
385 $contact_drop_link = '';
392 if ($contact['uid'] != $uid) {
394 $profile_link = zrl($contact['url']);
395 $menu = Array('profile' => array(t('View Profile'), $profile_link, true));
400 $r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `network` = '%s' AND `uid` = %d",
401 dbesc($contact['nurl']), dbesc($contact['network']), intval($uid));
403 return contact_photo_menu($r[0], $uid);
405 $profile_link = zrl($contact['url']);
406 $connlnk = 'follow/?url='.$contact['url'];
408 'profile' => array(t('View Profile'), $profile_link, true),
409 'follow' => array(t('Connect/Follow'), $connlnk, true)
417 if ($contact['network'] === NETWORK_DFRN) {
419 $profile_link = App::get_baseurl() . '/redir/' . $contact['id'];
421 $profile_link = $contact['url'];
424 if ($profile_link === 'mailbox') {
429 $status_link = $profile_link . '?url=status';
430 $photos_link = $profile_link . '?url=photos';
431 $profile_link = $profile_link . '?url=profile';
434 if (in_array($contact['network'], array(NETWORK_DFRN, NETWORK_DIASPORA))) {
435 $pm_url = App::get_baseurl() . '/message/new/' . $contact['id'];
438 if ($contact['network'] == NETWORK_DFRN) {
439 $poke_link = App::get_baseurl() . '/poke/?f=&c=' . $contact['id'];
442 $contact_url = App::get_baseurl() . '/contacts/' . $contact['id'];
444 $posts_link = App::get_baseurl() . '/contacts/' . $contact['id'] . '/posts';
445 $contact_drop_link = App::get_baseurl() . '/contacts/' . $contact['id'] . '/drop?confirm=1';
449 * "name" => [ "Label", "link", (bool)Should the link opened in a new tab? ]
452 'status' => array(t("View Status"), $status_link, true),
453 'profile' => array(t("View Profile"), $profile_link, true),
454 'photos' => array(t("View Photos"), $photos_link, true),
455 'network' => array(t("Network Posts"), $posts_link, false),
456 'edit' => array(t("View Contact"), $contact_url, false),
457 'drop' => array(t("Drop Contact"), $contact_drop_link, false),
458 'pm' => array(t("Send PM"), $pm_url, false),
459 'poke' => array(t("Poke"), $poke_link, false),
463 $args = array('contact' => $contact, 'menu' => &$menu);
465 call_hooks('contact_photo_menu', $args);
467 $menucondensed = array();
469 foreach ($menu AS $menuname => $menuitem) {
470 if ($menuitem[1] != '') {
471 $menucondensed[$menuname] = $menuitem;
475 return $menucondensed;
479 function random_profile() {
480 $r = q("SELECT `url` FROM `gcontact` WHERE `network` = '%s'
481 AND `last_contact` >= `last_failure`
482 AND `updated` > UTC_TIMESTAMP - INTERVAL 1 MONTH
483 ORDER BY rand() LIMIT 1",
484 dbesc(NETWORK_DFRN));
486 if (dbm::is_result($r))
487 return dirname($r[0]['url']);
492 function contacts_not_grouped($uid,$start = 0,$count = 0) {
495 $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) ",
505 $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",
516 * @brief Fetch the contact id for a given url and user
518 * First lookup in the contact table to find a record matching either `url`, `nurl`,
521 * If there's no record and we aren't looking for a public contact, we quit.
522 * If there's one, we check that it isn't time to update the picture else we
523 * directly return the found contact id.
525 * Second, we probe the provided $url wether it's http://server.tld/profile or
526 * nick@server.tld. We quit if we can't get any info back.
528 * Third, we create the contact record if it doesn't exist
530 * Fourth, we update the existing record with the new data (avatar, alias, nick)
531 * if there's any updates
533 * @param string $url Contact URL
534 * @param integer $uid The user id for the contact (0 = public contact)
535 * @param boolean $no_update Don't update the contact
537 * @return integer Contact ID
539 function get_contact($url, $uid = 0, $no_update = false) {
540 logger("Get contact data for url ".$url." and user ".$uid." - ".App::callstack(), LOGGER_DEBUG);;
549 // We first try the nurl (http://server.tld/nick), most common case
550 $contacts = q("SELECT `id`, `avatar-date` FROM `contact`
553 dbesc(normalise_link($url)),
557 // Then the addr (nick@server.tld)
558 if (! dbm::is_result($contacts)) {
559 $contacts = q("SELECT `id`, `avatar-date` FROM `contact`
566 // Then the alias (which could be anything)
567 if (! dbm::is_result($contacts)) {
568 $contacts = q("SELECT `id`, `avatar-date` FROM `contact`
569 WHERE `alias` IN ('%s', '%s')
572 dbesc(normalise_link($url)),
576 if (dbm::is_result($contacts)) {
577 $contact_id = $contacts[0]["id"];
579 // Update the contact every 7 days
580 $update_photo = ($contacts[0]['avatar-date'] < datetime_convert('','','now -7 days'));
582 if (!$update_photo OR $no_update) {
585 } elseif ($uid != 0) {
586 // Non-existing user-specific contact, exiting
590 require_once('include/Probe.php');
591 $data = Probe::uri($url);
593 // Last try in gcontact for unsupported networks
594 if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_PUMPIO))) {
599 // Get data from the gcontact table
600 $gcontacts = q("SELECT `name`, `nick`, `url`, `photo`, `addr`, `alias`, `network` FROM `gcontact` WHERE `nurl` = '%s'",
601 dbesc(normalise_link($url)));
606 $data = $gcontacts[0];
612 q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`,
613 `name`, `nick`, `photo`, `network`, `pubkey`, `rel`, `priority`,
614 `batch`, `request`, `confirm`, `poco`, `name-date`, `uri-date`,
615 `writable`, `blocked`, `readonly`, `pending`)
616 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)",
618 dbesc(datetime_convert()),
620 dbesc(normalise_link($data["url"])),
621 dbesc($data["addr"]),
622 dbesc($data["alias"]),
623 dbesc($data["notify"]),
624 dbesc($data["poll"]),
625 dbesc($data["name"]),
626 dbesc($data["nick"]),
627 dbesc($data["photo"]),
628 dbesc($data["network"]),
629 dbesc($data["pubkey"]),
630 intval(CONTACT_IS_SHARING),
631 intval($data["priority"]),
632 dbesc($data["batch"]),
633 dbesc($data["request"]),
634 dbesc($data["confirm"]),
635 dbesc($data["poco"]),
636 dbesc(datetime_convert()),
637 dbesc(datetime_convert())
640 $contacts = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d ORDER BY `id` LIMIT 2",
641 dbesc(normalise_link($data["url"])),
643 if (!dbm::is_result($contacts)) {
647 $contact_id = $contacts[0]["id"];
649 // Update the newly created contact from data in the gcontact table
650 $gcontacts = q("SELECT `location`, `about`, `keywords`, `gender` FROM `gcontact` WHERE `nurl` = '%s'",
651 dbesc(normalise_link($data["url"])));
652 if (dbm::is_result($gcontacts)) {
653 logger("Update contact " . $data["url"] . ' from gcontact');
654 q("UPDATE `contact` SET `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `id` = %d",
655 dbesc($gcontacts[0]["location"]), dbesc($gcontacts[0]["about"]), dbesc($gcontacts[0]["keywords"]),
656 dbesc($gcontacts[0]["gender"]), intval($contact_id));
660 if (count($contacts) > 1 AND $uid == 0 AND $contact_id != 0 AND $url != "") {
661 q("DELETE FROM `contact` WHERE `nurl` = '%s' AND `id` != %d AND NOT `self`",
662 dbesc(normalise_link($url)),
663 intval($contact_id));
666 require_once "Photo.php";
668 update_contact_avatar($data["photo"], $uid, $contact_id);
670 $contacts = q("SELECT `addr`, `alias`, `name`, `nick` FROM `contact` WHERE `id` = %d", intval($contact_id));
672 // This condition should always be true
673 if (!dbm::is_result($contacts)) {
677 // Only update if there had something been changed
678 if ($data["addr"] != $contacts[0]["addr"] OR
679 $data["alias"] != $contacts[0]["alias"] OR
680 $data["name"] != $contacts[0]["name"] OR
681 $data["nick"] != $contacts[0]["nick"]) {
682 q("UPDATE `contact` SET `addr` = '%s', `alias` = '%s', `name` = '%s', `nick` = '%s',
683 `name-date` = '%s', `uri-date` = '%s' WHERE `id` = %d",
684 dbesc($data["addr"]),
685 dbesc($data["alias"]),
686 dbesc($data["name"]),
687 dbesc($data["nick"]),
688 dbesc(datetime_convert()),
689 dbesc(datetime_convert()),
698 * @brief Returns posts from a given gcontact
700 * @param App $a argv application class
701 * @param int $gcontact_id Global contact
703 * @return string posts in HTML
705 function posts_from_gcontact(App $a, $gcontact_id) {
707 require_once('include/conversation.php');
709 // There are no posts with "uid = 0" with connector networks
710 // This speeds up the query a lot
711 $r = q("SELECT `network` FROM `gcontact` WHERE `id` = %d", dbesc($gcontact_id));
712 if (in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, "")))
713 $sql = "(`item`.`uid` = 0 OR (`item`.`uid` = %d AND `item`.`private`))";
715 $sql = "`item`.`uid` = %d";
717 $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
718 `author-name` AS `name`, `owner-avatar` AS `photo`,
719 `owner-link` AS `url`, `owner-avatar` AS `thumb`
721 WHERE `gcontact-id` = %d AND $sql AND
722 NOT `deleted` AND NOT `moderated` AND `visible`
723 ORDER BY `item`.`created` DESC LIMIT %d, %d",
724 intval($gcontact_id),
725 intval(local_user()),
726 intval($a->pager['start']),
727 intval($a->pager['itemspage'])
730 $o = conversation($a, $r, 'community', false);
732 $o .= alt_pager($a, count($r));
737 * @brief Returns posts from a given contact url
739 * @param App $a argv application class
740 * @param string $contact_url Contact URL
742 * @return string posts in HTML
744 function posts_from_contact_url(App $a, $contact_url) {
746 require_once('include/conversation.php');
748 // There are no posts with "uid = 0" with connector networks
749 // This speeds up the query a lot
750 $r = q("SELECT `network`, `id` AS `author-id` FROM `contact`
751 WHERE `contact`.`nurl` = '%s' AND `contact`.`uid` = 0",
752 dbesc(normalise_link($contact_url)));
753 if (in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, ""))) {
754 $sql = "(`item`.`uid` = 0 OR (`item`.`uid` = %d AND `item`.`private`))";
756 $sql = "`item`.`uid` = %d";
759 if (!dbm::is_result($r)) {
763 $author_id = intval($r[0]["author-id"]);
765 $r = q(item_query()." AND `item`.`author-id` = %d AND ".$sql.
766 " ORDER BY `item`.`created` DESC LIMIT %d, %d",
768 intval(local_user()),
769 intval($a->pager['start']),
770 intval($a->pager['itemspage'])
773 $o = conversation($a, $r, 'community', false);
775 $o .= alt_pager($a, count($r));
781 * @brief Returns a formatted location string from the given profile array
783 * @param array $profile Profile array (Generated from the "profile" table)
785 * @return string Location string
787 function formatted_location($profile) {
790 if($profile['locality'])
791 $location .= $profile['locality'];
793 if($profile['region'] AND ($profile['locality'] != $profile['region'])) {
797 $location .= $profile['region'];
800 if($profile['country-name']) {
804 $location .= $profile['country-name'];
811 * @brief Returns the account type name
813 * The function can be called with either the user or the contact array
815 * @param array $contact contact or user array
817 function account_type($contact) {
819 // There are several fields that indicate that the contact or user is a forum
820 // "page-flags" is a field in the user table,
821 // "forum" and "prv" are used in the contact table. They stand for PAGE_COMMUNITY and PAGE_PRVGROUP.
822 // "community" is used in the gcontact table and is true if the contact is PAGE_COMMUNITY or PAGE_PRVGROUP.
823 if((isset($contact['page-flags']) && (intval($contact['page-flags']) == PAGE_COMMUNITY))
824 || (isset($contact['page-flags']) && (intval($contact['page-flags']) == PAGE_PRVGROUP))
825 || (isset($contact['forum']) && intval($contact['forum']))
826 || (isset($contact['prv']) && intval($contact['prv']))
827 || (isset($contact['community']) && intval($contact['community'])))
828 $type = ACCOUNT_TYPE_COMMUNITY;
830 $type = ACCOUNT_TYPE_PERSON;
832 // The "contact-type" (contact table) and "account-type" (user table) are more general then the chaos from above.
833 if (isset($contact["contact-type"]))
834 $type = $contact["contact-type"];
835 if (isset($contact["account-type"]))
836 $type = $contact["account-type"];
839 case ACCOUNT_TYPE_ORGANISATION:
840 $account_type = t("Organisation");
842 case ACCOUNT_TYPE_NEWS:
843 $account_type = t('News');
845 case ACCOUNT_TYPE_COMMUNITY:
846 $account_type = t("Forum");
853 return $account_type;