namespace Friendica\Protocol;
+use DOMDocument;
+use DOMXPath;
+use Exception;
use Friendica\Content\Text\HTML;
use Friendica\Core\Config;
+use Friendica\Core\Logger;
+use Friendica\Core\Protocol;
use Friendica\Core\Worker;
-use Friendica\Database\DBM;
+use Friendica\Database\DBA;
use Friendica\Model\GContact;
use Friendica\Model\Profile;
+use Friendica\Module\Register;
use Friendica\Network\Probe;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
-use Friendica\Protocol\Diaspora;
-use dba;
-use DOMDocument;
-use DOMXPath;
-use Exception;
-
-require_once 'include/dba.php';
+use Friendica\Util\Strings;
+use Friendica\Util\XML;
class PortableContact
{
+ const DISABLED = 0;
+ const USERS = 1;
+ const USERS_GCONTACTS = 2;
+ const USERS_GCONTACTS_FALLBACK = 3;
+
/**
* @brief Fetch POCO data
*
* Once the global contact is stored add (if necessary) the contact linkage which associates
* the given uid, cid to the global contact entry. There can be many uid/cid combinations
* pointing to the same global contact id.
- *
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function loadWorker($cid, $uid = 0, $zcid = 0, $url = null)
{
* @param integer $uid User ID
* @param integer $zcid Global Contact ID
* @param integer $url POCO address that should be polled
- *
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function load($cid, $uid, $zcid, $url)
{
- $a = get_app();
-
if ($cid) {
if (!$url || !$uid) {
- $contact = dba::selectFirst('contact', ['poco', 'uid'], ['id' => $cid]);
- if (DBM::is_result($contact)) {
+ $contact = DBA::selectFirst('contact', ['poco', 'uid'], ['id' => $cid]);
+ if (DBA::isResult($contact)) {
$url = $contact['poco'];
$uid = $contact['uid'];
}
return;
}
- $url = $url . (($uid) ? '/@me/@all?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation' : '?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation') ;
+ $url = $url . (($uid) ? '/@me/@all?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation' : '?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation');
- logger('load: ' . $url, LOGGER_DEBUG);
+ Logger::log('load: ' . $url, Logger::DEBUG);
- $s = Network::fetchUrl($url);
+ $fetchresult = Network::fetchUrlFull($url);
+ $s = $fetchresult->getBody();
- logger('load: returns ' . $s, LOGGER_DATA);
+ Logger::log('load: returns ' . $s, Logger::DATA);
- logger('load: return code: ' . $a->get_curl_code(), LOGGER_DEBUG);
+ Logger::log('load: return code: ' . $fetchresult->getReturnCode(), Logger::DEBUG);
- if (($a->get_curl_code() > 299) || (! $s)) {
+ if (($fetchresult->getReturnCode() > 299) || (! $s)) {
return;
}
- $j = json_decode($s);
+ $j = json_decode($s, true);
- logger('load: json: ' . print_r($j, true), LOGGER_DATA);
+ Logger::log('load: json: ' . print_r($j, true), Logger::DATA);
- if (! isset($j->entry)) {
+ if (!isset($j['entry'])) {
return;
}
$total = 0;
- foreach ($j->entry as $entry) {
+ foreach ($j['entry'] as $entry) {
$total ++;
$profile_url = '';
$profile_photo = '';
$connect_url = '';
$name = '';
$network = '';
- $updated = NULL_DATE;
+ $updated = DBA::NULL_DATETIME;
$location = '';
$about = '';
$keywords = '';
$contact_type = -1;
$generation = 0;
- $name = $entry->displayName;
+ if (!empty($entry['displayName'])) {
+ $name = $entry['displayName'];
+ }
- if (isset($entry->urls)) {
- foreach ($entry->urls as $url) {
- if ($url->type == 'profile') {
- $profile_url = $url->value;
+ if (isset($entry['urls'])) {
+ foreach ($entry['urls'] as $url) {
+ if ($url['type'] == 'profile') {
+ $profile_url = $url['value'];
continue;
}
- if ($url->type == 'webfinger') {
- $connect_url = str_replace('acct:', '', $url->value);
+ if ($url['type'] == 'webfinger') {
+ $connect_url = str_replace('acct:', '', $url['value']);
continue;
}
}
}
- if (isset($entry->photos)) {
- foreach ($entry->photos as $photo) {
- if ($photo->type == 'profile') {
- $profile_photo = $photo->value;
+ if (isset($entry['photos'])) {
+ foreach ($entry['photos'] as $photo) {
+ if ($photo['type'] == 'profile') {
+ $profile_photo = $photo['value'];
continue;
}
}
}
- if (isset($entry->updated)) {
- $updated = date(DateTimeFormat::MYSQL, strtotime($entry->updated));
+ if (isset($entry['updated'])) {
+ $updated = date(DateTimeFormat::MYSQL, strtotime($entry['updated']));
}
- if (isset($entry->network)) {
- $network = $entry->network;
+ if (isset($entry['network'])) {
+ $network = $entry['network'];
}
- if (isset($entry->currentLocation)) {
- $location = $entry->currentLocation;
+ if (isset($entry['currentLocation'])) {
+ $location = $entry['currentLocation'];
}
- if (isset($entry->aboutMe)) {
- $about = HTML::toBBCode($entry->aboutMe);
+ if (isset($entry['aboutMe'])) {
+ $about = HTML::toBBCode($entry['aboutMe']);
}
- if (isset($entry->gender)) {
- $gender = $entry->gender;
+ if (isset($entry['gender'])) {
+ $gender = $entry['gender'];
}
- if (isset($entry->generation) && ($entry->generation > 0)) {
- $generation = ++$entry->generation;
+ if (isset($entry['generation']) && ($entry['generation'] > 0)) {
+ $generation = ++$entry['generation'];
}
- if (isset($entry->tags)) {
- foreach ($entry->tags as $tag) {
+ if (isset($entry['tags'])) {
+ foreach ($entry['tags'] as $tag) {
$keywords = implode(", ", $tag);
}
}
- if (isset($entry->contactType) && ($entry->contactType >= 0)) {
- $contact_type = $entry->contactType;
+ if (isset($entry['contactType']) && ($entry['contactType'] >= 0)) {
+ $contact_type = $entry['contactType'];
}
$gcontact = ["url" => $profile_url,
GContact::link($gcid, $uid, $cid, $zcid);
} catch (Exception $e) {
- logger($e->getMessage(), LOGGER_DEBUG);
+ Logger::log($e->getMessage(), Logger::DEBUG);
}
}
- logger("load: loaded $total entries", LOGGER_DEBUG);
+ Logger::log("load: loaded $total entries", Logger::DEBUG);
$condition = ["`cid` = ? AND `uid` = ? AND `zcid` = ? AND `updated` < UTC_TIMESTAMP - INTERVAL 2 DAY", $cid, $uid, $zcid];
- dba::delete('glink', $condition);
+ DBA::delete('glink', $condition);
}
public static function reachable($profile, $server = "", $network = "", $force = false)
$friendica = preg_replace("=(https?://)(.*)/profile/(.*)=ism", "$1$2", $profile);
if ($friendica != $profile) {
$server_url = $friendica;
- $network = NETWORK_DFRN;
}
}
$diaspora = preg_replace("=(https?://)(.*)/u/(.*)=ism", "$1$2", $profile);
if ($diaspora != $profile) {
$server_url = $diaspora;
- $network = NETWORK_DIASPORA;
}
}
$red = preg_replace("=(https?://)(.*)/channel/(.*)=ism", "$1$2", $profile);
if ($red != $profile) {
$server_url = $red;
- $network = NETWORK_DIASPORA;
}
}
$mastodon = preg_replace("=(https?://)(.*)/users/(.*)=ism", "$1$2", $profile);
if ($mastodon != $profile) {
$server_url = $mastodon;
- $network = NETWORK_OSTATUS;
}
}
$ostatus = preg_replace("=(https?://)(.*)/user/(.*)=ism", "$1$2", $profile);
if ($ostatus != $profile) {
$server_url = $ostatus;
- $network = NETWORK_OSTATUS;
}
}
$base = preg_replace("=(https?://)(.*?)/(.*)=ism", "$1$2", $profile);
if ($base != $profile) {
$server_url = $base;
- $network = NETWORK_PHANTOM;
}
}
$r = q(
"SELECT `id` FROM `gserver` WHERE `nurl` = '%s' AND `last_contact` > `last_failure`",
- dbesc(normalise_link($server_url))
+ DBA::escape(Strings::normaliseLink($server_url))
);
- if (DBM::is_result($r)) {
+ if (DBA::isResult($r)) {
return $server_url;
}
// Fetch the host-meta to check if this really is a server
- $serverret = Network::curl($server_url."/.well-known/host-meta");
- if (!$serverret["success"]) {
+ $curlResult = Network::curl($server_url."/.well-known/host-meta");
+ if (!$curlResult->isSuccess()) {
return "";
}
{
$gcontacts = q(
"SELECT * FROM `gcontact` WHERE `nurl` = '%s'",
- dbesc(normalise_link($profile))
+ DBA::escape(Strings::normaliseLink($profile))
);
- if (!DBM::is_result($gcontacts)) {
+ if (!DBA::isResult($gcontacts)) {
return false;
}
$contact = ["url" => $profile];
- if ($gcontacts[0]["created"] <= NULL_DATE) {
+ if ($gcontacts[0]["created"] <= DBA::NULL_DATETIME) {
$contact['created'] = DateTimeFormat::utcNow();
}
$server_url = '';
if ($force) {
- $server_url = normalise_link(self::detectServer($profile));
+ $server_url = Strings::normaliseLink(self::detectServer($profile));
}
if (($server_url == '') && ($gcontacts[0]["server_url"] != "")) {
}
if (!$force && (($server_url == '') || ($gcontacts[0]["server_url"] == $gcontacts[0]["nurl"]))) {
- $server_url = normalise_link(self::detectServer($profile));
+ $server_url = Strings::normaliseLink(self::detectServer($profile));
}
- if (!in_array($gcontacts[0]["network"], [NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_FEED, NETWORK_OSTATUS, ""])) {
- logger("Profile ".$profile.": Network type ".$gcontacts[0]["network"]." can't be checked", LOGGER_DEBUG);
+ if (!in_array($gcontacts[0]["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::FEED, Protocol::OSTATUS, ""])) {
+ Logger::log("Profile ".$profile.": Network type ".$gcontacts[0]["network"]." can't be checked", Logger::DEBUG);
return false;
}
if (!self::checkServer($server_url, $gcontacts[0]["network"], $force)) {
if ($force) {
$fields = ['last_failure' => DateTimeFormat::utcNow()];
- dba::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
+ DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($profile)]);
}
- logger("Profile ".$profile.": Server ".$server_url." wasn't reachable.", LOGGER_DEBUG);
+ Logger::log("Profile ".$profile.": Server ".$server_url." wasn't reachable.", Logger::DEBUG);
return false;
}
$contact['server_url'] = $server_url;
}
- if (in_array($gcontacts[0]["network"], ["", NETWORK_FEED])) {
+ if (in_array($gcontacts[0]["network"], ["", Protocol::FEED])) {
$server = q(
"SELECT `network` FROM `gserver` WHERE `nurl` = '%s' AND `network` != ''",
- dbesc(normalise_link($server_url))
+ DBA::escape(Strings::normaliseLink($server_url))
);
if ($server) {
// noscrape is really fast so we don't cache the call.
if (($server_url != "") && ($gcontacts[0]["nick"] != "")) {
// Use noscrape if possible
- $server = q("SELECT `noscrape`, `network` FROM `gserver` WHERE `nurl` = '%s' AND `noscrape` != ''", dbesc(normalise_link($server_url)));
+ $server = q("SELECT `noscrape`, `network` FROM `gserver` WHERE `nurl` = '%s' AND `noscrape` != ''", DBA::escape(Strings::normaliseLink($server_url)));
if ($server) {
- $noscraperet = Network::curl($server[0]["noscrape"]."/".$gcontacts[0]["nick"]);
+ $curlResult = Network::curl($server[0]["noscrape"]."/".$gcontacts[0]["nick"]);
- if ($noscraperet["success"] && ($noscraperet["body"] != "")) {
- $noscrape = json_decode($noscraperet["body"], true);
+ if ($curlResult->isSuccess() && ($curlResult->getBody() != "")) {
+ $noscrape = json_decode($curlResult->getBody(), true);
if (is_array($noscrape)) {
$contact["network"] = $server[0]["network"];
GContact::update($contact);
- if (trim($noscrape["updated"]) != "") {
+ if (!empty($noscrape["updated"])) {
$fields = ['last_contact' => DateTimeFormat::utcNow()];
- dba::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
+ DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($profile)]);
- logger("Profile ".$profile." was last updated at ".$noscrape["updated"]." (noscrape)", LOGGER_DEBUG);
+ Logger::log("Profile ".$profile." was last updated at ".$noscrape["updated"]." (noscrape)", Logger::DEBUG);
return $noscrape["updated"];
}
// If we only can poll the feed, then we only do this once a while
if (!$force && !self::updateNeeded($gcontacts[0]["created"], $gcontacts[0]["updated"], $gcontacts[0]["last_failure"], $gcontacts[0]["last_contact"])) {
- logger("Profile ".$profile." was last updated at ".$gcontacts[0]["updated"]." (cached)", LOGGER_DEBUG);
+ Logger::log("Profile ".$profile." was last updated at ".$gcontacts[0]["updated"]." (cached)", Logger::DEBUG);
GContact::update($contact);
return $gcontacts[0]["updated"];
// Is the profile link the alternate OStatus link notation? (http://domain.tld/user/4711)
// Then check the other link and delete this one
- if (($data["network"] == NETWORK_OSTATUS) && self::alternateOStatusUrl($profile)
- && (normalise_link($profile) == normalise_link($data["alias"]))
- && (normalise_link($profile) != normalise_link($data["url"]))
+ if (($data["network"] == Protocol::OSTATUS) && self::alternateOStatusUrl($profile)
+ && (Strings::normaliseLink($profile) == Strings::normaliseLink($data["alias"]))
+ && (Strings::normaliseLink($profile) != Strings::normaliseLink($data["url"]))
) {
// Delete the old entry
- dba::delete('gcontact', ['nurl' => normalise_link($profile)]);
+ DBA::delete('gcontact', ['nurl' => Strings::normaliseLink($profile)]);
$gcontact = array_merge($gcontacts[0], $data);
self::lastUpdated($data["url"], $force);
} catch (Exception $e) {
- logger($e->getMessage(), LOGGER_DEBUG);
+ Logger::log($e->getMessage(), Logger::DEBUG);
}
- logger("Profile ".$profile." was deleted", LOGGER_DEBUG);
+ Logger::log("Profile ".$profile." was deleted", Logger::DEBUG);
return false;
}
- if (($data["poll"] == "") || (in_array($data["network"], [NETWORK_FEED, NETWORK_PHANTOM]))) {
+ if (($data["poll"] == "") || (in_array($data["network"], [Protocol::FEED, Protocol::PHANTOM]))) {
$fields = ['last_failure' => DateTimeFormat::utcNow()];
- dba::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
+ DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($profile)]);
- logger("Profile ".$profile." wasn't reachable (profile)", LOGGER_DEBUG);
+ Logger::log("Profile ".$profile." wasn't reachable (profile)", Logger::DEBUG);
return false;
}
GContact::update($contact);
- $feedret = Network::curl($data["poll"]);
+ $curlResult = Network::curl($data["poll"]);
- if (!$feedret["success"]) {
+ if (!$curlResult->isSuccess()) {
$fields = ['last_failure' => DateTimeFormat::utcNow()];
- dba::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
+ DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($profile)]);
- logger("Profile ".$profile." wasn't reachable (no feed)", LOGGER_DEBUG);
+ Logger::log("Profile ".$profile." wasn't reachable (no feed)", Logger::DEBUG);
return false;
}
$doc = new DOMDocument();
- @$doc->loadXML($feedret["body"]);
+ /// @TODO Avoid error supression here
+ @$doc->loadXML($curlResult->getBody());
$xpath = new DOMXPath($doc);
$xpath->registerNamespace('atom', "http://www.w3.org/2005/Atom");
$last_updated = "";
foreach ($entries as $entry) {
- $published = DateTimeFormat::utc($xpath->query('atom:published/text()', $entry)->item(0)->nodeValue);
- $updated = DateTimeFormat::utc($xpath->query('atom:updated/text()' , $entry)->item(0)->nodeValue);
+ $published_item = $xpath->query('atom:published/text()', $entry)->item(0);
+ $updated_item = $xpath->query('atom:updated/text()' , $entry)->item(0);
+ $published = isset($published_item->nodeValue) ? DateTimeFormat::utc($published_item->nodeValue) : null;
+ $updated = isset($updated_item->nodeValue) ? DateTimeFormat::utc($updated_item->nodeValue) : null;
+
+ if (!isset($published) || !isset($updated)) {
+ Logger::notice('Invalid entry for XPath.', ['entry' => $entry, 'profile' => $profile]);
+ continue;
+ }
if ($last_updated < $published) {
$last_updated = $published;
// Maybe there aren't any entries. Then check if it is a valid feed
if ($last_updated == "") {
if ($xpath->query('/atom:feed')->length > 0) {
- $last_updated = NULL_DATE;
+ $last_updated = DBA::NULL_DATETIME;
}
}
- $fields = ['updated' => $last_updated, 'last_contact' => DateTimeFormat::utcNow()];
- dba::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
+ $fields = ['last_contact' => DateTimeFormat::utcNow()];
+
+ if (!empty($last_updated)) {
+ $fields['updated'] = $last_updated;
+ }
+
+ DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($profile)]);
if (($gcontacts[0]["generation"] == 0)) {
$fields = ['generation' => 9];
- dba::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
+ DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($profile)]);
}
- logger("Profile ".$profile." was last updated at ".$last_updated, LOGGER_DEBUG);
+ Logger::log("Profile ".$profile." was last updated at ".$last_updated, Logger::DEBUG);
return $last_updated;
}
return true;
}
+ /// @TODO Maybe move this out to an utilities class?
private static function toBoolean($val)
{
if (($val == "true") || ($val == 1)) {
/**
* @brief Detect server type (Hubzilla or Friendica) via the poco data
*
- * @param object $data POCO data
+ * @param array $data POCO data
* @return array Server data
*/
- private static function detectPocoData($data)
+ private static function detectPocoData(array $data)
{
- $server = false;
-
- if (!isset($data->entry)) {
+ if (!isset($data['entry'])) {
return false;
}
- if (count($data->entry) == 0) {
+ if (count($data['entry']) == 0) {
return false;
}
- if (!isset($data->entry[0]->urls)) {
+ if (!isset($data['entry'][0]['urls'])) {
return false;
}
- if (count($data->entry[0]->urls) == 0) {
+ if (count($data['entry'][0]['urls']) == 0) {
return false;
}
- foreach ($data->entry[0]->urls as $url) {
- if ($url->type == 'zot') {
+ foreach ($data['entry'][0]['urls'] as $url) {
+ if ($url['type'] == 'zot') {
$server = [];
$server["platform"] = 'Hubzilla';
- $server["network"] = NETWORK_DIASPORA;
+ $server["network"] = Protocol::DIASPORA;
return $server;
}
}
*
* @param string $server_url address of the server
* @return array Server data
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function fetchNodeinfo($server_url)
{
- $serverret = Network::curl($server_url."/.well-known/nodeinfo");
- if (!$serverret["success"]) {
+ $curlResult = Network::curl($server_url."/.well-known/nodeinfo");
+ if (!$curlResult->isSuccess()) {
return false;
}
- $nodeinfo = json_decode($serverret['body']);
-
- if (!is_object($nodeinfo)) {
- return false;
- }
+ $nodeinfo = json_decode($curlResult->getBody(), true);
- if (!is_array($nodeinfo->links)) {
+ if (!is_array($nodeinfo) || !isset($nodeinfo['links'])) {
return false;
}
$nodeinfo1_url = '';
$nodeinfo2_url = '';
- foreach ($nodeinfo->links as $link) {
- if ($link->rel == 'http://nodeinfo.diaspora.software/ns/schema/1.0') {
- $nodeinfo1_url = $link->href;
+ foreach ($nodeinfo['links'] as $link) {
+ if (!is_array($link) || empty($link['rel']) || empty($link['href'])) {
+ Logger::log('Invalid nodeinfo format for ' . $server_url, Logger::DEBUG);
+ continue;
}
- if ($link->rel == 'http://nodeinfo.diaspora.software/ns/schema/2.0') {
- $nodeinfo2_url = $link->href;
+ if ($link['rel'] == 'http://nodeinfo.diaspora.software/ns/schema/1.0') {
+ $nodeinfo1_url = $link['href'];
+ } elseif ($link['rel'] == 'http://nodeinfo.diaspora.software/ns/schema/2.0') {
+ $nodeinfo2_url = $link['href'];
}
}
*
* @param string $nodeinfo_url address of the nodeinfo path
* @return array Server data
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function parseNodeinfo1($nodeinfo_url)
{
- $serverret = Network::curl($nodeinfo_url);
- if (!$serverret["success"]) {
+ $curlResult = Network::curl($nodeinfo_url);
+
+ if (!$curlResult->isSuccess()) {
return false;
}
- $nodeinfo = json_decode($serverret['body']);
- if (!is_object($nodeinfo)) {
+ $nodeinfo = json_decode($curlResult->getBody(), true);
+
+ if (!is_array($nodeinfo)) {
return false;
}
$server = [];
- $server['register_policy'] = REGISTER_CLOSED;
+ $server['register_policy'] = Register::CLOSED;
- if (is_bool($nodeinfo->openRegistrations) && $nodeinfo->openRegistrations) {
- $server['register_policy'] = REGISTER_OPEN;
+ if (is_bool($nodeinfo['openRegistrations']) && $nodeinfo['openRegistrations']) {
+ $server['register_policy'] = Register::OPEN;
}
- if (is_object($nodeinfo->software)) {
- if (isset($nodeinfo->software->name)) {
- $server['platform'] = $nodeinfo->software->name;
+ if (is_array($nodeinfo['software'])) {
+ if (isset($nodeinfo['software']['name'])) {
+ $server['platform'] = $nodeinfo['software']['name'];
}
- if (isset($nodeinfo->software->version)) {
- $server['version'] = $nodeinfo->software->version;
+ if (isset($nodeinfo['software']['version'])) {
+ $server['version'] = $nodeinfo['software']['version'];
// Version numbers on Nodeinfo are presented with additional info, e.g.:
// 0.6.3.0-p1702cc1c, 0.6.99.0-p1b9ab160 or 3.4.3-2-1191.
$server['version'] = preg_replace("=(.+)-(.{4,})=ism", "$1", $server['version']);
}
}
- if (is_object($nodeinfo->metadata)) {
- if (isset($nodeinfo->metadata->nodeName)) {
- $server['site_name'] = $nodeinfo->metadata->nodeName;
- }
+ if (isset($nodeinfo['metadata']['nodeName'])) {
+ $server['site_name'] = $nodeinfo['metadata']['nodeName'];
}
- if (!empty($nodeinfo->usage->users->total)) {
- $server['registered-users'] = $nodeinfo->usage->users->total;
+ if (!empty($nodeinfo['usage']['users']['total'])) {
+ $server['registered-users'] = $nodeinfo['usage']['users']['total'];
}
$diaspora = false;
$friendica = false;
$gnusocial = false;
- if (is_array($nodeinfo->protocols->inbound)) {
- foreach ($nodeinfo->protocols->inbound as $inbound) {
+ if (!empty($nodeinfo['protocols']['inbound']) && is_array($nodeinfo['protocols']['inbound'])) {
+ foreach ($nodeinfo['protocols']['inbound'] as $inbound) {
if ($inbound == 'diaspora') {
$diaspora = true;
}
}
if ($gnusocial) {
- $server['network'] = NETWORK_OSTATUS;
+ $server['network'] = Protocol::OSTATUS;
}
if ($diaspora) {
- $server['network'] = NETWORK_DIASPORA;
+ $server['network'] = Protocol::DIASPORA;
}
if ($friendica) {
- $server['network'] = NETWORK_DFRN;
+ $server['network'] = Protocol::DFRN;
}
if (!$server) {
*
* @param string $nodeinfo_url address of the nodeinfo path
* @return array Server data
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function parseNodeinfo2($nodeinfo_url)
{
- $serverret = Network::curl($nodeinfo_url);
- if (!$serverret["success"]) {
+ $curlResult = Network::curl($nodeinfo_url);
+ if (!$curlResult->isSuccess()) {
return false;
}
- $nodeinfo = json_decode($serverret['body']);
- if (!is_object($nodeinfo)) {
+ $nodeinfo = json_decode($curlResult->getBody(), true);
+
+ if (!is_array($nodeinfo)) {
return false;
}
$server = [];
- $server['register_policy'] = REGISTER_CLOSED;
+ $server['register_policy'] = Register::CLOSED;
- if (is_bool($nodeinfo->openRegistrations) && $nodeinfo->openRegistrations) {
- $server['register_policy'] = REGISTER_OPEN;
+ if (is_bool($nodeinfo['openRegistrations']) && $nodeinfo['openRegistrations']) {
+ $server['register_policy'] = Register::OPEN;
}
- if (is_object($nodeinfo->software)) {
- if (isset($nodeinfo->software->name)) {
- $server['platform'] = $nodeinfo->software->name;
+ if (is_array($nodeinfo['software'])) {
+ if (isset($nodeinfo['software']['name'])) {
+ $server['platform'] = $nodeinfo['software']['name'];
}
- if (isset($nodeinfo->software->version)) {
- $server['version'] = $nodeinfo->software->version;
+ if (isset($nodeinfo['software']['version'])) {
+ $server['version'] = $nodeinfo['software']['version'];
// Version numbers on Nodeinfo are presented with additional info, e.g.:
// 0.6.3.0-p1702cc1c, 0.6.99.0-p1b9ab160 or 3.4.3-2-1191.
$server['version'] = preg_replace("=(.+)-(.{4,})=ism", "$1", $server['version']);
}
}
- if (is_object($nodeinfo->metadata)) {
- if (isset($nodeinfo->metadata->nodeName)) {
- $server['site_name'] = $nodeinfo->metadata->nodeName;
- }
+ if (isset($nodeinfo['metadata']['nodeName'])) {
+ $server['site_name'] = $nodeinfo['metadata']['nodeName'];
}
- if (!empty($nodeinfo->usage->users->total)) {
- $server['registered-users'] = $nodeinfo->usage->users->total;
+ if (!empty($nodeinfo['usage']['users']['total'])) {
+ $server['registered-users'] = $nodeinfo['usage']['users']['total'];
}
$diaspora = false;
$friendica = false;
$gnusocial = false;
- if (is_array($nodeinfo->protocols)) {
- foreach ($nodeinfo->protocols as $protocol) {
+ if (!empty($nodeinfo['protocols'])) {
+ foreach ($nodeinfo['protocols'] as $protocol) {
if ($protocol == 'diaspora') {
$diaspora = true;
- }
- if ($protocol == 'friendica') {
+ } elseif ($protocol == 'friendica') {
$friendica = true;
- }
- if ($protocol == 'gnusocial') {
+ } elseif ($protocol == 'gnusocial') {
$gnusocial = true;
}
}
}
if ($gnusocial) {
- $server['network'] = NETWORK_OSTATUS;
- }
- if ($diaspora) {
- $server['network'] = NETWORK_DIASPORA;
- }
- if ($friendica) {
- $server['network'] = NETWORK_DFRN;
+ $server['network'] = Protocol::OSTATUS;
+ } elseif ($diaspora) {
+ $server['network'] = Protocol::DIASPORA;
+ } elseif ($friendica) {
+ $server['network'] = Protocol::DFRN;
}
- if (!$server) {
+ if (empty($server)) {
return false;
}
$server = false;
$doc = new DOMDocument();
+ /// @TODO Acoid supressing error
@$doc->loadHTML($body);
$xpath = new DOMXPath($doc);
$server = [];
$server["platform"] = $version_part[0];
$server["version"] = $version_part[1];
- $server["network"] = NETWORK_DFRN;
+ $server["network"] = Protocol::DFRN;
}
}
}
$server = [];
$server["platform"] = $attr['content'];
$server["version"] = "";
- $server["network"] = NETWORK_DIASPORA;
+ $server["network"] = Protocol::DIASPORA;
}
}
}
return false;
}
- $server["site_name"] = $xpath->evaluate("//head/title/text()")->item(0)->nodeValue;
+ $server["site_name"] = XML::getFirstNodeValue($xpath, '//head/title/text()');
+
return $server;
}
return false;
}
- $gserver = dba::selectFirst('gserver', [], ['nurl' => normalise_link($server_url)]);
- if (DBM::is_result($gserver)) {
- if ($gserver["created"] <= NULL_DATE) {
+ $gserver = DBA::selectFirst('gserver', [], ['nurl' => Strings::normaliseLink($server_url)]);
+ if (DBA::isResult($gserver)) {
+ if ($gserver["created"] <= DBA::NULL_DATETIME) {
$fields = ['created' => DateTimeFormat::utcNow()];
- $condition = ['nurl' => normalise_link($server_url)];
- dba::update('gserver', $fields, $condition);
+ $condition = ['nurl' => Strings::normaliseLink($server_url)];
+ DBA::update('gserver', $fields, $condition);
}
$poco = $gserver["poco"];
$noscrape = $gserver["noscrape"];
// See discussion under https://forum.friendi.ca/display/0b6b25a8135aabc37a5a0f5684081633
// It can happen that a zero date is in the database, but storing it again is forbidden.
- if ($last_contact < NULL_DATE) {
- $last_contact = NULL_DATE;
+ if ($last_contact < DBA::NULL_DATETIME) {
+ $last_contact = DBA::NULL_DATETIME;
}
- if ($last_failure < NULL_DATE) {
- $last_failure = NULL_DATE;
+
+ if ($last_failure < DBA::NULL_DATETIME) {
+ $last_failure = DBA::NULL_DATETIME;
}
if (!$force && !self::updateNeeded($gserver["created"], "", $last_failure, $last_contact)) {
- logger("Use cached data for server ".$server_url, LOGGER_DEBUG);
+ Logger::log("Use cached data for server ".$server_url, Logger::DEBUG);
return ($last_contact >= $last_failure);
}
} else {
$register_policy = -1;
$registered_users = 0;
- $last_contact = NULL_DATE;
- $last_failure = NULL_DATE;
+ $last_contact = DBA::NULL_DATETIME;
+ $last_failure = DBA::NULL_DATETIME;
}
- logger("Server ".$server_url." is outdated or unknown. Start discovery. Force: ".$force." Created: ".$gserver["created"]." Failure: ".$last_failure." Contact: ".$last_contact, LOGGER_DEBUG);
+ Logger::log("Server ".$server_url." is outdated or unknown. Start discovery. Force: ".$force." Created: ".$gserver["created"]." Failure: ".$last_failure." Contact: ".$last_contact, Logger::DEBUG);
$failure = false;
$possible_failure = false;
// Mastodon uses the "@" for user profiles.
// But this can be misunderstood.
if (parse_url($server_url, PHP_URL_USER) != '') {
- dba::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => normalise_link($server_url)]);
+ DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => Strings::normaliseLink($server_url)]);
return false;
}
$server_url = str_replace("http://", "https://", $server_url);
// We set the timeout to 20 seconds since this operation should be done in no time if the server was vital
- $serverret = Network::curl($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]);
+ $curlResult = Network::curl($server_url."/.well-known/host-meta", false, ['timeout' => 20]);
// Quit if there is a timeout.
// But we want to make sure to only quit if we are mostly sure that this server url fits.
- if (DBM::is_result($gserver) && ($orig_server_url == $server_url) &&
- ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT)) {
- logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG);
- dba::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => normalise_link($server_url)]);
+ if (DBA::isResult($gserver) && ($orig_server_url == $server_url) &&
+ ($curlResult->isTimeout())) {
+ Logger::log("Connection to server ".$server_url." timed out.", Logger::DEBUG);
+ DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => Strings::normaliseLink($server_url)]);
return false;
}
// Maybe the page is unencrypted only?
- $xmlobj = @simplexml_load_string($serverret["body"], 'SimpleXMLElement', 0, "http://docs.oasis-open.org/ns/xri/xrd-1.0");
- if (!$serverret["success"] || ($serverret["body"] == "") || (@sizeof($xmlobj) == 0) || !is_object($xmlobj)) {
+ $xmlobj = @simplexml_load_string($curlResult->getBody(), 'SimpleXMLElement', 0, "http://docs.oasis-open.org/ns/xri/xrd-1.0");
+ if (!$curlResult->isSuccess() || ($curlResult->getBody() == "") || empty($xmlobj) || !is_object($xmlobj)) {
$server_url = str_replace("https://", "http://", $server_url);
// We set the timeout to 20 seconds since this operation should be done in no time if the server was vital
- $serverret = Network::curl($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]);
+ $curlResult = Network::curl($server_url."/.well-known/host-meta", false, ['timeout' => 20]);
// Quit if there is a timeout
- if ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT) {
- logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG);
- dba::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => normalise_link($server_url)]);
+ if ($curlResult->isTimeout()) {
+ Logger::log("Connection to server " . $server_url . " timed out.", Logger::DEBUG);
+ DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => Strings::normaliseLink($server_url)]);
return false;
}
- $xmlobj = @simplexml_load_string($serverret["body"], 'SimpleXMLElement', 0, "http://docs.oasis-open.org/ns/xri/xrd-1.0");
+ $xmlobj = @simplexml_load_string($curlResult->getBody(), 'SimpleXMLElement', 0, "http://docs.oasis-open.org/ns/xri/xrd-1.0");
}
- if (!$serverret["success"] || ($serverret["body"] == "") || (sizeof($xmlobj) == 0) || !is_object($xmlobj)) {
+ if (!$curlResult->isSuccess() || ($curlResult->getBody() == "") || empty($xmlobj) || !is_object($xmlobj)) {
// Workaround for bad configured servers (known nginx problem)
- if (!in_array($serverret["debug"]["http_code"], ["403", "404"])) {
+ if (!empty($curlResult->getInfo()) && !in_array($curlResult->getInfo()["http_code"], ["403", "404"])) {
$failure = true;
}
+
$possible_failure = true;
}
if (!$failure) {
// This will be too low, but better than no value at all.
- $registered_users = dba::count('gcontact', ['server_url' => normalise_link($server_url)]);
+ $registered_users = DBA::count('gcontact', ['server_url' => Strings::normaliseLink($server_url)]);
}
// Look for poco
if (!$failure) {
- $serverret = Network::curl($server_url."/poco");
- if ($serverret["success"]) {
- $data = json_decode($serverret["body"]);
- if (isset($data->totalResults)) {
- $registered_users = $data->totalResults;
- $poco = $server_url."/poco";
+ $curlResult = Network::curl($server_url."/poco");
+
+ if ($curlResult->isSuccess()) {
+ $data = json_decode($curlResult->getBody(), true);
+
+ if (isset($data['totalResults'])) {
+ $registered_users = $data['totalResults'];
+ $poco = $server_url . "/poco";
$server = self::detectPocoData($data);
- if ($server) {
+
+ if (!empty($server)) {
$platform = $server['platform'];
$network = $server['network'];
$version = '';
$site_name = '';
}
}
- // There are servers out there who don't return 404 on a failure
- // We have to be sure that don't misunderstand this
+
+ /*
+ * There are servers out there who don't return 404 on a failure
+ * We have to be sure that don't misunderstand this
+ */
if (is_null($data)) {
$poco = "";
$noscrape = "";
if (!$failure) {
// Test for Diaspora, Hubzilla, Mastodon or older Friendica servers
- $serverret = Network::curl($server_url);
+ $curlResult = Network::curl($server_url);
- if (!$serverret["success"] || ($serverret["body"] == "")) {
+ if (!$curlResult->isSuccess() || ($curlResult->getBody() == "")) {
$failure = true;
} else {
- $server = self::detectServerType($serverret["body"]);
- if ($server) {
+ $server = self::detectServerType($curlResult->getBody());
+
+ if (!empty($server)) {
$platform = $server['platform'];
$network = $server['network'];
$version = $server['version'];
$site_name = $server['site_name'];
}
- $lines = explode("\n", $serverret["header"]);
+ $lines = explode("\n", $curlResult->getHeader());
+
if (count($lines)) {
foreach ($lines as $line) {
$line = trim($line);
+
if (stristr($line, 'X-Diaspora-Version:')) {
$platform = "Diaspora";
$version = trim(str_replace("X-Diaspora-Version:", "", $line));
$version = trim(str_replace("x-diaspora-version:", "", $version));
- $network = NETWORK_DIASPORA;
+ $network = Protocol::DIASPORA;
$versionparts = explode("-", $version);
$version = $versionparts[0];
}
if (stristr($line, 'Server: Mastodon')) {
$platform = "Mastodon";
- $network = NETWORK_OSTATUS;
+ $network = Protocol::OSTATUS;
}
}
}
// Test for Statusnet
// Will also return data for Friendica and GNU Social - but it will be overwritten later
// The "not implemented" is a special treatment for really, really old Friendica versions
- $serverret = Network::curl($server_url."/api/statusnet/version.json");
- if ($serverret["success"] && ($serverret["body"] != '{"error":"not implemented"}') &&
- ($serverret["body"] != '') && (strlen($serverret["body"]) < 30)) {
+ $curlResult = Network::curl($server_url."/api/statusnet/version.json");
+
+ if ($curlResult->isSuccess() && ($curlResult->getBody() != '{"error":"not implemented"}') &&
+ ($curlResult->getBody() != '') && (strlen($curlResult->getBody()) < 30)) {
$platform = "StatusNet";
// Remove junk that some GNU Social servers return
- $version = str_replace(chr(239).chr(187).chr(191), "", $serverret["body"]);
+ $version = str_replace(chr(239).chr(187).chr(191), "", $curlResult->getBody());
$version = trim($version, '"');
- $network = NETWORK_OSTATUS;
+ $network = Protocol::OSTATUS;
}
// Test for GNU Social
- $serverret = Network::curl($server_url."/api/gnusocial/version.json");
- if ($serverret["success"] && ($serverret["body"] != '{"error":"not implemented"}') &&
- ($serverret["body"] != '') && (strlen($serverret["body"]) < 30)) {
+ $curlResult = Network::curl($server_url."/api/gnusocial/version.json");
+
+ if ($curlResult->isSuccess() && ($curlResult->getBody() != '{"error":"not implemented"}') &&
+ ($curlResult->getBody() != '') && (strlen($curlResult->getBody()) < 30)) {
$platform = "GNU Social";
// Remove junk that some GNU Social servers return
- $version = str_replace(chr(239).chr(187).chr(191), "", $serverret["body"]);
+ $version = str_replace(chr(239) . chr(187) . chr(191), "", $curlResult->getBody());
$version = trim($version, '"');
- $network = NETWORK_OSTATUS;
+ $network = Protocol::OSTATUS;
}
// Test for Mastodon
$orig_version = $version;
- $serverret = Network::curl($server_url."/api/v1/instance");
- if ($serverret["success"] && ($serverret["body"] != '')) {
- $data = json_decode($serverret["body"]);
+ $curlResult = Network::curl($server_url . "/api/v1/instance");
- if (isset($data->version)) {
+ if ($curlResult->isSuccess() && ($curlResult->getBody() != '')) {
+ $data = json_decode($curlResult->getBody(), true);
+
+ if (isset($data['version'])) {
$platform = "Mastodon";
- $version = $data->version;
- $site_name = $data->title;
- $info = $data->description;
- $network = NETWORK_OSTATUS;
+ $version = defaults($data, 'version', '');
+ $site_name = defaults($data, 'title', '');
+ $info = defaults($data, 'description', '');
+ $network = Protocol::OSTATUS;
}
- if (!empty($data->stats->user_count)) {
- $registered_users = $data->stats->user_count;
+
+ if (!empty($data['stats']['user_count'])) {
+ $registered_users = $data['stats']['user_count'];
}
}
- if (strstr($orig_version.$version, 'Pleroma')) {
+
+ if (strstr($orig_version . $version, 'Pleroma')) {
$platform = 'Pleroma';
$version = trim(str_replace('Pleroma', '', $version));
}
if (!$failure) {
// Test for Hubzilla and Red
- $serverret = Network::curl($server_url."/siteinfo.json");
- if ($serverret["success"]) {
- $data = json_decode($serverret["body"]);
- if (isset($data->url)) {
- $platform = $data->platform;
- $version = $data->version;
- $network = NETWORK_DIASPORA;
+ $curlResult = Network::curl($server_url . "/siteinfo.json");
+
+ if ($curlResult->isSuccess()) {
+ $data = json_decode($curlResult->getBody(), true);
+
+ if (isset($data['url'])) {
+ $platform = $data['platform'];
+ $version = $data['version'];
+ $network = Protocol::DIASPORA;
}
- if (!empty($data->site_name)) {
- $site_name = $data->site_name;
+
+ if (!empty($data['site_name'])) {
+ $site_name = $data['site_name'];
}
- if (!empty($data->channels_total)) {
- $registered_users = $data->channels_total;
+
+ if (!empty($data['channels_total'])) {
+ $registered_users = $data['channels_total'];
}
- switch ($data->register_policy) {
- case "REGISTER_OPEN":
- $register_policy = REGISTER_OPEN;
- break;
- case "REGISTER_APPROVE":
- $register_policy = REGISTER_APPROVE;
- break;
- case "REGISTER_CLOSED":
- default:
- $register_policy = REGISTER_CLOSED;
- break;
+
+ if (!empty($data['register_policy'])) {
+ switch ($data['register_policy']) {
+ case "REGISTER_OPEN":
+ $register_policy = Register::OPEN;
+ break;
+
+ case "REGISTER_APPROVE":
+ $register_policy = Register::APPROVE;
+ break;
+
+ case "REGISTER_CLOSED":
+ default:
+ $register_policy = Register::CLOSED;
+ break;
+ }
}
} else {
// Test for Hubzilla, Redmatrix or Friendica
- $serverret = Network::curl($server_url."/api/statusnet/config.json");
- if ($serverret["success"]) {
- $data = json_decode($serverret["body"]);
- if (isset($data->site->server)) {
- if (isset($data->site->platform)) {
- $platform = $data->site->platform->PLATFORM_NAME;
- $version = $data->site->platform->STD_VERSION;
- $network = NETWORK_DIASPORA;
+ $curlResult = Network::curl($server_url."/api/statusnet/config.json");
+
+ if ($curlResult->isSuccess()) {
+ $data = json_decode($curlResult->getBody(), true);
+
+ if (isset($data['site']['server'])) {
+ if (isset($data['site']['platform'])) {
+ $platform = $data['site']['platform']['PLATFORM_NAME'];
+ $version = $data['site']['platform']['STD_VERSION'];
+ $network = Protocol::DIASPORA;
}
- if (isset($data->site->BlaBlaNet)) {
- $platform = $data->site->BlaBlaNet->PLATFORM_NAME;
- $version = $data->site->BlaBlaNet->STD_VERSION;
- $network = NETWORK_DIASPORA;
+
+ if (isset($data['site']['BlaBlaNet'])) {
+ $platform = $data['site']['BlaBlaNet']['PLATFORM_NAME'];
+ $version = $data['site']['BlaBlaNet']['STD_VERSION'];
+ $network = Protocol::DIASPORA;
}
- if (isset($data->site->hubzilla)) {
- $platform = $data->site->hubzilla->PLATFORM_NAME;
- $version = $data->site->hubzilla->RED_VERSION;
- $network = NETWORK_DIASPORA;
+
+ if (isset($data['site']['hubzilla'])) {
+ $platform = $data['site']['hubzilla']['PLATFORM_NAME'];
+ $version = $data['site']['hubzilla']['RED_VERSION'];
+ $network = Protocol::DIASPORA;
}
- if (isset($data->site->redmatrix)) {
- if (isset($data->site->redmatrix->PLATFORM_NAME)) {
- $platform = $data->site->redmatrix->PLATFORM_NAME;
- } elseif (isset($data->site->redmatrix->RED_PLATFORM)) {
- $platform = $data->site->redmatrix->RED_PLATFORM;
+
+ if (isset($data['site']['redmatrix'])) {
+ if (isset($data['site']['redmatrix']['PLATFORM_NAME'])) {
+ $platform = $data['site']['redmatrix']['PLATFORM_NAME'];
+ } elseif (isset($data['site']['redmatrix']['RED_PLATFORM'])) {
+ $platform = $data['site']['redmatrix']['RED_PLATFORM'];
}
- $version = $data->site->redmatrix->RED_VERSION;
- $network = NETWORK_DIASPORA;
+ $version = $data['site']['redmatrix']['RED_VERSION'];
+ $network = Protocol::DIASPORA;
+ }
+
+ if (isset($data['site']['friendica'])) {
+ $platform = $data['site']['friendica']['FRIENDICA_PLATFORM'];
+ $version = $data['site']['friendica']['FRIENDICA_VERSION'];
+ $network = Protocol::DFRN;
}
- if (isset($data->site->friendica)) {
- $platform = $data->site->friendica->FRIENDICA_PLATFORM;
- $version = $data->site->friendica->FRIENDICA_VERSION;
- $network = NETWORK_DFRN;
+
+ $site_name = $data['site']['name'];
+
+ $private = false;
+ $inviteonly = false;
+ $closed = false;
+
+ if (!empty($data['site']['closed'])) {
+ $closed = self::toBoolean($data['site']['closed']);
}
- $site_name = $data->site->name;
+ if (!empty($data['site']['private'])) {
+ $private = self::toBoolean($data['site']['private']);
+ }
- $data->site->closed = self::toBoolean($data->site->closed);
- $data->site->private = self::toBoolean($data->site->private);
- $data->site->inviteonly = self::toBoolean($data->site->inviteonly);
+ if (!empty($data['site']['inviteonly'])) {
+ $inviteonly = self::toBoolean($data['site']['inviteonly']);
+ }
- if (!$data->site->closed && !$data->site->private and $data->site->inviteonly) {
- $register_policy = REGISTER_APPROVE;
- } elseif (!$data->site->closed && !$data->site->private) {
- $register_policy = REGISTER_OPEN;
+ if (!$closed && !$private and $inviteonly) {
+ $register_policy = Register::APPROVE;
+ } elseif (!$closed && !$private) {
+ $register_policy = Register::OPEN;
} else {
- $register_policy = REGISTER_CLOSED;
+ $register_policy = Register::CLOSED;
}
}
}
// Query statistics.json. Optional package for Diaspora, Friendica and Redmatrix
if (!$failure) {
- $serverret = Network::curl($server_url."/statistics.json");
- if ($serverret["success"]) {
- $data = json_decode($serverret["body"]);
+ $curlResult = Network::curl($server_url . "/statistics.json");
- if (isset($data->version)) {
- $version = $data->version;
+ if ($curlResult->isSuccess()) {
+ $data = json_decode($curlResult->getBody(), true);
+
+ if (isset($data['version'])) {
+ $version = $data['version'];
// Version numbers on statistics.json are presented with additional info, e.g.:
// 0.6.3.0-p1702cc1c, 0.6.99.0-p1b9ab160 or 3.4.3-2-1191.
$version = preg_replace("=(.+)-(.{4,})=ism", "$1", $version);
}
- if (!empty($data->name)) {
- $site_name = $data->name;
+ if (!empty($data['name'])) {
+ $site_name = $data['name'];
}
- if (!empty($data->network)) {
- $platform = $data->network;
+ if (!empty($data['network'])) {
+ $platform = $data['network'];
}
if ($platform == "Diaspora") {
- $network = NETWORK_DIASPORA;
+ $network = Protocol::DIASPORA;
}
- if ($data->registrations_open) {
- $register_policy = REGISTER_OPEN;
+ if (!empty($data['registrations_open']) && $data['registrations_open']) {
+ $register_policy = Register::OPEN;
} else {
- $register_policy = REGISTER_CLOSED;
+ $register_policy = Register::CLOSED;
}
}
}
// Query nodeinfo. Working for (at least) Diaspora and Friendica.
if (!$failure) {
$server = self::fetchNodeinfo($server_url);
- if ($server) {
+
+ if (!empty($server)) {
$register_policy = $server['register_policy'];
if (isset($server['platform'])) {
// Check for noscrape
// Friendica servers could be detected as OStatus servers
- if (!$failure && in_array($network, [NETWORK_DFRN, NETWORK_OSTATUS])) {
- $serverret = Network::curl($server_url."/friendica/json");
+ if (!$failure && in_array($network, [Protocol::DFRN, Protocol::OSTATUS])) {
+ $curlResult = Network::curl($server_url . "/friendica/json");
- if (!$serverret["success"]) {
- $serverret = Network::curl($server_url."/friendika/json");
+ if (!$curlResult->isSuccess()) {
+ $curlResult = Network::curl($server_url . "/friendika/json");
}
- if ($serverret["success"]) {
- $data = json_decode($serverret["body"]);
+ if ($curlResult->isSuccess()) {
+ $data = json_decode($curlResult->getBody(), true);
+
+ if (isset($data['version'])) {
+ $network = Protocol::DFRN;
- if (isset($data->version)) {
- $network = NETWORK_DFRN;
+ if (!empty($data['no_scrape_url'])) {
+ $noscrape = $data['no_scrape_url'];
+ }
- $noscrape = defaults($data->no_scrape_url, '');
- $version = $data->version;
- $site_name = $data->site_name;
- $info = $data->info;
- $register_policy_str = $data->register_policy;
- $platform = $data->platform;
+ $version = $data['version'];
- switch ($register_policy_str) {
- case "REGISTER_CLOSED":
- $register_policy = REGISTER_CLOSED;
+ if (!empty($data['site_name'])) {
+ $site_name = $data['site_name'];
+ }
+
+ $info = defaults($data, 'info', '');
+
+ $register_policy = defaults($data, 'register_policy', 'REGISTER_CLOSED');
+ switch ($register_policy) {
+ case 'REGISTER_OPEN':
+ $register_policy = Register::OPEN;
break;
- case "REGISTER_APPROVE":
- $register_policy = REGISTER_APPROVE;
+
+ case 'REGISTER_APPROVE':
+ $register_policy = Register::APPROVE;
break;
- case "REGISTER_OPEN":
- $register_policy = REGISTER_OPEN;
+
+ default:
+ Logger::log("Register policy '$register_policy' from $server_url is invalid.");
+ // Defaulting to closed
+
+ case 'REGISTER_CLOSED':
+ case 'REGISTER_INVITATION':
+ $register_policy = Register::CLOSED;
break;
}
+
+ $platform = defaults($data, 'platform', '');
}
}
}
}
if (($last_contact <= $last_failure) && !$failure) {
- logger("Server ".$server_url." seems to be alive, but last contact wasn't set - could be a bug", LOGGER_DEBUG);
+ Logger::log("Server ".$server_url." seems to be alive, but last contact wasn't set - could be a bug", Logger::DEBUG);
} elseif (($last_contact >= $last_failure) && $failure) {
- logger("Server ".$server_url." seems to be dead, but last failure wasn't set - could be a bug", LOGGER_DEBUG);
+ Logger::log("Server ".$server_url." seems to be dead, but last failure wasn't set - could be a bug", Logger::DEBUG);
}
// Check again if the server exists
- $found = dba::exists('gserver', ['nurl' => normalise_link($server_url)]);
+ $found = DBA::exists('gserver', ['nurl' => Strings::normaliseLink($server_url)]);
$version = strip_tags($version);
$site_name = strip_tags($site_name);
'last_contact' => $last_contact, 'last_failure' => $last_failure];
if ($found) {
- dba::update('gserver', $fields, ['nurl' => normalise_link($server_url)]);
+ DBA::update('gserver', $fields, ['nurl' => Strings::normaliseLink($server_url)]);
} elseif (!$failure) {
- $fields['nurl'] = normalise_link($server_url);
+ $fields['nurl'] = Strings::normaliseLink($server_url);
$fields['created'] = DateTimeFormat::utcNow();
- dba::insert('gserver', $fields);
+ DBA::insert('gserver', $fields);
}
- if (!$failure && in_array($fields['network'], [NETWORK_DFRN, NETWORK_DIASPORA])) {
+ if (!$failure && in_array($fields['network'], [Protocol::DFRN, Protocol::DIASPORA])) {
self::discoverRelay($server_url);
}
- logger("End discovery for server " . $server_url, LOGGER_DEBUG);
+ Logger::log("End discovery for server " . $server_url, Logger::DEBUG);
return !$failure;
}
* @brief Fetch relay data from a given server url
*
* @param string $server_url address of the server
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function discoverRelay($server_url)
{
- logger("Discover relay data for server " . $server_url, LOGGER_DEBUG);
+ Logger::log("Discover relay data for server " . $server_url, Logger::DEBUG);
+
+ $curlResult = Network::curl($server_url . "/.well-known/x-social-relay");
- $serverret = Network::curl($server_url."/.well-known/x-social-relay");
- if (!$serverret["success"]) {
+ if (!$curlResult->isSuccess()) {
return;
}
- $data = json_decode($serverret['body']);
- if (!is_object($data)) {
+ $data = json_decode($curlResult->getBody(), true);
+
+ if (!is_array($data)) {
return;
}
- $gserver = dba::selectFirst('gserver', ['id', 'relay-subscribe', 'relay-scope'], ['nurl' => normalise_link($server_url)]);
- if (!DBM::is_result($gserver)) {
+ $gserver = DBA::selectFirst('gserver', ['id', 'relay-subscribe', 'relay-scope'], ['nurl' => Strings::normaliseLink($server_url)]);
+
+ if (!DBA::isResult($gserver)) {
return;
}
- if (($gserver['relay-subscribe'] != $data->subscribe) || ($gserver['relay-scope'] != $data->scope)) {
- $fields = ['relay-subscribe' => $data->subscribe, 'relay-scope' => $data->scope];
- dba::update('gserver', $fields, ['id' => $gserver['id']]);
+ if (($gserver['relay-subscribe'] != $data['subscribe']) || ($gserver['relay-scope'] != $data['scope'])) {
+ $fields = ['relay-subscribe' => $data['subscribe'], 'relay-scope' => $data['scope']];
+ DBA::update('gserver', $fields, ['id' => $gserver['id']]);
}
- dba::delete('gserver-tag', ['gserver-id' => $gserver['id']]);
- if ($data->scope == 'tags') {
+ DBA::delete('gserver-tag', ['gserver-id' => $gserver['id']]);
+
+ if ($data['scope'] == 'tags') {
// Avoid duplicates
$tags = [];
- foreach ($data->tags as $tag) {
+ foreach ($data['tags'] as $tag) {
$tag = mb_strtolower($tag);
- $tags[$tag] = $tag;
+ if (strlen($tag) < 100) {
+ $tags[$tag] = $tag;
+ }
}
foreach ($tags as $tag) {
- dba::insert('gserver-tag', ['gserver-id' => $gserver['id'], 'tag' => $tag]);
+ DBA::insert('gserver-tag', ['gserver-id' => $gserver['id'], 'tag' => $tag], true);
}
}
// Create or update the relay contact
$fields = [];
- if (isset($data->protocols)) {
- if (isset($data->protocols->diaspora)) {
- $fields['network'] = NETWORK_DIASPORA;
- if (isset($data->protocols->diaspora->receive)) {
- $fields['batch'] = $data->protocols->diaspora->receive;
- } elseif (is_string($data->protocols->diaspora)) {
- $fields['batch'] = $data->protocols->diaspora;
+ if (isset($data['protocols'])) {
+ if (isset($data['protocols']['diaspora'])) {
+ $fields['network'] = Protocol::DIASPORA;
+
+ if (isset($data['protocols']['diaspora']['receive'])) {
+ $fields['batch'] = $data['protocols']['diaspora']['receive'];
+ } elseif (is_string($data['protocols']['diaspora'])) {
+ $fields['batch'] = $data['protocols']['diaspora'];
}
}
- if (isset($data->protocols->dfrn)) {
- $fields['network'] = NETWORK_DFRN;
- if (isset($data->protocols->dfrn->receive)) {
- $fields['batch'] = $data->protocols->dfrn->receive;
- } elseif (is_string($data->protocols->dfrn)) {
- $fields['batch'] = $data->protocols->dfrn;
+
+ if (isset($data['protocols']['dfrn'])) {
+ $fields['network'] = Protocol::DFRN;
+
+ if (isset($data['protocols']['dfrn']['receive'])) {
+ $fields['batch'] = $data['protocols']['dfrn']['receive'];
+ } elseif (is_string($data['protocols']['dfrn'])) {
+ $fields['batch'] = $data['protocols']['dfrn'];
}
}
}
/**
* @brief Returns a list of all known servers
* @return array List of server urls
+ * @throws Exception
*/
public static function serverlist()
{
WHERE `network` IN ('%s', '%s', '%s') AND `last_contact` > `last_failure`
ORDER BY `last_contact`
LIMIT 1000",
- dbesc(NETWORK_DFRN),
- dbesc(NETWORK_DIASPORA),
- dbesc(NETWORK_OSTATUS)
+ DBA::escape(Protocol::DFRN),
+ DBA::escape(Protocol::DIASPORA),
+ DBA::escape(Protocol::OSTATUS)
);
- if (!DBM::is_result($r)) {
+ if (!DBA::isResult($r)) {
return false;
}
* @brief Fetch server list from remote servers and adds them when they are new.
*
* @param string $poco URL to the POCO endpoint
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function fetchServerlist($poco)
{
- $serverret = Network::curl($poco."/@server");
- if (!$serverret["success"]) {
+ $curlResult = Network::curl($poco . "/@server");
+
+ if (!$curlResult->isSuccess()) {
return;
}
- $serverlist = json_decode($serverret['body']);
+
+ $serverlist = json_decode($curlResult->getBody(), true);
if (!is_array($serverlist)) {
return;
}
foreach ($serverlist as $server) {
- $server_url = str_replace("/index.php", "", $server->url);
+ $server_url = str_replace("/index.php", "", $server['url']);
+
+ $r = q("SELECT `nurl` FROM `gserver` WHERE `nurl` = '%s'", DBA::escape(Strings::normaliseLink($server_url)));
- $r = q("SELECT `nurl` FROM `gserver` WHERE `nurl` = '%s'", dbesc(normalise_link($server_url)));
- if (!DBM::is_result($r)) {
- logger("Call server check for server ".$server_url, LOGGER_DEBUG);
+ if (!DBA::isResult($r)) {
+ Logger::log("Call server check for server ".$server_url, Logger::DEBUG);
Worker::add(PRIORITY_LOW, "DiscoverPoCo", "server", $server_url);
}
}
if ($last) {
$next = $last + (24 * 60 * 60);
+
if ($next > time()) {
return;
}
}
// Discover Friendica, Hubzilla and Diaspora servers
- $serverdata = Network::fetchUrl("http://the-federation.info/pods.json");
+ $curlResult = Network::fetchUrl("http://the-federation.info/pods.json");
- if ($serverdata) {
- $servers = json_decode($serverdata);
+ if (!empty($curlResult)) {
+ $servers = json_decode($curlResult, true);
- foreach ($servers->pods as $server) {
- Worker::add(PRIORITY_LOW, "DiscoverPoCo", "server", "https://".$server->host);
+ if (!empty($servers['pods'])) {
+ foreach ($servers['pods'] as $server) {
+ Worker::add(PRIORITY_LOW, "DiscoverPoCo", "server", "https://" . $server['host']);
+ }
}
}
// Disvover Mastodon servers
if (!Config::get('system', 'ostatus_disabled')) {
$accesstoken = Config::get('system', 'instances_social_key');
+
if (!empty($accesstoken)) {
$api = 'https://instances.social/api/1.0/instances/list?count=0';
$header = ['Authorization: Bearer '.$accesstoken];
- $serverdata = Network::curl($api, false, $redirects, ['headers' => $header]);
- if ($serverdata['success']) {
- $servers = json_decode($serverdata['body']);
- foreach ($servers->instances as $server) {
- $url = (is_null($server->https_score) ? 'http' : 'https').'://'.$server->name;
+ $curlResult = Network::curl($api, false, ['headers' => $header]);
+
+ if ($curlResult->isSuccess()) {
+ $servers = json_decode($curlResult->getBody(), true);
+
+ foreach ($servers['instances'] as $server) {
+ $url = (is_null($server['https_score']) ? 'http' : 'https') . '://' . $server['name'];
Worker::add(PRIORITY_LOW, "DiscoverPoCo", "server", $url);
}
}
//if (!Config::get('system','ostatus_disabled')) {
// $serverdata = "http://gstools.org/api/get_open_instances/";
- // $result = Network::curl($serverdata);
- // if ($result["success"]) {
- // $servers = json_decode($result["body"]);
+ // $curlResult = Network::curl($serverdata);
+ // if ($curlResult->isSuccess()) {
+ // $servers = json_decode($result->getBody(), true);
- // foreach($servers->data as $server)
- // self::checkServer($server->instance_address);
+ // foreach($servers['data'] as $server)
+ // self::checkServer($server['instance_address']);
// }
//}
public static function discoverSingleServer($id)
{
- $r = q("SELECT `poco`, `nurl`, `url`, `network` FROM `gserver` WHERE `id` = %d", intval($id));
- if (!DBM::is_result($r)) {
+ $server = DBA::selectFirst('gserver', ['poco', 'nurl', 'url', 'network'], ['id' => $id]);
+
+ if (!DBA::isResult($server)) {
return false;
}
- $server = $r[0];
-
// Discover new servers out there (Works from Friendica version 3.5.2)
self::fetchServerlist($server["poco"]);
// Fetch all users from the other server
- $url = $server["poco"]."/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation";
+ $url = $server["poco"] . "/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation";
- logger("Fetch all users from the server ".$server["url"], LOGGER_DEBUG);
+ Logger::info("Fetch all users from the server " . $server["url"]);
- $retdata = Network::curl($url);
- if ($retdata["success"]) {
- $data = json_decode($retdata["body"]);
+ $curlResult = Network::curl($url);
- self::discoverServer($data, 2);
+ if ($curlResult->isSuccess() && !empty($curlResult->getBody())) {
+ $data = json_decode($curlResult->getBody(), true);
- if (Config::get('system', 'poco_discovery') > 1) {
+ if (!empty($data)) {
+ self::discoverServer($data, 2);
+ }
+
+ if (Config::get('system', 'poco_discovery') >= self::USERS_GCONTACTS) {
$timeframe = Config::get('system', 'poco_discovery_since');
+
if ($timeframe == 0) {
$timeframe = 30;
}
$success = false;
- $retdata = Network::curl($url);
- if ($retdata["success"]) {
- logger("Fetch all global contacts from the server ".$server["nurl"], LOGGER_DEBUG);
- $success = self::discoverServer(json_decode($retdata["body"]));
+ $curlResult = Network::curl($url);
+
+ if ($curlResult->isSuccess() && !empty($curlResult->getBody())) {
+ Logger::info("Fetch all global contacts from the server " . $server["nurl"]);
+ $data = json_decode($curlResult->getBody(), true);
+
+ if (!empty($data)) {
+ $success = self::discoverServer($data);
+ }
}
- if (!$success && (Config::get('system', 'poco_discovery') > 2)) {
- logger("Fetch contacts from users of the server ".$server["nurl"], LOGGER_DEBUG);
+ if (!$success && !empty($data) && Config::get('system', 'poco_discovery') >= self::USERS_GCONTACTS_FALLBACK) {
+ Logger::info("Fetch contacts from users of the server " . $server["nurl"]);
self::discoverServerUsers($data, $server);
}
}
$fields = ['last_poco_query' => DateTimeFormat::utcNow()];
- dba::update('gserver', $fields, ['nurl' => $server["nurl"]]);
+ DBA::update('gserver', $fields, ['nurl' => $server["nurl"]]);
return true;
} else {
// If we couldn't reach the server, we will try it some time later
$fields = ['last_poco_query' => DateTimeFormat::utcNow()];
- dba::update('gserver', $fields, ['nurl' => $server["nurl"]]);
+ DBA::update('gserver', $fields, ['nurl' => $server["nurl"]]);
return false;
}
$no_of_queries = 5;
- $requery_days = intval(Config::get("system", "poco_requery_days"));
+ $requery_days = intval(Config::get('system', 'poco_requery_days'));
if ($requery_days == 0) {
$requery_days = 7;
}
- $last_update = date("c", time() - (60 * 60 * 24 * $requery_days));
- $r = q("SELECT `id`, `url`, `network` FROM `gserver` WHERE `last_contact` >= `last_failure` AND `poco` != '' AND `last_poco_query` < '%s' ORDER BY RAND()", dbesc($last_update));
- if (DBM::is_result($r)) {
- foreach ($r as $server) {
- if (!self::checkServer($server["url"], $server["network"])) {
+ $last_update = date('c', time() - (60 * 60 * 24 * $requery_days));
+
+ $gservers = q("SELECT `id`, `url`, `nurl`, `network`
+ FROM `gserver`
+ WHERE `last_contact` >= `last_failure`
+ AND `poco` != ''
+ AND `last_poco_query` < '%s'
+ ORDER BY RAND()", DBA::escape($last_update)
+ );
+
+ if (DBA::isResult($gservers)) {
+ foreach ($gservers as $gserver) {
+ if (!self::checkServer($gserver['url'], $gserver['network'])) {
// The server is not reachable? Okay, then we will try it later
$fields = ['last_poco_query' => DateTimeFormat::utcNow()];
- dba::update('gserver', $fields, ['nurl' => $server["nurl"]]);
+ DBA::update('gserver', $fields, ['nurl' => $gserver['nurl']]);
continue;
}
- logger('Update directory from server '.$server['url'].' with ID '.$server['id'], LOGGER_DEBUG);
- Worker::add(PRIORITY_LOW, "DiscoverPoCo", "update_server_directory", (int)$server['id']);
+ Logger::log('Update directory from server ' . $gserver['url'] . ' with ID ' . $gserver['id'], Logger::DEBUG);
+ Worker::add(PRIORITY_LOW, 'DiscoverPoCo', 'update_server_directory', (int) $gserver['id']);
- if (!$complete && (--$no_of_queries == 0)) {
+ if (!$complete && ( --$no_of_queries == 0)) {
break;
}
}
}
}
- private static function discoverServerUsers($data, $server)
+ private static function discoverServerUsers(array $data, array $server)
{
- if (!isset($data->entry)) {
+ if (!isset($data['entry'])) {
return;
}
- foreach ($data->entry as $entry) {
- $username = "";
- if (isset($entry->urls)) {
- foreach ($entry->urls as $url) {
- if ($url->type == 'profile') {
- $profile_url = $url->value;
- $urlparts = parse_url($profile_url);
- $username = end(explode("/", $urlparts["path"]));
+ foreach ($data['entry'] as $entry) {
+ $username = '';
+
+ if (isset($entry['urls'])) {
+ foreach ($entry['urls'] as $url) {
+ if ($url['type'] == 'profile') {
+ $profile_url = $url['value'];
+ $path_array = explode('/', parse_url($profile_url, PHP_URL_PATH));
+ $username = end($path_array);
}
}
}
- if ($username != "") {
- logger("Fetch contacts for the user ".$username." from the server ".$server["nurl"], LOGGER_DEBUG);
+
+ if ($username != '') {
+ Logger::log('Fetch contacts for the user ' . $username . ' from the server ' . $server['nurl'], Logger::DEBUG);
// Fetch all contacts from a given user from the other server
- $url = $server["poco"]."/".$username."/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation";
+ $url = $server['poco'] . '/' . $username . '/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation';
+
+ $curlResult = Network::curl($url);
- $retdata = Network::curl($url);
- if ($retdata["success"]) {
- self::discoverServer(json_decode($retdata["body"]), 3);
+ if ($curlResult->isSuccess()) {
+ $data = json_decode($curlResult->getBody(), true);
+
+ if (!empty($data)) {
+ self::discoverServer($data, 3);
+ }
}
}
}
}
- private static function discoverServer($data, $default_generation = 0)
+ private static function discoverServer(array $data, $default_generation = 0)
{
- if (!isset($data->entry) || !count($data->entry)) {
+ if (empty($data['entry'])) {
return false;
}
$success = false;
- foreach ($data->entry as $entry) {
+ foreach ($data['entry'] as $entry) {
$profile_url = '';
$profile_photo = '';
$connect_url = '';
$name = '';
$network = '';
- $updated = NULL_DATE;
+ $updated = DBA::NULL_DATETIME;
$location = '';
$about = '';
$keywords = '';
$contact_type = -1;
$generation = $default_generation;
- $name = $entry->displayName;
+ if (!empty($entry['displayName'])) {
+ $name = $entry['displayName'];
+ }
- if (isset($entry->urls)) {
- foreach ($entry->urls as $url) {
- if ($url->type == 'profile') {
- $profile_url = $url->value;
+ if (isset($entry['urls'])) {
+ foreach ($entry['urls'] as $url) {
+ if ($url['type'] == 'profile') {
+ $profile_url = $url['value'];
continue;
}
- if ($url->type == 'webfinger') {
- $connect_url = str_replace('acct:' , '', $url->value);
+ if ($url['type'] == 'webfinger') {
+ $connect_url = str_replace('acct:' , '', $url['value']);
continue;
}
}
}
- if (isset($entry->photos)) {
- foreach ($entry->photos as $photo) {
- if ($photo->type == 'profile') {
- $profile_photo = $photo->value;
+ if (isset($entry['photos'])) {
+ foreach ($entry['photos'] as $photo) {
+ if ($photo['type'] == 'profile') {
+ $profile_photo = $photo['value'];
continue;
}
}
}
- if (isset($entry->updated)) {
- $updated = date(DateTimeFormat::MYSQL, strtotime($entry->updated));
+ if (isset($entry['updated'])) {
+ $updated = date(DateTimeFormat::MYSQL, strtotime($entry['updated']));
}
- if (isset($entry->network)) {
- $network = $entry->network;
+ if (isset($entry['network'])) {
+ $network = $entry['network'];
}
- if (isset($entry->currentLocation)) {
- $location = $entry->currentLocation;
+ if (isset($entry['currentLocation'])) {
+ $location = $entry['currentLocation'];
}
- if (isset($entry->aboutMe)) {
- $about = HTML::toBBCode($entry->aboutMe);
+ if (isset($entry['aboutMe'])) {
+ $about = HTML::toBBCode($entry['aboutMe']);
}
- if (isset($entry->gender)) {
- $gender = $entry->gender;
+ if (isset($entry['gender'])) {
+ $gender = $entry['gender'];
}
- if (isset($entry->generation) && ($entry->generation > 0)) {
- $generation = ++$entry->generation;
+ if (isset($entry['generation']) && ($entry['generation'] > 0)) {
+ $generation = ++$entry['generation'];
}
- if (isset($entry->contactType) && ($entry->contactType >= 0)) {
- $contact_type = $entry->contactType;
+ if (isset($entry['contactType']) && ($entry['contactType'] >= 0)) {
+ $contact_type = $entry['contactType'];
}
- if (isset($entry->tags)) {
- foreach ($entry->tags as $tag) {
+ if (isset($entry['tags'])) {
+ foreach ($entry['tags'] as $tag) {
$keywords = implode(", ", $tag);
}
}
if ($generation > 0) {
$success = true;
- logger("Store profile ".$profile_url, LOGGER_DEBUG);
+ Logger::log("Store profile ".$profile_url, Logger::DEBUG);
$gcontact = ["url" => $profile_url,
"name" => $name,
$gcontact = GContact::sanitize($gcontact);
GContact::update($gcontact);
} catch (Exception $e) {
- logger($e->getMessage(), LOGGER_DEBUG);
+ Logger::log($e->getMessage(), Logger::DEBUG);
}
- logger("Done for profile ".$profile_url, LOGGER_DEBUG);
+ Logger::log("Done for profile ".$profile_url, Logger::DEBUG);
}
}
return $success;