3 * @file src/Core/NotificationsManager.php
4 * @brief Methods for read and write notifications from/to database
5 * or for formatting notifications
7 namespace Friendica\Core;
9 use Friendica\BaseObject;
10 use Friendica\Content\Text\BBCode;
11 use Friendica\Core\L10n;
12 use Friendica\Core\PConfig;
13 use Friendica\Core\System;
14 use Friendica\Database\DBM;
15 use Friendica\Model\Contact;
16 use Friendica\Model\Profile;
17 use Friendica\Util\DateTimeFormat;
18 use Friendica\Util\Temporal;
19 use Friendica\Util\XML;
21 require_once 'include/dba.php';
22 require_once 'include/html2plain.php';
25 * @brief Methods for read and write notifications from/to database
26 * or for formatting notifications
28 class NotificationsManager extends BaseObject
31 * @brief set some extra note properties
33 * @param array $notes array of note arrays from db
34 * @return array Copy of input array with added properties
36 * Set some extra properties to note array from db:
37 * - timestamp as int in default TZ
38 * - date_rel : relative date string
39 * - msg_html: message as html string
40 * - msg_plain: message as plain text string
42 private function _set_extra($notes)
45 foreach ($notes as $n) {
46 $local_time = DateTimeFormat::local($n['date']);
47 $n['timestamp'] = strtotime($local_time);
48 $n['date_rel'] = Temporal::getRelativeDate($n['date']);
49 $n['msg_html'] = BBCode::convert($n['msg'], false);
50 $n['msg_plain'] = explode("\n", trim(html2plain($n['msg_html'], 0)))[0];
58 * @brief Get all notifications for local_user()
60 * @param array $filter optional Array "column name"=>value: filter query by columns values
61 * @param string $order optional Space separated list of column to sort by.
62 * Prepend name with "+" to sort ASC, "-" to sort DESC. Default to "-date"
63 * @param string $limit optional Query limits
65 * @return array of results or false on errors
67 public function getAll($filter = [], $order = "-date", $limit = "")
71 foreach ($filter as $column => $value) {
72 $filter_str[] = sprintf("`%s` = '%s'", $column, dbesc($value));
74 if (count($filter_str) > 0) {
75 $filter_sql = "AND " . implode(" AND ", $filter_str);
78 $aOrder = explode(" ", $order);
80 foreach ($aOrder as $o) {
90 $asOrder[] = "$o $dir";
92 $order_sql = implode(", ", $asOrder);
95 $limit = " LIMIT " . $limit;
98 "SELECT * FROM `notify` WHERE `uid` = %d $filter_sql ORDER BY $order_sql $limit",
102 if (DBM::is_result($r)) {
103 return $this->_set_extra($r);
110 * @brief Get one note for local_user() by $id value
112 * @param int $id identity
113 * @return array note values or null if not found
115 public function getByID($id)
118 "SELECT * FROM `notify` WHERE `id` = %d AND `uid` = %d LIMIT 1",
122 if (DBM::is_result($r)) {
123 return $this->_set_extra($r)[0];
129 * @brief set seen state of $note of local_user()
131 * @param array $note note array
132 * @param bool $seen optional true or false, default true
133 * @return bool true on success, false on errors
135 public function setSeen($note, $seen = true)
138 "UPDATE `notify` SET `seen` = %d WHERE (`link` = '%s' OR (`parent` != 0 AND `parent` = %d AND `otype` = '%s')) AND `uid` = %d",
140 dbesc($note['link']),
141 intval($note['parent']),
142 dbesc($note['otype']),
148 * @brief set seen state of all notifications of local_user()
150 * @param bool $seen optional true or false. default true
151 * @return bool true on success, false on error
153 public function setAllSeen($seen = true)
156 "UPDATE `notify` SET `seen` = %d WHERE `uid` = %d",
163 * @brief List of pages for the Notifications TabBar
165 * @return array with with notifications TabBar data
167 public function getTabs()
171 'label' => L10n::t('System'),
172 'url' => 'notifications/system',
173 'sel' => ((self::getApp()->argv[1] == 'system') ? 'active' : ''),
174 'id' => 'system-tab',
178 'label' => L10n::t('Network'),
179 'url' => 'notifications/network',
180 'sel' => ((self::getApp()->argv[1] == 'network') ? 'active' : ''),
181 'id' => 'network-tab',
185 'label' => L10n::t('Personal'),
186 'url' => 'notifications/personal',
187 'sel' => ((self::getApp()->argv[1] == 'personal') ? 'active' : ''),
188 'id' => 'personal-tab',
192 'label' => L10n::t('Home'),
193 'url' => 'notifications/home',
194 'sel' => ((self::getApp()->argv[1] == 'home') ? 'active' : ''),
199 'label' => L10n::t('Introductions'),
200 'url' => 'notifications/intros',
201 'sel' => ((self::getApp()->argv[1] == 'intros') ? 'active' : ''),
211 * @brief Format the notification query in an usable array
213 * @param array $notifs The array from the db query
214 * @param string $ident The notifications identifier (e.g. network)
216 * string 'label' => The type of the notification
217 * string 'link' => URL to the source
218 * string 'image' => The avatar image
219 * string 'url' => The profile url of the contact
220 * string 'text' => The notification text
221 * string 'when' => The date of the notification
222 * string 'ago' => T relative date of the notification
223 * bool 'seen' => Is the notification marked as "seen"
225 private function formatNotifs($notifs, $ident = "")
230 if (DBM::is_result($notifs)) {
231 foreach ($notifs as $it) {
232 // Because we use different db tables for the notification query
233 // we have sometimes $it['unseen'] and sometimes $it['seen].
234 // So we will have to transform $it['unseen']
235 if (array_key_exists('unseen', $it)) {
236 $it['seen'] = ($it['unseen'] > 0 ? false : true);
239 // Depending on the identifier of the notification we need to use different defaults
242 $default_item_label = 'notify';
243 $default_item_link = System::baseUrl(true) . '/notify/view/' . $it['id'];
244 $default_item_image = proxy_url($it['photo'], false, PROXY_SIZE_MICRO);
245 $default_item_url = $it['url'];
246 $default_item_text = strip_tags(BBCode::convert($it['msg']));
247 $default_item_when = DateTimeFormat::local($it['date'], 'r');
248 $default_item_ago = Temporal::getRelativeDate($it['date']);
252 $default_item_label = 'comment';
253 $default_item_link = System::baseUrl(true) . '/display/' . $it['pguid'];
254 $default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO);
255 $default_item_url = $it['author-link'];
256 $default_item_text = L10n::t("%s commented on %s's post", $it['author-name'], $it['pname']);
257 $default_item_when = DateTimeFormat::local($it['created'], 'r');
258 $default_item_ago = Temporal::getRelativeDate($it['created']);
262 $default_item_label = (($it['id'] == $it['parent']) ? 'post' : 'comment');
263 $default_item_link = System::baseUrl(true) . '/display/' . $it['pguid'];
264 $default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO);
265 $default_item_url = $it['author-link'];
266 $default_item_text = (($it['id'] == $it['parent'])
267 ? L10n::t("%s created a new post", $it['author-name'])
268 : L10n::t("%s commented on %s's post", $it['author-name'], $it['pname']));
269 $default_item_when = DateTimeFormat::local($it['created'], 'r');
270 $default_item_ago = Temporal::getRelativeDate($it['created']);
273 // Transform the different types of notification in an usable array
274 switch ($it['verb']) {
278 'link' => System::baseUrl(true) . '/display/' . $it['pguid'],
279 'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
280 'url' => $it['author-link'],
281 'text' => L10n::t("%s liked %s's post", $it['author-name'], $it['pname']),
282 'when' => $default_item_when,
283 'ago' => $default_item_ago,
284 'seen' => $it['seen']
288 case ACTIVITY_DISLIKE:
290 'label' => 'dislike',
291 'link' => System::baseUrl(true) . '/display/' . $it['pguid'],
292 'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
293 'url' => $it['author-link'],
294 'text' => L10n::t("%s disliked %s's post", $it['author-name'], $it['pname']),
295 'when' => $default_item_when,
296 'ago' => $default_item_ago,
297 'seen' => $it['seen']
301 case ACTIVITY_ATTEND:
304 'link' => System::baseUrl(true) . '/display/' . $it['pguid'],
305 'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
306 'url' => $it['author-link'],
307 'text' => L10n::t("%s is attending %s's event", $it['author-name'], $it['pname']),
308 'when' => $default_item_when,
309 'ago' => $default_item_ago,
310 'seen' => $it['seen']
314 case ACTIVITY_ATTENDNO:
316 'label' => 'attendno',
317 'link' => System::baseUrl(true) . '/display/' . $it['pguid'],
318 'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
319 'url' => $it['author-link'],
320 'text' => L10n::t("%s is not attending %s's event", $it['author-name'], $it['pname']),
321 'when' => $default_item_when,
322 'ago' => $default_item_ago,
323 'seen' => $it['seen']
327 case ACTIVITY_ATTENDMAYBE:
329 'label' => 'attendmaybe',
330 'link' => System::baseUrl(true) . '/display/' . $it['pguid'],
331 'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
332 'url' => $it['author-link'],
333 'text' => L10n::t("%s may attend %s's event", $it['author-name'], $it['pname']),
334 'when' => $default_item_when,
335 'ago' => $default_item_ago,
336 'seen' => $it['seen']
340 case ACTIVITY_FRIEND:
341 $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
342 $obj = XML::parseString($xmlhead . $it['object']);
343 $it['fname'] = $obj->title;
347 'link' => System::baseUrl(true) . '/display/' . $it['pguid'],
348 'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
349 'url' => $it['author-link'],
350 'text' => L10n::t("%s is now friends with %s", $it['author-name'], $it['fname']),
351 'when' => $default_item_when,
352 'ago' => $default_item_ago,
353 'seen' => $it['seen']
359 'label' => $default_item_label,
360 'link' => $default_item_link,
361 'image' => $default_item_image,
362 'url' => $default_item_url,
363 'text' => $default_item_text,
364 'when' => $default_item_when,
365 'ago' => $default_item_ago,
366 'seen' => $it['seen']
378 * @brief Total number of network notifications
379 * @param int|string $seen If 0 only include notifications into the query
380 * which aren't marked as "seen"
382 * @return int Number of network notifications
384 private function networkTotal($seen = 0)
390 $sql_seen = " AND `item`.`unseen` ";
391 $index_hint = "USE INDEX (`uid_unseen_contactid`)";
395 "SELECT COUNT(*) AS `total`
396 FROM `item` $index_hint STRAIGHT_JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
397 WHERE `item`.`visible` AND `pitem`.`parent` != 0 AND
398 NOT `item`.`deleted` AND `item`.`uid` = %d AND NOT `item`.`wall`
402 if (DBM::is_result($r)) {
403 return $r[0]['total'];
410 * @brief Get network notifications
412 * @param int|string $seen If 0 only include notifications into the query
413 * which aren't marked as "seen"
414 * @param int $start Start the query at this point
415 * @param int $limit Maximum number of query results
418 * string 'ident' => Notification identifier
419 * int 'total' => Total number of available network notifications
420 * array 'notifications' => Network notifications
422 public function networkNotifs($seen = 0, $start = 0, $limit = 80)
425 $total = $this->networkTotal($seen);
431 $sql_seen = " AND `item`.`unseen` ";
432 $index_hint = "USE INDEX (`uid_unseen_contactid`)";
436 "SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`,
437 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`,
438 `pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`, `pitem`.`guid` AS `pguid`
439 FROM `item` $index_hint STRAIGHT_JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
440 WHERE `item`.`visible` AND `pitem`.`parent` != 0 AND
441 NOT `item`.`deleted` AND `item`.`uid` = %d AND NOT `item`.`wall`
443 ORDER BY `item`.`created` DESC LIMIT %d, %d ",
444 intval(local_user()),
448 if (DBM::is_result($r)) {
449 $notifs = $this->formatNotifs($r, $ident);
453 'notifications' => $notifs,
462 * @brief Total number of system notifications
463 * @param int|string $seen If 0 only include notifications into the query
464 * which aren't marked as "seen"
466 * @return int Number of system notifications
468 private function systemTotal($seen = 0)
473 $sql_seen = " AND NOT `seen` ";
477 "SELECT COUNT(*) AS `total` FROM `notify` WHERE `uid` = %d $sql_seen",
480 if (DBM::is_result($r)) {
481 return $r[0]['total'];
488 * @brief Get system notifications
490 * @param int|string $seen If 0 only include notifications into the query
491 * which aren't marked as "seen"
492 * @param int $start Start the query at this point
493 * @param int $limit Maximum number of query results
496 * string 'ident' => Notification identifier
497 * int 'total' => Total number of available system notifications
498 * array 'notifications' => System notifications
500 public function systemNotifs($seen = 0, $start = 0, $limit = 80)
503 $total = $this->systemTotal($seen);
508 $sql_seen = " AND NOT `seen` ";
512 "SELECT `id`, `url`, `photo`, `msg`, `date`, `seen` FROM `notify`
513 WHERE `uid` = %d $sql_seen ORDER BY `date` DESC LIMIT %d, %d ",
514 intval(local_user()),
518 if (DBM::is_result($r)) {
519 $notifs = $this->formatNotifs($r, $ident);
523 'notifications' => $notifs,
532 * @brief Additional SQL query string for the personal notifications
534 * @return string The additional SQL query
536 private function personalSqlExtra()
538 $myurl = System::baseUrl(true) . '/profile/' . self::getApp()->user['nickname'];
539 $myurl = substr($myurl, strpos($myurl, '://') + 3);
540 $myurl = str_replace(['www.', '.'], ['', '\\.'], $myurl);
541 $diasp_url = str_replace('/profile/', '/u/', $myurl);
542 $sql_extra = sprintf(
543 " AND (`item`.`author-link` REGEXP '%s' OR `item`.`tag` REGEXP '%s' OR `item`.`tag` REGEXP '%s') ",
545 dbesc($myurl . '\\]'),
546 dbesc($diasp_url . '\\]')
553 * @brief Total number of personal notifications
554 * @param int|string $seen If 0 only include notifications into the query
555 * which aren't marked as "seen"
557 * @return int Number of personal notifications
559 private function personalTotal($seen = 0)
563 $sql_extra = $this->personalSqlExtra();
566 $sql_seen = " AND `item`.`unseen` ";
567 $index_hint = "USE INDEX (`uid_unseen_contactid`)";
571 "SELECT COUNT(*) AS `total`
572 FROM `item` $index_hint
573 WHERE `item`.`visible`
576 AND NOT `item`.`deleted` AND `item`.`uid` = %d AND NOT `item`.`wall`",
579 if (DBM::is_result($r)) {
580 return $r[0]['total'];
587 * @brief Get personal notifications
589 * @param int|string $seen If 0 only include notifications into the query
590 * which aren't marked as "seen"
591 * @param int $start Start the query at this point
592 * @param int $limit Maximum number of query results
595 * string 'ident' => Notification identifier
596 * int 'total' => Total number of available personal notifications
597 * array 'notifications' => Personal notifications
599 public function personalNotifs($seen = 0, $start = 0, $limit = 80)
602 $total = $this->personalTotal($seen);
603 $sql_extra = $this->personalSqlExtra();
609 $sql_seen = " AND `item`.`unseen` ";
610 $index_hint = "USE INDEX (`uid_unseen_contactid`)";
614 "SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`,
615 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`,
616 `pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`, `pitem`.`guid` AS `pguid`
617 FROM `item` $index_hint STRAIGHT_JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
618 WHERE `item`.`visible`
621 AND NOT `item`.`deleted` AND `item`.`uid` = %d AND NOT `item`.`wall`
622 ORDER BY `item`.`created` DESC LIMIT %d, %d ",
623 intval(local_user()),
627 if (DBM::is_result($r)) {
628 $notifs = $this->formatNotifs($r, $ident);
632 'notifications' => $notifs,
641 * @brief Total number of home notifications
642 * @param int|string $seen If 0 only include notifications into the query
643 * which aren't marked as "seen"
645 * @return int Number of home notifications
647 private function homeTotal($seen = 0)
653 $sql_seen = " AND `item`.`unseen` ";
654 $index_hint = "USE INDEX (`uid_unseen_contactid`)";
658 "SELECT COUNT(*) AS `total` FROM `item` $index_hint
659 WHERE `item`.`visible` = 1 AND
660 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1
664 if (DBM::is_result($r)) {
665 return $r[0]['total'];
672 * @brief Get home notifications
674 * @param int|string $seen If 0 only include notifications into the query
675 * which aren't marked as "seen"
676 * @param int $start Start the query at this point
677 * @param int $limit Maximum number of query results
680 * string 'ident' => Notification identifier
681 * int 'total' => Total number of available home notifications
682 * array 'notifications' => Home notifications
684 public function homeNotifs($seen = 0, $start = 0, $limit = 80)
687 $total = $this->homeTotal($seen);
693 $sql_seen = " AND `item`.`unseen` ";
694 $index_hint = "USE INDEX (`uid_unseen_contactid`)";
698 "SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`,
699 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`,
700 `pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`, `pitem`.`guid` AS `pguid`
701 FROM `item` $index_hint STRAIGHT_JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
702 WHERE `item`.`visible` AND
703 NOT `item`.`deleted` AND `item`.`uid` = %d AND `item`.`wall`
705 ORDER BY `item`.`created` DESC LIMIT %d, %d ",
706 intval(local_user()),
710 if (DBM::is_result($r)) {
711 $notifs = $this->formatNotifs($r, $ident);
715 'notifications' => $notifs,
724 * @brief Total number of introductions
725 * @param bool $all If false only include introductions into the query
726 * which aren't marked as ignored
728 * @return int Number of introductions
730 private function introTotal($all = false)
735 $sql_extra = " AND `ignore` = 0 ";
739 "SELECT COUNT(*) AS `total` FROM `intro`
740 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
741 intval($_SESSION['uid'])
744 if (DBM::is_result($r)) {
745 return $r[0]['total'];
752 * @brief Get introductions
754 * @param bool $all If false only include introductions into the query
755 * which aren't marked as ignored
756 * @param int $start Start the query at this point
757 * @param int $limit Maximum number of query results
760 * string 'ident' => Notification identifier
761 * int 'total' => Total number of available introductions
762 * array 'notifications' => Introductions
764 public function introNotifs($all = false, $start = 0, $limit = 80)
766 $ident = 'introductions';
767 $total = $this->introTotal($all);
772 $sql_extra = " AND `ignore` = 0 ";
775 /// @todo Fetch contact details by "Contact::getDetailsByUrl" instead of queries to contact, fcontact and gcontact
777 "SELECT `intro`.`id` AS `intro_id`, `intro`.*, `contact`.*,
778 `fcontact`.`name` AS `fname`, `fcontact`.`url` AS `furl`,
779 `fcontact`.`photo` AS `fphoto`, `fcontact`.`request` AS `frequest`,
780 `gcontact`.`location` AS `glocation`, `gcontact`.`about` AS `gabout`,
781 `gcontact`.`keywords` AS `gkeywords`, `gcontact`.`gender` AS `ggender`,
782 `gcontact`.`network` AS `gnetwork`, `gcontact`.`addr` AS `gaddr`
784 LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id`
785 LEFT JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
786 LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
787 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0
789 intval($_SESSION['uid']),
793 if (DBM::is_result($r)) {
794 $notifs = $this->formatIntros($r);
800 'notifications' => $notifs,
807 * @brief Format the notification query in an usable array
809 * @param array $intros The array from the db query
810 * @return array with the introductions
812 private function formatIntros($intros)
816 foreach ($intros as $it) {
817 // There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
818 // We have to distinguish between these two because they use different data.
819 // Contact suggestions
821 $return_addr = bin2hex(self::getApp()->user['nickname'] . '@' . self::getApp()->get_hostname() . ((self::getApp()->path) ? '/' . self::getApp()->path : ''));
824 'label' => 'friend_suggestion',
825 'notify_type' => L10n::t('Friend Suggestion'),
826 'intro_id' => $it['intro_id'],
827 'madeby' => $it['name'],
828 'contact_id' => $it['contact-id'],
829 'photo' => ((x($it, 'fphoto')) ? proxy_url($it['fphoto'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"),
830 'name' => $it['fname'],
831 'url' => Profile::zrl($it['furl']),
832 'hidden' => $it['hidden'] == 1,
833 'post_newfriend' => (intval(PConfig::get(local_user(), 'system', 'post_newfriend')) ? '1' : 0),
834 'knowyou' => $knowyou,
835 'note' => $it['note'],
836 'request' => $it['frequest'] . '?addr=' . $return_addr,
839 // Normal connection requests
841 $it = $this->getMissingIntroData($it);
843 // Don't show these data until you are connected. Diaspora is doing the same.
844 if ($it['gnetwork'] === NETWORK_DIASPORA) {
845 $it['glocation'] = "";
850 'label' => (($it['network'] !== NETWORK_OSTATUS) ? 'friend_request' : 'follower'),
851 'notify_type' => (($it['network'] !== NETWORK_OSTATUS) ? L10n::t('Friend/Connect Request') : L10n::t('New Follower')),
852 'dfrn_id' => $it['issued-id'],
853 'uid' => $_SESSION['uid'],
854 'intro_id' => $it['intro_id'],
855 'contact_id' => $it['contact-id'],
856 'photo' => ((x($it, 'photo')) ? proxy_url($it['photo'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"),
857 'name' => $it['name'],
858 'location' => BBCode::convert($it['glocation'], false),
859 'about' => BBCode::convert($it['gabout'], false),
860 'keywords' => $it['gkeywords'],
861 'gender' => $it['ggender'],
862 'hidden' => $it['hidden'] == 1,
863 'post_newfriend' => (intval(PConfig::get(local_user(), 'system', 'post_newfriend')) ? '1' : 0),
865 'zrl' => Profile::zrl($it['url']),
866 'addr' => $it['gaddr'],
867 'network' => $it['gnetwork'],
868 'knowyou' => $it['knowyou'],
869 'note' => $it['note'],
880 * @brief Check for missing contact data and try to fetch the data from
883 * @param array $arr The input array with the intro data
885 * @return array The array with the intro data
887 private function getMissingIntroData($arr)
889 // If the network and the addr isn't available from the gcontact
890 // table entry, take the one of the contact table entry
891 if ($arr['gnetwork'] == "") {
892 $arr['gnetwork'] = $arr['network'];
894 if ($arr['gaddr'] == "") {
895 $arr['gaddr'] = $arr['addr'];
898 // If the network and addr is still not available
899 // get the missing data data from other sources
900 if ($arr['gnetwork'] == "" || $arr['gaddr'] == "") {
901 $ret = Contact::getDetailsByURL($arr['url']);
903 if ($arr['gnetwork'] == "" && $ret['network'] != "") {
904 $arr['gnetwork'] = $ret['network'];
906 if ($arr['gaddr'] == "" && $ret['addr'] != "") {
907 $arr['gaddr'] = $ret['addr'];