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)
389 $sql_seen = " AND `item`.`unseen` = 1 ";
393 "SELECT COUNT(*) AS `total`
394 FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
395 WHERE `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND
396 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0
400 if (DBM::is_result($r)) {
401 return $r[0]['total'];
408 * @brief Get network notifications
410 * @param int|string $seen If 0 only include notifications into the query
411 * which aren't marked as "seen"
412 * @param int $start Start the query at this point
413 * @param int $limit Maximum number of query results
416 * string 'ident' => Notification identifier
417 * int 'total' => Total number of available network notifications
418 * array 'notifications' => Network notifications
420 public function networkNotifs($seen = 0, $start = 0, $limit = 80)
423 $total = $this->networkTotal($seen);
428 $sql_seen = " AND `item`.`unseen` = 1 ";
432 "SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`,
433 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`,
434 `pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`, `pitem`.`guid` AS `pguid`
435 FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
436 WHERE `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND
437 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0
439 ORDER BY `item`.`created` DESC LIMIT %d, %d ",
440 intval(local_user()),
444 if (DBM::is_result($r)) {
445 $notifs = $this->formatNotifs($r, $ident);
449 'notifications' => $notifs,
458 * @brief Total number of system notifications
459 * @param int|string $seen If 0 only include notifications into the query
460 * which aren't marked as "seen"
462 * @return int Number of system notifications
464 private function systemTotal($seen = 0)
469 $sql_seen = " AND `seen` = 0 ";
473 "SELECT COUNT(*) AS `total` FROM `notify` WHERE `uid` = %d $sql_seen",
476 if (DBM::is_result($r)) {
477 return $r[0]['total'];
484 * @brief Get system notifications
486 * @param int|string $seen If 0 only include notifications into the query
487 * which aren't marked as "seen"
488 * @param int $start Start the query at this point
489 * @param int $limit Maximum number of query results
492 * string 'ident' => Notification identifier
493 * int 'total' => Total number of available system notifications
494 * array 'notifications' => System notifications
496 public function systemNotifs($seen = 0, $start = 0, $limit = 80)
499 $total = $this->systemTotal($seen);
504 $sql_seen = " AND `seen` = 0 ";
508 "SELECT `id`, `url`, `photo`, `msg`, `date`, `seen` FROM `notify`
509 WHERE `uid` = %d $sql_seen ORDER BY `date` DESC LIMIT %d, %d ",
510 intval(local_user()),
514 if (DBM::is_result($r)) {
515 $notifs = $this->formatNotifs($r, $ident);
519 'notifications' => $notifs,
528 * @brief Additional SQL query string for the personal notifications
530 * @return string The additional SQL query
532 private function personalSqlExtra()
534 $myurl = System::baseUrl(true) . '/profile/' . self::getApp()->user['nickname'];
535 $myurl = substr($myurl, strpos($myurl, '://') + 3);
536 $myurl = str_replace(['www.', '.'], ['', '\\.'], $myurl);
537 $diasp_url = str_replace('/profile/', '/u/', $myurl);
538 $sql_extra = sprintf(
539 " AND ( `item`.`author-link` regexp '%s' OR `item`.`tag` regexp '%s' OR `item`.`tag` regexp '%s' ) ",
541 dbesc($myurl . '\\]'),
542 dbesc($diasp_url . '\\]')
549 * @brief Total number of personal notifications
550 * @param int|string $seen If 0 only include notifications into the query
551 * which aren't marked as "seen"
553 * @return int Number of personal notifications
555 private function personalTotal($seen = 0)
558 $sql_extra = $this->personalSqlExtra();
561 $sql_seen = " AND `item`.`unseen` = 1 ";
565 "SELECT COUNT(*) AS `total`
566 FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
567 WHERE `item`.`visible` = 1
570 AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ",
573 if (DBM::is_result($r)) {
574 return $r[0]['total'];
581 * @brief Get personal notifications
583 * @param int|string $seen If 0 only include notifications into the query
584 * which aren't marked as "seen"
585 * @param int $start Start the query at this point
586 * @param int $limit Maximum number of query results
589 * string 'ident' => Notification identifier
590 * int 'total' => Total number of available personal notifications
591 * array 'notifications' => Personal notifications
593 public function personalNotifs($seen = 0, $start = 0, $limit = 80)
596 $total = $this->personalTotal($seen);
597 $sql_extra = $this->personalSqlExtra();
602 $sql_seen = " AND `item`.`unseen` = 1 ";
606 "SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`,
607 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`,
608 `pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`, `pitem`.`guid` AS `pguid`
609 FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
610 WHERE `item`.`visible` = 1
613 AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0
614 ORDER BY `item`.`created` DESC LIMIT %d, %d ",
615 intval(local_user()),
619 if (DBM::is_result($r)) {
620 $notifs = $this->formatNotifs($r, $ident);
624 'notifications' => $notifs,
633 * @brief Total number of home notifications
634 * @param int|string $seen If 0 only include notifications into the query
635 * which aren't marked as "seen"
637 * @return int Number of home notifications
639 private function homeTotal($seen = 0)
644 $sql_seen = " AND `item`.`unseen` = 1 ";
648 "SELECT COUNT(*) AS `total` FROM `item`
649 WHERE `item`.`visible` = 1 AND
650 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1
654 if (DBM::is_result($r)) {
655 return $r[0]['total'];
662 * @brief Get home notifications
664 * @param int|string $seen If 0 only include notifications into the query
665 * which aren't marked as "seen"
666 * @param int $start Start the query at this point
667 * @param int $limit Maximum number of query results
670 * string 'ident' => Notification identifier
671 * int 'total' => Total number of available home notifications
672 * array 'notifications' => Home notifications
674 public function homeNotifs($seen = 0, $start = 0, $limit = 80)
677 $total = $this->homeTotal($seen);
682 $sql_seen = " AND `item`.`unseen` = 1 ";
686 "SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`,
687 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`,
688 `pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`, `pitem`.`guid` AS `pguid`
689 FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
690 WHERE `item`.`visible` = 1 AND
691 `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1
693 ORDER BY `item`.`created` DESC LIMIT %d, %d ",
694 intval(local_user()),
698 if (DBM::is_result($r)) {
699 $notifs = $this->formatNotifs($r, $ident);
703 'notifications' => $notifs,
712 * @brief Total number of introductions
713 * @param bool $all If false only include introductions into the query
714 * which aren't marked as ignored
716 * @return int Number of introductions
718 private function introTotal($all = false)
723 $sql_extra = " AND `ignore` = 0 ";
727 "SELECT COUNT(*) AS `total` FROM `intro`
728 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
729 intval($_SESSION['uid'])
732 if (DBM::is_result($r)) {
733 return $r[0]['total'];
740 * @brief Get introductions
742 * @param bool $all If false only include introductions into the query
743 * which aren't marked as ignored
744 * @param int $start Start the query at this point
745 * @param int $limit Maximum number of query results
748 * string 'ident' => Notification identifier
749 * int 'total' => Total number of available introductions
750 * array 'notifications' => Introductions
752 public function introNotifs($all = false, $start = 0, $limit = 80)
754 $ident = 'introductions';
755 $total = $this->introTotal($all);
760 $sql_extra = " AND `ignore` = 0 ";
763 /// @todo Fetch contact details by "Contact::getDetailsByUrl" instead of queries to contact, fcontact and gcontact
765 "SELECT `intro`.`id` AS `intro_id`, `intro`.*, `contact`.*,
766 `fcontact`.`name` AS `fname`, `fcontact`.`url` AS `furl`,
767 `fcontact`.`photo` AS `fphoto`, `fcontact`.`request` AS `frequest`,
768 `gcontact`.`location` AS `glocation`, `gcontact`.`about` AS `gabout`,
769 `gcontact`.`keywords` AS `gkeywords`, `gcontact`.`gender` AS `ggender`,
770 `gcontact`.`network` AS `gnetwork`, `gcontact`.`addr` AS `gaddr`
772 LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id`
773 LEFT JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
774 LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
775 WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0
777 intval($_SESSION['uid']),
781 if (DBM::is_result($r)) {
782 $notifs = $this->formatIntros($r);
788 'notifications' => $notifs,
795 * @brief Format the notification query in an usable array
797 * @param array $intros The array from the db query
798 * @return array with the introductions
800 private function formatIntros($intros)
804 foreach ($intros as $it) {
805 // There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
806 // We have to distinguish between these two because they use different data.
807 // Contact suggestions
809 $return_addr = bin2hex(self::getApp()->user['nickname'] . '@' . self::getApp()->get_hostname() . ((self::getApp()->path) ? '/' . self::getApp()->path : ''));
812 'label' => 'friend_suggestion',
813 'notify_type' => L10n::t('Friend Suggestion'),
814 'intro_id' => $it['intro_id'],
815 'madeby' => $it['name'],
816 'contact_id' => $it['contact-id'],
817 'photo' => ((x($it, 'fphoto')) ? proxy_url($it['fphoto'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"),
818 'name' => $it['fname'],
819 'url' => Profile::zrl($it['furl']),
820 'hidden' => $it['hidden'] == 1,
821 'post_newfriend' => (intval(PConfig::get(local_user(), 'system', 'post_newfriend')) ? '1' : 0),
822 'knowyou' => $knowyou,
823 'note' => $it['note'],
824 'request' => $it['frequest'] . '?addr=' . $return_addr,
827 // Normal connection requests
829 $it = $this->getMissingIntroData($it);
831 // Don't show these data until you are connected. Diaspora is doing the same.
832 if ($it['gnetwork'] === NETWORK_DIASPORA) {
833 $it['glocation'] = "";
838 'label' => (($it['network'] !== NETWORK_OSTATUS) ? 'friend_request' : 'follower'),
839 'notify_type' => (($it['network'] !== NETWORK_OSTATUS) ? L10n::t('Friend/Connect Request') : L10n::t('New Follower')),
840 'dfrn_id' => $it['issued-id'],
841 'uid' => $_SESSION['uid'],
842 'intro_id' => $it['intro_id'],
843 'contact_id' => $it['contact-id'],
844 'photo' => ((x($it, 'photo')) ? proxy_url($it['photo'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"),
845 'name' => $it['name'],
846 'location' => BBCode::convert($it['glocation'], false),
847 'about' => BBCode::convert($it['gabout'], false),
848 'keywords' => $it['gkeywords'],
849 'gender' => $it['ggender'],
850 'hidden' => $it['hidden'] == 1,
851 'post_newfriend' => (intval(PConfig::get(local_user(), 'system', 'post_newfriend')) ? '1' : 0),
853 'zrl' => Profile::zrl($it['url']),
854 'addr' => $it['gaddr'],
855 'network' => $it['gnetwork'],
856 'knowyou' => $it['knowyou'],
857 'note' => $it['note'],
868 * @brief Check for missing contact data and try to fetch the data from
871 * @param array $arr The input array with the intro data
873 * @return array The array with the intro data
875 private function getMissingIntroData($arr)
877 // If the network and the addr isn't available from the gcontact
878 // table entry, take the one of the contact table entry
879 if ($arr['gnetwork'] == "") {
880 $arr['gnetwork'] = $arr['network'];
882 if ($arr['gaddr'] == "") {
883 $arr['gaddr'] = $arr['addr'];
886 // If the network and addr is still not available
887 // get the missing data data from other sources
888 if ($arr['gnetwork'] == "" || $arr['gaddr'] == "") {
889 $ret = Contact::getDetailsByURL($arr['url']);
891 if ($arr['gnetwork'] == "" && $ret['network'] != "") {
892 $arr['gnetwork'] = $ret['network'];
894 if ($arr['gaddr'] == "" && $ret['addr'] != "") {
895 $arr['gaddr'] = $ret['addr'];