]> git.mxchange.org Git - friendica.git/blob - include/Contact.php
Unified contact data handling
[friendica.git] / include / Contact.php
1 <?php
2
3
4 // Included here for completeness, but this is a very dangerous operation.
5 // It is the caller's responsibility to confirm the requestor's intent and
6 // authorisation to do this.
7
8 function user_remove($uid) {
9         if(! $uid)
10                 return;
11         $a = get_app();
12         logger('Removing user: ' . $uid);
13
14         $r = q("select * from user where uid = %d limit 1", intval($uid));
15
16         call_hooks('remove_user',$r[0]);
17
18         // save username (actually the nickname as it is guaranteed
19         // unique), so it cannot be re-registered in the future.
20
21         q("insert into userd ( username ) values ( '%s' )",
22                 $r[0]['nickname']
23         );
24
25         // don't delete yet, will be done later when contacts have deleted my stuff
26         // q("DELETE FROM `contact` WHERE `uid` = %d", intval($uid));
27         q("DELETE FROM `gcign` WHERE `uid` = %d", intval($uid));
28         q("DELETE FROM `group` WHERE `uid` = %d", intval($uid));
29         q("DELETE FROM `group_member` WHERE `uid` = %d", intval($uid));
30         q("DELETE FROM `intro` WHERE `uid` = %d", intval($uid));
31         q("DELETE FROM `event` WHERE `uid` = %d", intval($uid));
32         q("DELETE FROM `item` WHERE `uid` = %d", intval($uid));
33         q("DELETE FROM `item_id` WHERE `uid` = %d", intval($uid));
34         q("DELETE FROM `mail` WHERE `uid` = %d", intval($uid));
35         q("DELETE FROM `mailacct` WHERE `uid` = %d", intval($uid));
36         q("DELETE FROM `manage` WHERE `uid` = %d", intval($uid));
37         q("DELETE FROM `notify` WHERE `uid` = %d", intval($uid));
38         q("DELETE FROM `photo` WHERE `uid` = %d", intval($uid));
39         q("DELETE FROM `attach` WHERE `uid` = %d", intval($uid));
40         q("DELETE FROM `profile` WHERE `uid` = %d", intval($uid));
41         q("DELETE FROM `profile_check` WHERE `uid` = %d", intval($uid));
42         q("DELETE FROM `pconfig` WHERE `uid` = %d", intval($uid));
43         q("DELETE FROM `search` WHERE `uid` = %d", intval($uid));
44         q("DELETE FROM `spam` WHERE `uid` = %d", intval($uid));
45         // don't delete yet, will be done later when contacts have deleted my stuff
46         // q("DELETE FROM `user` WHERE `uid` = %d", intval($uid));
47         q("UPDATE `user` SET `account_removed` = 1, `account_expires_on` = UTC_TIMESTAMP() WHERE `uid` = %d", intval($uid));
48         proc_run('php', "include/notifier.php", "removeme", $uid);
49
50         // Send an update to the directory
51         proc_run('php', "include/directory.php", $r[0]['url']);
52
53         if($uid == local_user()) {
54                 unset($_SESSION['authenticated']);
55                 unset($_SESSION['uid']);
56                 goaway($a->get_baseurl());
57         }
58 }
59
60
61 function contact_remove($id) {
62
63         $r = q("select uid from contact where id = %d limit 1",
64                 intval($id)
65         );
66         if((! count($r)) || (! intval($r[0]['uid'])))
67                 return;
68
69         $archive = get_pconfig($r[0]['uid'], 'system','archive_removed_contacts');
70         if($archive) {
71                 q("update contact set `archive` = 1, `network` = 'none', `writable` = 0 where id = %d",
72                         intval($id)
73                 );
74                 return;
75         }
76
77         q("DELETE FROM `contact` WHERE `id` = %d",
78                 intval($id)
79         );
80         q("DELETE FROM `item` WHERE `contact-id` = %d ",
81                 intval($id)
82         );
83         q("DELETE FROM `photo` WHERE `contact-id` = %d ",
84                 intval($id)
85         );
86         q("DELETE FROM `mail` WHERE `contact-id` = %d ",
87                 intval($id)
88         );
89         q("DELETE FROM `event` WHERE `cid` = %d ",
90                 intval($id)
91         );
92         q("DELETE FROM `queue` WHERE `cid` = %d ",
93                 intval($id)
94         );
95
96 }
97
98
99 // sends an unfriend message. Does not remove the contact
100
101 function terminate_friendship($user,$self,$contact) {
102
103
104         $a = get_app();
105
106         require_once('include/datetime.php');
107
108         if($contact['network'] === NETWORK_OSTATUS) {
109
110                 $slap = replace_macros(get_markup_template('follow_slap.tpl'), array(
111                         '$name' => $user['username'],
112                         '$profile_page' => $a->get_baseurl() . '/profile/' . $user['nickname'],
113                         '$photo' => $self['photo'],
114                         '$thumb' => $self['thumb'],
115                         '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
116                         '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . get_guid(32),
117                         '$title' => '',
118                         '$type' => 'text',
119                         '$content' => t('stopped following'),
120                         '$nick' => $user['nickname'],
121                         '$verb' => 'http://ostatus.org/schema/1.0/unfollow', // ACTIVITY_UNFOLLOW,
122                         '$ostat_follow' => '' // '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
123                 ));
124
125                 if((x($contact,'notify')) && (strlen($contact['notify']))) {
126                         require_once('include/salmon.php');
127                         slapper($user,$contact['notify'],$slap);
128                 }
129         }
130         elseif($contact['network'] === NETWORK_DIASPORA) {
131                 require_once('include/diaspora.php');
132                 diaspora::send_unshare($user,$contact);
133         }
134         elseif($contact['network'] === NETWORK_DFRN) {
135                 require_once('include/dfrn.php');
136                 dfrn::deliver($user,$contact,'placeholder', 1);
137         }
138
139 }
140
141
142 // Contact has refused to recognise us as a friend. We will start a countdown.
143 // If they still don't recognise us in 32 days, the relationship is over,
144 // and we won't waste any more time trying to communicate with them.
145 // This provides for the possibility that their database is temporarily messed
146 // up or some other transient event and that there's a possibility we could recover from it.
147
148 if(! function_exists('mark_for_death')) {
149 function mark_for_death($contact) {
150
151         if($contact['archive'])
152                 return;
153
154         if($contact['term-date'] == '0000-00-00 00:00:00') {
155                 q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d",
156                                 dbesc(datetime_convert()),
157                                 intval($contact['id'])
158                 );
159         }
160         else {
161
162                 /// @todo 
163                 /// We really should send a notification to the owner after 2-3 weeks
164                 /// so they won't be surprised when the contact vanishes and can take
165                 /// remedial action if this was a serious mistake or glitch
166
167                 $expiry = $contact['term-date'] . ' + 32 days ';
168                 if(datetime_convert() > datetime_convert('UTC','UTC',$expiry)) {
169
170                         // relationship is really truly dead.
171                         // archive them rather than delete
172                         // though if the owner tries to unarchive them we'll start the whole process over again
173
174                         q("update contact set `archive` = 1 where id = %d",
175                                 intval($contact['id'])
176                         );
177                         q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact['id']), intval($contact['uid']));
178
179                         //contact_remove($contact['id']);
180
181                 }
182         }
183
184 }}
185
186 if(! function_exists('unmark_for_death')) {
187 function unmark_for_death($contact) {
188         // It's a miracle. Our dead contact has inexplicably come back to life.
189         q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d",
190                 dbesc('0000-00-00 00:00:00'),
191                 intval($contact['id'])
192         );
193 }}
194
195 function get_contact_details_by_url($url, $uid = -1, $default = array()) {
196         if ($uid == -1)
197                 $uid = local_user();
198
199         // community, nurl, alias, nsfw, birthday
200
201         // Fetch contact data from the contact table for the user and given network
202         $r = q("SELECT `id`, `id` AS `cid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`,
203                         `keywords`, `gender`, `photo`, `thumb`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `bd`, `bd` AS `birthday`, `self`
204                 FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `network` IN ('%s', '')",
205                         dbesc(normalise_link($url)), intval($uid), dbesc($profile["network"]));
206
207         // Is the contact present for the user in a different network? (Can happen with OStatus and the "Statusnet" addon)
208         if (!count($r) AND !isset($profile))
209                 $r = q("SELECT `id`, `id` AS `cid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`,
210                                 `keywords`, `gender`, `photo`, `thumb`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `bd`, `bd` AS `birthday`, `self`
211                         FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
212                                 dbesc(normalise_link($url)), intval($uid));
213
214         // Fetch the data from the contact table with "uid=0" (which is filled automatically)
215         if (!count($r) AND !isset($profile))
216                 $r = q("SELECT `id`, 0 AS `cid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`,
217                                 `keywords`, `gender`, `photo`, `thumb`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `bd`, `bd` AS `birthday`, 0 AS `self`
218                         FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0",
219                                 dbesc(normalise_link($url)));
220
221         // Fetch the data from the gcontact table
222         if (!count($r) AND !isset($profile))
223                 $r = q("SELECT 0 AS `id`, 0 AS `cid`, `id` AS `gid`, 0 AS `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`,
224                                 `keywords`, `gender`, `photo`, `photo` AS `thumb`, `community` AS `forum`, 0 AS `prv`, `community`, `birthday` AS `bd`, `birthday`, 0 AS `self`
225                         FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
226                                 dbesc(normalise_link($url)));
227
228         if ($r)
229                 $profile = $r[0];
230         else {
231                 $profile = $default;
232                 if (!isset($profile["thumb"]) AND isset($profile["photo"]))
233                         $profile["thumb"] = $profile["photo"];
234         }
235
236         if ((($profile["addr"] == "") OR ($profile["name"] == "")) AND ($profile["gid"] != 0) AND
237                 in_array($profile["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) {
238                 proc_run('php',"include/update_gcontact.php", $profile["gid"]);
239         }
240
241         // Show contact details of Diaspora contacts only if connected
242         if (($profile["cid"] == 0) AND ($profile["network"] == NETWORK_DIASPORA)) {
243                 $profile["location"] = "";
244                 $profile["about"] = "";
245                 $profile["gender"] = "";
246                 $profile["birthday"] = "0000-00-00";
247         }
248
249         return($profile);
250 }
251
252 if(! function_exists('contact_photo_menu')){
253 function contact_photo_menu($contact, $uid = 0) {
254
255         $a = get_app();
256
257         $contact_url="";
258         $pm_url="";
259         $status_link="";
260         $photos_link="";
261         $posts_link="";
262         $contact_drop_link = "";
263         $poke_link="";
264
265         if ($uid == 0)
266                 $uid = local_user();
267
268         if ($contact["uid"] != $uid) {
269                 if ($uid == 0) {
270                         $profile_link = zrl($contact['url']);
271                         $menu = Array('profile' => array(t("View Profile"), $profile_link, true));
272
273                         return $menu;
274                 }
275
276                 $r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `network` = '%s' AND `uid` = %d",
277                         dbesc($contact["nurl"]), dbesc($contact["network"]), intval($uid));
278                 if ($r)
279                         return contact_photo_menu($r[0], $uid);
280                 else {
281                         $profile_link = zrl($contact['url']);
282                         $connlnk = 'follow/?url='.$contact['url'];
283                         $menu = Array(
284                                 'profile' => array(t("View Profile"), $profile_link, true),
285                                 'follow' => array(t("Connect/Follow"), $connlnk, true)
286                                 );
287
288                         return $menu;
289                 }
290         }
291
292         $sparkle = false;
293         if($contact['network'] === NETWORK_DFRN) {
294                 $sparkle = true;
295                 $profile_link = $a->get_baseurl() . '/redir/' . $contact['id'];
296         }
297         else
298                 $profile_link = $contact['url'];
299
300         if($profile_link === 'mailbox')
301                 $profile_link = '';
302
303         if($sparkle) {
304                 $status_link = $profile_link . "?url=status";
305                 $photos_link = $profile_link . "?url=photos";
306                 $profile_link = $profile_link . "?url=profile";
307         }
308
309         if (in_array($contact["network"], array(NETWORK_DFRN, NETWORK_DIASPORA)))
310                 $pm_url = $a->get_baseurl() . '/message/new/' . $contact['id'];
311
312         if ($contact["network"] == NETWORK_DFRN)
313                 $poke_link = $a->get_baseurl() . '/poke/?f=&c=' . $contact['id'];
314
315         $contact_url = $a->get_baseurl() . '/contacts/' . $contact['id'];
316         $posts_link = $a->get_baseurl() . "/contacts/" . $contact['id'] . '/posts';
317         $contact_drop_link = $a->get_baseurl() . "/contacts/" . $contact['id'] . '/drop?confirm=1';
318
319
320         /**
321          * menu array:
322          * "name" => [ "Label", "link", (bool)Should the link opened in a new tab? ]
323          */
324         $menu = Array(
325                 'status' => array(t("View Status"), $status_link, true),
326                 'profile' => array(t("View Profile"), $profile_link, true),
327                 'photos' => array(t("View Photos"), $photos_link,true),
328                 'network' => array(t("Network Posts"), $posts_link,false),
329                 'edit' => array(t("Edit Contact"), $contact_url, false),
330                 'drop' => array(t("Drop Contact"), $contact_drop_link, false),
331                 'pm' => array(t("Send PM"), $pm_url, false),
332                 'poke' => array(t("Poke"), $poke_link, false),
333         );
334
335
336         $args = array('contact' => $contact, 'menu' => &$menu);
337
338         call_hooks('contact_photo_menu', $args);
339
340         $menucondensed = array();
341
342         foreach ($menu AS $menuname=>$menuitem)
343                 if ($menuitem[1] != "")
344                         $menucondensed[$menuname] = $menuitem;
345
346         return $menucondensed;
347 }}
348
349
350 function random_profile() {
351         $r = q("SELECT `url` FROM `gcontact` WHERE `network` = '%s'
352                                 AND `last_contact` >= `last_failure`
353                                 AND `updated` > UTC_TIMESTAMP - INTERVAL 1 MONTH
354                         ORDER BY rand() LIMIT 1",
355                 dbesc(NETWORK_DFRN));
356
357         if(count($r))
358                 return dirname($r[0]['url']);
359         return '';
360 }
361
362
363 function contacts_not_grouped($uid,$start = 0,$count = 0) {
364
365         if(! $count) {
366                 $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) ",
367                         intval($uid),
368                         intval($uid)
369                 );
370
371                 return $r;
372
373
374         }
375
376         $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",
377                 intval($uid),
378                 intval($uid),
379                 intval($start),
380                 intval($count)
381         );
382
383         return $r;
384 }
385
386 function get_contact($url, $uid = 0) {
387         require_once("include/Scrape.php");
388
389         $data = array();
390         $contactid = 0;
391
392         // is it an address in the format user@server.tld?
393         /// @todo use gcontact and/or the addr field for a lookup
394         if (!strstr($url, "http") OR strstr($url, "@")) {
395                 $data = probe_url($url);
396                 $url = $data["url"];
397                 if ($url == "")
398                         return 0;
399         }
400
401         $contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d ORDER BY `id` LIMIT 2",
402                         dbesc(normalise_link($url)),
403                         intval($uid));
404
405         if (!$contact)
406                 $contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `alias` IN ('%s', '%s') AND `uid` = %d ORDER BY `id` LIMIT 1",
407                                 dbesc($url),
408                                 dbesc(normalise_link($url)),
409                                 intval($uid));
410
411         if ($contact) {
412                 $contactid = $contact[0]["id"];
413
414                 // Update the contact every 7 days
415                 $update_photo = ($contact[0]['avatar-date'] < datetime_convert('','','now -7 days'));
416                 //$update_photo = ($contact[0]['avatar-date'] < datetime_convert('','','now -12 hours'));
417
418                 if (!$update_photo)
419                         return($contactid);
420         } elseif ($uid != 0)
421                 return 0;
422
423         if (!count($data))
424                 $data = probe_url($url);
425
426         // Does this address belongs to a valid network?
427         if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
428                 return 0;
429
430         $url = $data["url"];
431
432         if ($contactid == 0) {
433                 q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`,
434                                         `name`, `nick`, `photo`, `network`, `pubkey`, `rel`, `priority`,
435                                         `batch`, `request`, `confirm`, `poco`,
436                                         `writable`, `blocked`, `readonly`, `pending`)
437                                         VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', '%s', 1, 0, 0, 0)",
438                         intval($uid),
439                         dbesc(datetime_convert()),
440                         dbesc($data["url"]),
441                         dbesc(normalise_link($data["url"])),
442                         dbesc($data["addr"]),
443                         dbesc($data["alias"]),
444                         dbesc($data["notify"]),
445                         dbesc($data["poll"]),
446                         dbesc($data["name"]),
447                         dbesc($data["nick"]),
448                         dbesc($data["photo"]),
449                         dbesc($data["network"]),
450                         dbesc($data["pubkey"]),
451                         intval(CONTACT_IS_SHARING),
452                         intval($data["priority"]),
453                         dbesc($data["batch"]),
454                         dbesc($data["request"]),
455                         dbesc($data["confirm"]),
456                         dbesc($data["poco"])
457                 );
458
459                 $contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d ORDER BY `id` LIMIT 2",
460                                 dbesc(normalise_link($data["url"])),
461                                 intval($uid));
462                 if (!$contact)
463                         return 0;
464
465                 $contactid = $contact[0]["id"];
466         }
467
468         if ((count($contact) > 1) AND ($uid == 0) AND ($contactid != 0) AND ($url != ""))
469                 q("DELETE FROM `contact` WHERE `nurl` = '%s' AND `id` != %d",
470                         dbesc(normalise_link($url)),
471                         intval($contactid));
472
473         require_once("Photo.php");
474
475         update_contact_avatar($data["photo"],$uid,$contactid);
476
477         q("UPDATE `contact` SET `addr` = '%s', `alias` = '%s', `name` = '%s', `nick` = '%s',
478                 `name-date` = '%s', `uri-date` = '%s' WHERE `id` = %d",
479                 dbesc($data["addr"]),
480                 dbesc($data["alias"]),
481                 dbesc($data["name"]),
482                 dbesc($data["nick"]),
483                 dbesc(datetime_convert()),
484                 dbesc(datetime_convert()),
485                 intval($contactid)
486         );
487
488         return $contactid;
489 }
490
491 /**
492  * @brief Returns posts from a given gcontact
493  *
494  * @param App $a argv application class
495  * @param int $gcontact_id Global contact
496  *
497  * @return string posts in HTML
498  */
499 function posts_from_gcontact($a, $gcontact_id) {
500
501         require_once('include/conversation.php');
502
503         // There are no posts with "uid = 0" with connector networks
504         // This speeds up the query a lot
505         $r = q("SELECT `network` FROM `gcontact` WHERE `id` = %d", dbesc($gcontact_id));
506         if (in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, "")))
507                 $sql = "(`item`.`uid` = 0 OR  (`item`.`uid` = %d AND `item`.`private`))";
508         else
509                 $sql = "`item`.`uid` = %d";
510
511         if(get_config('system', 'old_pager')) {
512                 $r = q("SELECT COUNT(*) AS `total` FROM `item`
513                         WHERE `gcontact-id` = %d and $sql",
514                         intval($gcontact_id),
515                         intval(local_user()));
516
517                 $a->set_pager_total($r[0]['total']);
518         }
519
520         $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
521                         `author-name` AS `name`, `owner-avatar` AS `photo`,
522                         `owner-link` AS `url`, `owner-avatar` AS `thumb`
523                 FROM `item` FORCE INDEX (`gcontactid_uid_created`)
524                 WHERE `gcontact-id` = %d AND $sql AND
525                         NOT `deleted` AND NOT `moderated` AND `visible`
526                 ORDER BY `item`.`created` DESC LIMIT %d, %d",
527                 intval($gcontact_id),
528                 intval(local_user()),
529                 intval($a->pager['start']),
530                 intval($a->pager['itemspage'])
531         );
532
533         $o = conversation($a,$r,'community',false);
534
535         if(!get_config('system', 'old_pager')) {
536                 $o .= alt_pager($a,count($r));
537         } else {
538                 $o .= paginate($a);
539         }
540
541         return $o;
542 }
543
544 /**
545  * @brief Returns posts from a given contact
546  *
547  * @param App $a argv application class
548  * @param int $contact_id contact
549  *
550  * @return string posts in HTML
551  */
552 function posts_from_contact($a, $contact_id) {
553
554         require_once('include/conversation.php');
555
556         $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", intval($contact_id));
557         if (!$r)
558                 return false;
559
560         $contact = $r[0];
561
562         if(get_config('system', 'old_pager')) {
563                 $r = q("SELECT COUNT(*) AS `total` FROM `item`
564                         WHERE `item`.`uid` = %d AND `author-link` IN ('%s', '%s')",
565                         intval(local_user()),
566                         dbesc(str_replace("https://", "http://", $contact["url"])),
567                         dbesc(str_replace("http://", "https://", $contact["url"])));
568
569                 $a->set_pager_total($r[0]['total']);
570         }
571
572         $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
573                         `author-name` AS `name`, `owner-avatar` AS `photo`,
574                         `owner-link` AS `url`, `owner-avatar` AS `thumb`
575                 FROM `item` FORCE INDEX (`uid_contactid_created`)
576                 WHERE `item`.`uid` = %d AND `contact-id` = %d
577                         AND `author-link` IN ('%s', '%s')
578                         AND NOT `deleted` AND NOT `moderated` AND `visible`
579                 ORDER BY `item`.`created` DESC LIMIT %d, %d",
580                 intval(local_user()),
581                 intval($contact_id),
582                 dbesc(str_replace("https://", "http://", $contact["url"])),
583                 dbesc(str_replace("http://", "https://", $contact["url"])),
584                 intval($a->pager['start']),
585                 intval($a->pager['itemspage'])
586         );
587
588         $o .= conversation($a,$r,'community',false);
589
590         if(!get_config('system', 'old_pager'))
591                 $o .= alt_pager($a,count($r));
592         else
593                 $o .= paginate($a);
594
595         return $o;
596 }
597
598 /**
599  * @brief Returns a formatted location string from the given profile array
600  *
601  * @param array $profile Profile array (Generated from the "profile" table)
602  *
603  * @return string Location string
604  */
605 function formatted_location($profile) {
606         $location = '';
607
608         if($profile['locality'])
609                 $location .= $profile['locality'];
610
611         if($profile['region'] AND ($profile['locality'] != $profile['region'])) {
612                 if($location)
613                         $location .= ', ';
614
615                 $location .= $profile['region'];
616         }
617
618         if($profile['country-name']) {
619                 if($location)
620                         $location .= ', ';
621
622                 $location .= $profile['country-name'];
623         }
624
625         return $location;
626 }
627 ?>