use Friendica\Util\Crypto;
use Friendica\Util\Network;
use Friendica\Util\XML;
-
+use Friendica\Util\DateTimeFormat;
use dba;
use DOMXPath;
use DOMDocument;
}
}
- if (self::$baseurl != "") {
+ if (!empty(self::$baseurl)) {
$data["baseurl"] = self::$baseurl;
}
- if (!isset($data["network"])) {
+ if (empty($data["network"])) {
$data["network"] = NETWORK_PHANTOM;
}
'network' => $data['network'],
'server_url' => $data['baseurl']];
+ // This doesn't cover the case when a community isn't a community anymore
+ if (!empty($data['community']) && $data['community']) {
+ $fields['community'] = $data['community'];
+ $fields['contact-type'] = ACCOUNT_TYPE_COMMUNITY;
+ }
+
$fieldnames = [];
foreach ($fields as $key => $val) {
$old_fields = dba::selectFirst('gcontact', $fieldnames, $condition);
+ // When the gcontact doesn't exist, the value "true" will trigger an insert.
+ // In difference to the public contacts we want to have every contact
+ // in the world in our global contacts.
+ if (!$old_fields) {
+ $old_fields = true;
+
+ // These values have to be set only on insert
+ $fields['photo'] = $data['photo'];
+ $fields['created'] = DateTimeFormat::utcNow();
+ }
+
dba::update('gcontact', $fields, $condition, $old_fields);
$fields = ['name' => $data['name'],
'confirm' => $data['confirm'],
'poco' => $data['poco'],
'network' => $data['network'],
- 'success_update' => DBM::date()];
+ 'pubkey' => $data['pubkey'],
+ 'priority' => $data['priority'],
+ 'writable' => true,
+ 'rel' => CONTACT_IS_SHARING];
$fieldnames = [];
$condition = ['nurl' => normalise_link($data["url"]), 'self' => false, 'uid' => 0];
+ // "$old_fields" will return a "false" when the contact doesn't exist.
+ // This won't trigger an insert. This is intended, since we only need
+ // public contacts for everyone we store items from.
+ // We don't need to store every contact on the planet.
$old_fields = dba::selectFirst('contact', $fieldnames, $condition);
+ $fields['name-date'] = DateTimeFormat::utcNow();
+ $fields['uri-date'] = DateTimeFormat::utcNow();
+ $fields['success_update'] = DateTimeFormat::utcNow();
+
dba::update('contact', $fields, $condition, $old_fields);
}
}
$result = self::ostatus($webfinger);
}
if ((!$result && ($network == "")) || ($network == NETWORK_PUMPIO)) {
- $result = self::pumpio($webfinger);
+ $result = self::pumpio($webfinger, $addr);
}
if ((!$result && ($network == "")) || ($network == NETWORK_FEED)) {
$result = self::feed($uri);
$result["baseurl"] = substr($result["url"], 0, $pos).$host;
}
}
-
return $result;
}
}
}
+ if (substr($webfinger["subject"], 0, 5) == "acct:") {
+ $data["addr"] = substr($webfinger["subject"], 5);
+ }
+
if (!isset($data["network"]) || ($hcard_url == "")) {
return false;
}
$data = [];
- // This is ugly - but pump.io doesn't seem to know a better way for it
- $data["name"] = trim($xpath->query("//h1[@class='media-header']")->item(0)->nodeValue);
- $pos = strpos($data["name"], chr(10));
- if ($pos) {
- $data["name"] = trim(substr($data["name"], 0, $pos));
+ $data["name"] = $xpath->query("//span[contains(@class, 'p-name')]")->item(0)->nodeValue;
+
+ if ($data["name"] == '') {
+ // This is ugly - but pump.io doesn't seem to know a better way for it
+ $data["name"] = trim($xpath->query("//h1[@class='media-header']")->item(0)->nodeValue);
+ $pos = strpos($data["name"], chr(10));
+ if ($pos) {
+ $data["name"] = trim(substr($data["name"], 0, $pos));
+ }
+ }
+
+ $data["location"] = $xpath->query("//p[contains(@class, 'p-locality')]")->item(0)->nodeValue;
+
+ if ($data["location"] == '') {
+ $data["location"] = $xpath->query("//p[contains(@class, 'location')]")->item(0)->nodeValue;
}
- $avatar = $xpath->query("//img[@class='img-rounded media-object']")->item(0);
+ $data["about"] = $xpath->query("//p[contains(@class, 'p-note')]")->item(0)->nodeValue;
+
+ if ($data["about"] == '') {
+ $data["about"] = $xpath->query("//p[contains(@class, 'summary')]")->item(0)->nodeValue;
+ }
+
+ $avatar = $xpath->query("//img[contains(@class, 'u-photo')]")->item(0);
+ if (!$avatar) {
+ $avatar = $xpath->query("//img[@class='img-rounded media-object']")->item(0);
+ }
if ($avatar) {
foreach ($avatar->attributes as $attribute) {
if ($attribute->name == "src") {
}
}
- $data["location"] = $xpath->query("//p[@class='location']")->item(0)->nodeValue;
- $data["about"] = $xpath->query("//p[@class='summary']")->item(0)->nodeValue;
-
return $data;
}
*
* @return array pump.io data
*/
- private static function pumpio($webfinger)
+ private static function pumpio($webfinger, $addr)
{
$data = [];
foreach ($webfinger["links"] as $link) {
$data = array_merge($data, $profile_data);
+ if (($addr != '') && ($data['name'] != '')) {
+ $name = trim(str_replace($addr, '', $data['name']));
+ if ($name != '') {
+ $data['name'] = $name;
+ }
+ }
+
return $data;
}
return false;
}
- if ($uid != 0) {
- $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid));
-
- $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval($uid));
+ if ($uid == 0) {
+ return false;
+ }
- if (DBM::is_result($x) && DBM::is_result($r)) {
- $mailbox = Email::constructMailboxName($r[0]);
- $password = '';
- openssl_private_decrypt(hex2bin($r[0]['pass']), $password, $x[0]['prvkey']);
- $mbox = Email::connect($mailbox, $r[0]['user'], $password);
- if (!mbox) {
- return false;
- }
- }
+ $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid));
- $msgs = Email::poll($mbox, $uri);
- logger('searching '.$uri.', '.count($msgs).' messages found.', LOGGER_DEBUG);
+ $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval($uid));
- if (!count($msgs)) {
+ if (DBM::is_result($x) && DBM::is_result($r)) {
+ $mailbox = Email::constructMailboxName($r[0]);
+ $password = '';
+ openssl_private_decrypt(hex2bin($r[0]['pass']), $password, $x[0]['prvkey']);
+ $mbox = Email::connect($mailbox, $r[0]['user'], $password);
+ if (!$mbox) {
return false;
}
}
+ $msgs = Email::poll($mbox, $uri);
+ logger('searching '.$uri.', '.count($msgs).' messages found.', LOGGER_DEBUG);
+
+ if (!count($msgs)) {
+ return false;
+ }
+
$phost = substr($uri, strpos($uri, '@') + 1);
$data = [];