X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Ffollow.php;h=650eb7fc89c3723101b3e9f66fa3f8e13ea0e850;hb=c105a67cd9cb0669c492cb20d1153fac1c001b56;hp=161e669e949bb26480e07521528aa02b9820125d;hpb=1c38540f20b3207a0fd09ef0802125e45e83bcf6;p=friendica.git diff --git a/include/follow.php b/include/follow.php index 161e669e94..650eb7fc89 100644 --- a/include/follow.php +++ b/include/follow.php @@ -1,14 +1,16 @@ $val) { - if (isset($r[0][$key]) AND ($r[0][$key] != "") AND ($val == "")) + if (isset($r[0][$key]) && ($r[0][$key] != "") && ($val == "")) $ret[$key] = $r[0][$key]; - if (isset($r[0][$key]) AND ($ret[$key] != $r[0][$key])) + if (isset($r[0][$key]) && ($ret[$key] != $r[0][$key])) $update = true; } @@ -70,7 +72,7 @@ function update_contact($id) { -function new_contact($uid,$url,$interactive = false) { +function new_contact($uid, $url, $interactive = false, $network = '') { $result = array('cid' => -1, 'success' => false,'message' => ''); @@ -101,15 +103,19 @@ function new_contact($uid,$url,$interactive = false) { if (x($arr['contact'],'name')) { $ret = $arr['contact']; + } else { + $ret = Probe::uri($url, $network, $uid, false); } - else { - $ret = probe_url($url); + + if (($network != '') && ($ret['network'] != $network)) { + logger('Expected network '.$network.' does not match actual network '.$ret['network']); + return result; } if ($ret['network'] === NETWORK_DFRN) { if ($interactive) { if (strlen($a->path)) { - $myaddr = bin2hex(App::get_baseurl() . '/profile/' . $a->user['nickname']); + $myaddr = bin2hex(System::baseUrl() . '/profile/' . $a->user['nickname']); } else { $myaddr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname()); } @@ -186,42 +192,12 @@ function new_contact($uid,$url,$interactive = false) { if (dbm::is_result($r)) { // update contact - if ($r[0]['rel'] == CONTACT_IS_FOLLOWER || ($network === NETWORK_DIASPORA && $r[0]['rel'] == CONTACT_IS_SHARING)) { - q("UPDATE `contact` SET `rel` = %d , `subhub` = %d, `readonly` = 0 WHERE `id` = %d AND `uid` = %d", - intval(CONTACT_IS_FRIEND), - intval($subhub), - intval($r[0]['id']), - intval($uid) - ); - } - } else { - // check service class limits - - $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `pending` = 0 AND `self` = 0", - intval($uid) - ); - if (dbm::is_result($r)) - $total_contacts = $r[0]['total']; - - if (! service_class_allows($uid,'total_contacts',$total_contacts)) { - $result['message'] .= upgrade_message(); - return $result; - } - - $r = q("SELECT COUNT(`network`) AS `total` FROM `contact` WHERE `uid` = %d AND `network` = '%s' AND `pending` = 0 AND `self` = 0", - intval($uid), - dbesc($network) - ); - if (dbm::is_result($r)) { - $total_network = $r[0]['total']; - } - - if (! service_class_allows($uid,'total_contacts_' . $network,$total_network)) { - $result['message'] .= upgrade_message(); - return $result; - } + $new_relation = (($r[0]['rel'] == CONTACT_IS_FOLLOWER) ? CONTACT_IS_FRIEND : CONTACT_IS_SHARING); - $new_relation = ((in_array($ret['network'], array(NETWORK_MAIL, NETWORK_DIASPORA))) ? CONTACT_IS_FRIEND : CONTACT_IS_SHARING); + $fields = array('rel' => $new_relation, 'subhub' => $subhub, 'readonly' => false); + dba::update('contact', $fields, array('id' => $r[0]['id'])); + } else { + $new_relation = ((in_array($ret['network'], array(NETWORK_MAIL))) ? CONTACT_IS_FRIEND : CONTACT_IS_SHARING); // create contact record $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `alias`, `batch`, `notify`, `poll`, `poco`, `name`, `nick`, `network`, `pubkey`, `rel`, `priority`,