<?php
-require_once("include/Scrape.php");
-require_once("include/socgraph.php");
-require_once('include/group.php');
-require_once('include/salmon.php');
-require_once('include/ostatus.php');
-require_once("include/Photo.php");
-require_once('include/diaspora.php');
+
+use Friendica\App;
+use Friendica\Core\System;
+use Friendica\Core\Worker;
+use Friendica\Network\Probe;
+
+require_once 'include/probe.php';
+require_once 'include/socgraph.php';
+require_once 'include/group.php';
+require_once 'include/salmon.php';
+require_once 'include/ostatus.php';
+require_once 'include/Photo.php';
+require_once 'include/diaspora.php';
function update_contact($id) {
/*
// make sure to not overwrite existing values with blank entries
foreach ($ret AS $key => $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;
}
-function new_contact($uid,$url,$interactive = false) {
+function new_contact($uid, $url, $interactive = false, $network = '') {
$result = array('cid' => -1, 'success' => false,'message' => '');
return $result;
}
+ if (blocked_url($url)) {
+ $result['message'] = t('Blocked domain');
+ return $result;
+ }
+
if (! $url) {
$result['message'] = t('Connect URL missing.');
return $result;
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());
}
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
+ $new_relation = (($r[0]['rel'] == CONTACT_IS_FOLLOWER) ? CONTACT_IS_FRIEND : CONTACT_IS_SHARING);
- $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 = ((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`,
// pull feed and consume it, which should subscribe to the hub.
- proc_run(PRIORITY_HIGH, "include/onepoll.php", $contact_id, "force");
+ Worker::add(PRIORITY_HIGH, "onepoll", $contact_id, "force");
$r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",