3 * @file src/Network/Probe.php
5 namespace Friendica\Network;
8 * @file src/Network/Probe.php
9 * @brief Functions for probing URL
14 use Friendica\Core\Cache;
15 use Friendica\Core\Config;
16 use Friendica\Core\Logger;
17 use Friendica\Core\Protocol;
18 use Friendica\Core\System;
19 use Friendica\Database\DBA;
20 use Friendica\Model\Contact;
21 use Friendica\Model\Profile;
22 use Friendica\Protocol\ActivityPub;
23 use Friendica\Protocol\Email;
24 use Friendica\Protocol\Feed;
25 use Friendica\Util\Crypto;
26 use Friendica\Util\DateTimeFormat;
27 use Friendica\Util\Network;
28 use Friendica\Util\Strings;
29 use Friendica\Util\XML;
32 * @brief This class contain functions for probing URL
37 private static $baseurl;
38 private static $istimeout;
41 * @brief Rearrange the array so that it always has the same order
43 * @param array $data Unordered data
45 * @return array Ordered data
47 private static function rearrangeData($data)
49 $fields = ["name", "nick", "guid", "url", "addr", "alias",
50 "photo", "community", "keywords", "location", "about",
51 "batch", "notify", "poll", "request", "confirm", "poco",
52 "priority", "network", "pubkey", "baseurl"];
55 foreach ($fields as $field) {
56 if (isset($data[$field])) {
57 $newdata[$field] = $data[$field];
59 $newdata[$field] = "";
63 // We don't use the "priority" field anymore and replace it with a dummy.
64 $newdata["priority"] = 0;
70 * @brief Check if the hostname belongs to the own server
72 * @param string $host The hostname that is to be checked
74 * @return bool Does the testes hostname belongs to the own server?
76 private static function ownHost($host)
78 $own_host = \get_app()->getHostName();
80 $parts = parse_url($host);
82 if (!isset($parts['scheme'])) {
83 $parts = parse_url('http://'.$host);
86 if (!isset($parts['host'])) {
89 return $parts['host'] == $own_host;
93 * @brief Probes for webfinger path via "host-meta"
95 * We have to check if the servers in the future still will offer this.
96 * It seems as if it was dropped from the standard.
98 * @param string $host The host part of an url
100 * @return array with template and type of the webfinger template for JSON or XML
101 * @throws HTTPException\InternalServerErrorException
103 private static function hostMeta($host)
105 // Reset the static variable
108 $ssl_url = "https://".$host."/.well-known/host-meta";
109 $url = "http://".$host."/.well-known/host-meta";
111 $xrd_timeout = Config::get('system', 'xrd_timeout', 20);
114 Logger::log("Probing for ".$host, Logger::DEBUG);
117 $curlResult = Network::curl($ssl_url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
118 if ($curlResult->isSuccess()) {
119 $xml = $curlResult->getBody();
120 $xrd = XML::parseString($xml, false);
121 $host_url = 'https://'.$host;
124 if (!is_object($xrd)) {
125 $curlResult = Network::curl($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
126 if ($curlResult->isTimeout()) {
127 Logger::log("Probing timeout for " . $url, Logger::DEBUG);
128 self::$istimeout = true;
131 $xml = $curlResult->getBody();
132 $xrd = XML::parseString($xml, false);
133 $host_url = 'http://'.$host;
135 if (!is_object($xrd)) {
136 Logger::log("No xrd object found for ".$host, Logger::DEBUG);
140 $links = XML::elementToArray($xrd);
141 if (!isset($links["xrd"]["link"])) {
142 Logger::log("No xrd data found for ".$host, Logger::DEBUG);
147 // The following webfinger path is defined in RFC 7033 https://tools.ietf.org/html/rfc7033
148 // Problem is that Hubzilla currently doesn't provide all data in the JSON webfinger
149 // compared to the XML webfinger. So this is commented out by now.
150 // $lrdd = array("application/jrd+json" => $host_url.'/.well-known/webfinger?resource={uri}');
152 foreach ($links["xrd"]["link"] as $value => $link) {
153 if (!empty($link["@attributes"])) {
154 $attributes = $link["@attributes"];
155 } elseif ($value == "@attributes") {
161 if (!empty($attributes["rel"]) && $attributes["rel"] == "lrdd" && !empty($attributes["template"])) {
162 $type = (empty($attributes["type"]) ? '' : $attributes["type"]);
164 $lrdd[$type] = $attributes["template"];
168 self::$baseurl = $host_url;
170 Logger::log("Probing successful for ".$host, Logger::DEBUG);
176 * @brief Perform Webfinger lookup and return DFRN data
178 * Given an email style address, perform webfinger lookup and
179 * return the resulting DFRN profile URL, or if no DFRN profile URL
180 * is located, returns an OStatus subscription template (prefixed
181 * with the string 'stat:' to identify it as on OStatus template).
182 * If this isn't an email style address just return $webbie.
183 * Return an empty string if email-style addresses but webfinger fails,
184 * or if the resultant personal XRD doesn't contain a supported
185 * subscription/friend-request attribute.
187 * amended 7/9/2011 to return an hcard which could save potentially loading
188 * a lengthy content page to scrape dfrn attributes
190 * @param string $webbie Address that should be probed
191 * @param string $hcard_url Link to the hcard - is returned by reference
193 * @return string profile link
194 * @throws HTTPException\InternalServerErrorException
196 public static function webfingerDfrn($webbie, &$hcard_url)
200 $links = self::lrdd($webbie);
201 Logger::log('webfingerDfrn: '.$webbie.':'.print_r($links, true), Logger::DATA);
203 foreach ($links as $link) {
204 if ($link['@attributes']['rel'] === NAMESPACE_DFRN) {
205 $profile_link = $link['@attributes']['href'];
207 if (($link['@attributes']['rel'] === NAMESPACE_OSTATUSSUB) && ($profile_link == "")) {
208 $profile_link = 'stat:'.$link['@attributes']['template'];
210 if ($link['@attributes']['rel'] === 'http://microformats.org/profile/hcard') {
211 $hcard_url = $link['@attributes']['href'];
215 return $profile_link;
219 * @brief Check an URI for LRDD data
221 * this is a replacement for the "lrdd" function.
222 * It isn't used in this class and has some redundancies in the code.
223 * When time comes we can check the existing calls for "lrdd" if we can rework them.
225 * @param string $uri Address that should be probed
227 * @return array uri data
228 * @throws HTTPException\InternalServerErrorException
230 public static function lrdd($uri)
232 $lrdd = self::hostMeta($uri);
235 if (is_bool($lrdd)) {
240 $parts = @parse_url($uri);
241 if (!$parts || empty($parts["host"]) || empty($parts["path"])) {
245 $host = $parts["host"];
246 if (!empty($parts["port"])) {
247 $host .= ':'.$parts["port"];
250 $path_parts = explode("/", trim($parts["path"], "/"));
252 $nick = array_pop($path_parts);
255 $lrdd = self::hostMeta($host);
256 $host .= "/".array_shift($path_parts);
257 } while (!$lrdd && (sizeof($path_parts) > 0));
261 Logger::log("No lrdd data found for ".$uri, Logger::DEBUG);
265 foreach ($lrdd as $type => $template) {
270 $path = str_replace('{uri}', urlencode($uri), $template);
271 $webfinger = self::webfinger($path, $type);
273 if (!$webfinger && (strstr($uri, "@"))) {
274 $path = str_replace('{uri}', urlencode("acct:".$uri), $template);
275 $webfinger = self::webfinger($path, $type);
278 // Special treatment for Mastodon
279 // Problem is that Mastodon uses an URL format like http://domain.tld/@nick
280 // But the webfinger for this format fails.
281 if (!$webfinger && !empty($nick)) {
282 // Mastodon uses a "@" as prefix for usernames in their url format
283 $nick = ltrim($nick, '@');
285 $addr = $nick."@".$host;
287 $path = str_replace('{uri}', urlencode("acct:".$addr), $template);
288 $webfinger = self::webfinger($path, $type);
292 if (!is_array($webfinger["links"])) {
293 Logger::log("No webfinger links found for ".$uri, Logger::DEBUG);
299 foreach ($webfinger["links"] as $link) {
300 $data[] = ["@attributes" => $link];
303 if (is_array($webfinger["aliases"])) {
304 foreach ($webfinger["aliases"] as $alias) {
305 $data[] = ["@attributes" =>
315 * @brief Fetch information (protocol endpoints and user information) about a given uri
317 * @param string $uri Address that should be probed
318 * @param string $network Test for this specific network
319 * @param integer $uid User ID for the probe (only used for mails)
320 * @param boolean $cache Use cached values?
322 * @return array uri data
323 * @throws HTTPException\InternalServerErrorException
324 * @throws \ImagickException
326 public static function uri($uri, $network = '', $uid = -1, $cache = true)
329 $result = Cache::get('Probe::uri:' . $network . ':' . $uri);
330 if (!is_null($result)) {
339 self::$istimeout = false;
341 if ($network != Protocol::ACTIVITYPUB) {
342 $data = self::detect($uri, $network, $uid);
347 // When the previous detection process had got a time out
348 // we could falsely detect a Friendica profile as AP profile.
349 if (!self::$istimeout) {
350 $ap_profile = ActivityPub::probeProfile($uri);
352 if (!empty($ap_profile) && empty($network) && (defaults($data, 'network', '') != Protocol::DFRN)) {
356 Logger::notice('Time out detected. AP will not be probed.', ['uri' => $uri]);
359 if (!isset($data['url'])) {
363 if (!empty($data['photo'])) {
364 $data['baseurl'] = Network::getUrlMatch(Strings::normaliseLink(defaults($data, 'baseurl', '')), Strings::normaliseLink($data['photo']));
366 $data['photo'] = System::baseUrl() . '/images/person-300.jpg';
369 if (empty($data['name'])) {
370 if (!empty($data['nick'])) {
371 $data['name'] = $data['nick'];
374 if (empty($data['name'])) {
375 $data['name'] = $data['url'];
379 if (empty($data['nick'])) {
380 $data['nick'] = strtolower($data['name']);
382 if (strpos($data['nick'], ' ')) {
383 $data['nick'] = trim(substr($data['nick'], 0, strpos($data['nick'], ' ')));
387 if (!empty(self::$baseurl)) {
388 $data['baseurl'] = self::$baseurl;
391 if (empty($data['network'])) {
392 $data['network'] = Protocol::PHANTOM;
395 $data = self::rearrangeData($data);
397 // Only store into the cache if the value seems to be valid
398 if (!in_array($data['network'], [Protocol::PHANTOM, Protocol::MAIL])) {
399 Cache::set('Probe::uri:' . $network . ':' . $uri, $data, Cache::DAY);
401 /// @todo temporary fix - we need a real contact update function that updates only changing fields
402 /// The biggest problem is the avatar picture that could have a reduced image size.
403 /// It should only be updated if the existing picture isn't existing anymore.
404 /// We only update the contact when it is no probing for a specific network.
405 if (($data['network'] != Protocol::FEED)
414 'name' => $data['name'],
415 'nick' => $data['nick'],
416 'url' => $data['url'],
417 'addr' => $data['addr'],
418 'photo' => $data['photo'],
419 'keywords' => $data['keywords'],
420 'location' => $data['location'],
421 'about' => $data['about'],
422 'notify' => $data['notify'],
423 'network' => $data['network'],
424 'server_url' => $data['baseurl']
427 // This doesn't cover the case when a community isn't a community anymore
428 if (!empty($data['community']) && $data['community']) {
429 $fields['community'] = $data['community'];
430 $fields['contact-type'] = Contact::TYPE_COMMUNITY;
435 foreach ($fields as $key => $val) {
437 unset($fields[$key]);
439 $fieldnames[] = $key;
443 $fields['updated'] = DateTimeFormat::utcNow();
445 $condition = ['nurl' => Strings::normaliseLink($data['url'])];
447 $old_fields = DBA::selectFirst('gcontact', $fieldnames, $condition);
449 // When the gcontact doesn't exist, the value "true" will trigger an insert.
450 // In difference to the public contacts we want to have every contact
451 // in the world in our global contacts.
455 // These values have to be set only on insert
456 $fields['photo'] = $data['photo'];
457 $fields['created'] = DateTimeFormat::utcNow();
460 DBA::update('gcontact', $fields, $condition, $old_fields);
463 'name' => $data['name'],
464 'nick' => $data['nick'],
465 'url' => $data['url'],
466 'addr' => $data['addr'],
467 'alias' => $data['alias'],
468 'keywords' => $data['keywords'],
469 'location' => $data['location'],
470 'about' => $data['about'],
471 'batch' => $data['batch'],
472 'notify' => $data['notify'],
473 'poll' => $data['poll'],
474 'request' => $data['request'],
475 'confirm' => $data['confirm'],
476 'poco' => $data['poco'],
477 'network' => $data['network'],
478 'pubkey' => $data['pubkey'],
479 'priority' => $data['priority'],
481 'rel' => Contact::SHARING
486 foreach ($fields as $key => $val) {
488 unset($fields[$key]);
490 $fieldnames[] = $key;
494 $condition = ['nurl' => Strings::normaliseLink($data['url']), 'self' => false, 'uid' => 0];
496 // "$old_fields" will return a "false" when the contact doesn't exist.
497 // This won't trigger an insert. This is intended, since we only need
498 // public contacts for everyone we store items from.
499 // We don't need to store every contact on the planet.
500 $old_fields = DBA::selectFirst('contact', $fieldnames, $condition);
502 $fields['name-date'] = DateTimeFormat::utcNow();
503 $fields['uri-date'] = DateTimeFormat::utcNow();
504 $fields['success_update'] = DateTimeFormat::utcNow();
506 DBA::update('contact', $fields, $condition, $old_fields);
514 * @brief Checks if a profile url should be OStatus but only provides partial information
516 * @param array $webfinger Webfinger data
517 * @param string $lrdd Path template for webfinger request
518 * @param string $type type
520 * @return array fixed webfinger data
521 * @throws HTTPException\InternalServerErrorException
523 private static function fixOStatus($webfinger, $lrdd, $type)
525 if (empty($webfinger['links']) || empty($webfinger['subject'])) {
532 foreach ($webfinger['links'] as $link) {
533 if ($link['rel'] == NAMESPACE_OSTATUSSUB) {
536 if ($link['rel'] == 'magic-public-key') {
541 if (!$is_ostatus || $has_key) {
545 $url = Network::switchScheme($webfinger['subject']);
546 $path = str_replace('{uri}', urlencode($url), $lrdd);
547 $webfinger2 = self::webfinger($path, $type);
549 // Is the new webfinger detectable as OStatus?
550 if (self::ostatus($webfinger2, true)) {
551 $webfinger = $webfinger2;
558 * @brief Fetch information (protocol endpoints and user information) about a given uri
560 * This function is only called by the "uri" function that adds caching and rearranging of data.
562 * @param string $uri Address that should be probed
563 * @param string $network Test for this specific network
564 * @param integer $uid User ID for the probe (only used for mails)
566 * @return array uri data
567 * @throws HTTPException\InternalServerErrorException
569 private static function detect($uri, $network, $uid)
571 $parts = parse_url($uri);
573 if (!empty($parts["scheme"]) && !empty($parts["host"])) {
574 $host = $parts["host"];
575 if (!empty($parts["port"])) {
576 $host .= ':'.$parts["port"];
579 if ($host == 'twitter.com') {
580 return ["network" => Protocol::TWITTER];
582 $lrdd = self::hostMeta($host);
584 if (is_bool($lrdd)) {
588 $path_parts = explode("/", trim(defaults($parts, 'path', ''), "/"));
590 while (!$lrdd && (sizeof($path_parts) > 1)) {
591 $host .= "/".array_shift($path_parts);
592 $lrdd = self::hostMeta($host);
595 Logger::log('No XRD data was found for '.$uri, Logger::DEBUG);
596 return self::feed($uri);
598 $nick = array_pop($path_parts);
600 // Mastodon uses a "@" as prefix for usernames in their url format
601 $nick = ltrim($nick, '@');
603 $addr = $nick."@".$host;
604 } elseif (strstr($uri, '@')) {
605 // If the URI starts with "mailto:" then jump directly to the mail detection
606 if (strpos($uri, 'mailto:') !== false) {
607 $uri = str_replace('mailto:', '', $uri);
608 return self::mail($uri, $uid);
611 if ($network == Protocol::MAIL) {
612 return self::mail($uri, $uid);
614 // Remove "acct:" from the URI
615 $uri = str_replace('acct:', '', $uri);
617 $host = substr($uri, strpos($uri, '@') + 1);
618 $nick = substr($uri, 0, strpos($uri, '@'));
620 if (strpos($uri, '@twitter.com')) {
621 return ["network" => Protocol::TWITTER];
623 $lrdd = self::hostMeta($host);
625 if (is_bool($lrdd)) {
630 Logger::log('No XRD data was found for '.$uri, Logger::DEBUG);
631 return self::mail($uri, $uid);
635 Logger::log("Uri ".$uri." was not detectable", Logger::DEBUG);
641 /// @todo Do we need the prefix "acct:" or "acct://"?
643 foreach ($lrdd as $type => $template) {
648 // At first try it with the given uri
649 $path = str_replace('{uri}', urlencode($uri), $template);
650 $webfinger = self::webfinger($path, $type);
652 // Fix possible problems with GNU Social probing to wrong scheme
653 $webfinger = self::fixOStatus($webfinger, $template, $type);
655 // We cannot be sure that the detected address was correct, so we don't use the values
656 if ($webfinger && ($uri != $addr)) {
661 // Try webfinger with the address (user@domain.tld)
663 $path = str_replace('{uri}', urlencode($addr), $template);
664 $webfinger = self::webfinger($path, $type);
667 // Mastodon needs to have it with "acct:"
669 $path = str_replace('{uri}', urlencode("acct:".$addr), $template);
670 $webfinger = self::webfinger($path, $type);
675 return self::feed($uri);
680 Logger::log("Probing ".$uri, Logger::DEBUG);
682 if (in_array($network, ["", Protocol::DFRN])) {
683 $result = self::dfrn($webfinger);
685 if ((!$result && ($network == "")) || ($network == Protocol::DIASPORA)) {
686 $result = self::diaspora($webfinger);
688 if ((!$result && ($network == "")) || ($network == Protocol::OSTATUS)) {
689 $result = self::ostatus($webfinger);
691 if ((!$result && ($network == "")) || ($network == Protocol::PUMPIO)) {
692 $result = self::pumpio($webfinger, $addr);
694 if ((!$result && ($network == "")) || ($network == Protocol::FEED)) {
695 $result = self::feed($uri);
697 // We overwrite the detected nick with our try if the previois routines hadn't detected it.
698 // Additionally it is overwritten when the nickname doesn't make sense (contains spaces).
699 if ((empty($result["nick"]) || (strstr($result["nick"], " "))) && ($nick != "")) {
700 $result["nick"] = $nick;
703 if (empty($result["addr"]) && ($addr != "")) {
704 $result["addr"] = $addr;
708 if (empty($result["network"])) {
709 $result["network"] = Protocol::PHANTOM;
712 if (empty($result["url"])) {
713 $result["url"] = $uri;
716 Logger::log($uri." is ".$result["network"], Logger::DEBUG);
718 if (empty($result["baseurl"])) {
719 $pos = strpos($result["url"], $host);
721 $result["baseurl"] = substr($result["url"], 0, $pos).$host;
728 * @brief Perform a webfinger request.
730 * For details see RFC 7033: <https://tools.ietf.org/html/rfc7033>
732 * @param string $url Address that should be probed
733 * @param string $type type
735 * @return array webfinger data
736 * @throws HTTPException\InternalServerErrorException
738 private static function webfinger($url, $type)
740 $xrd_timeout = Config::get('system', 'xrd_timeout', 20);
743 $curlResult = Network::curl($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => $type]);
744 if ($curlResult->isTimeout()) {
745 self::$istimeout = true;
748 $data = $curlResult->getBody();
750 $webfinger = json_decode($data, true);
751 if (is_array($webfinger)) {
752 if (!isset($webfinger["links"])) {
753 Logger::log("No json webfinger links for ".$url, Logger::DEBUG);
759 // If it is not JSON, maybe it is XML
760 $xrd = XML::parseString($data, false);
761 if (!is_object($xrd)) {
762 Logger::log("No webfinger data retrievable for ".$url, Logger::DEBUG);
766 $xrd_arr = XML::elementToArray($xrd);
767 if (!isset($xrd_arr["xrd"]["link"])) {
768 Logger::log("No XML webfinger links for ".$url, Logger::DEBUG);
774 if (!empty($xrd_arr["xrd"]["subject"])) {
775 $webfinger["subject"] = $xrd_arr["xrd"]["subject"];
778 if (!empty($xrd_arr["xrd"]["alias"])) {
779 $webfinger["aliases"] = $xrd_arr["xrd"]["alias"];
782 $webfinger["links"] = [];
784 foreach ($xrd_arr["xrd"]["link"] as $value => $data) {
785 if (!empty($data["@attributes"])) {
786 $attributes = $data["@attributes"];
787 } elseif ($value == "@attributes") {
793 $webfinger["links"][] = $attributes;
799 * @brief Poll the Friendica specific noscrape page.
801 * "noscrape" is a faster alternative to fetch the data from the hcard.
802 * This functionality was originally created for the directory.
804 * @param string $noscrape_url Link to the noscrape page
805 * @param array $data The already fetched data
807 * @return array noscrape data
808 * @throws HTTPException\InternalServerErrorException
810 private static function pollNoscrape($noscrape_url, $data)
812 $curlResult = Network::curl($noscrape_url);
813 if ($curlResult->isTimeout()) {
814 self::$istimeout = true;
817 $content = $curlResult->getBody();
819 Logger::log("Empty body for ".$noscrape_url, Logger::DEBUG);
823 $json = json_decode($content, true);
824 if (!is_array($json)) {
825 Logger::log("No json data for ".$noscrape_url, Logger::DEBUG);
829 if (!empty($json["fn"])) {
830 $data["name"] = $json["fn"];
833 if (!empty($json["addr"])) {
834 $data["addr"] = $json["addr"];
837 if (!empty($json["nick"])) {
838 $data["nick"] = $json["nick"];
841 if (!empty($json["guid"])) {
842 $data["guid"] = $json["guid"];
845 if (!empty($json["comm"])) {
846 $data["community"] = $json["comm"];
849 if (!empty($json["tags"])) {
850 $keywords = implode(" ", $json["tags"]);
851 if ($keywords != "") {
852 $data["keywords"] = $keywords;
856 $location = Profile::formatLocation($json);
858 $data["location"] = $location;
861 if (!empty($json["about"])) {
862 $data["about"] = $json["about"];
865 if (!empty($json["key"])) {
866 $data["pubkey"] = $json["key"];
869 if (!empty($json["photo"])) {
870 $data["photo"] = $json["photo"];
873 if (!empty($json["dfrn-request"])) {
874 $data["request"] = $json["dfrn-request"];
877 if (!empty($json["dfrn-confirm"])) {
878 $data["confirm"] = $json["dfrn-confirm"];
881 if (!empty($json["dfrn-notify"])) {
882 $data["notify"] = $json["dfrn-notify"];
885 if (!empty($json["dfrn-poll"])) {
886 $data["poll"] = $json["dfrn-poll"];
893 * @brief Check for valid DFRN data
895 * @param array $data DFRN data
897 * @return int Number of errors
899 public static function validDfrn($data)
902 if (!isset($data['key'])) {
905 if (!isset($data['dfrn-request'])) {
908 if (!isset($data['dfrn-confirm'])) {
911 if (!isset($data['dfrn-notify'])) {
914 if (!isset($data['dfrn-poll'])) {
921 * @brief Fetch data from a DFRN profile page and via "noscrape"
923 * @param string $profile_link Link to the profile page
925 * @return array profile data
926 * @throws HTTPException\InternalServerErrorException
927 * @throws \ImagickException
929 public static function profile($profile_link)
933 Logger::log("Check profile ".$profile_link, Logger::DEBUG);
935 // Fetch data via noscrape - this is faster
936 $noscrape_url = str_replace(["/hcard/", "/profile/"], "/noscrape/", $profile_link);
937 $data = self::pollNoscrape($noscrape_url, $data);
939 if (!isset($data["notify"])
940 || !isset($data["confirm"])
941 || !isset($data["request"])
942 || !isset($data["poll"])
943 || !isset($data["name"])
944 || !isset($data["photo"])
946 $data = self::pollHcard($profile_link, $data, true);
951 if (empty($data["addr"]) || empty($data["nick"])) {
952 $probe_data = self::uri($profile_link);
953 $data["addr"] = defaults($data, "addr", $probe_data["addr"]);
954 $data["nick"] = defaults($data, "nick", $probe_data["nick"]);
957 $prof_data["addr"] = $data["addr"];
958 $prof_data["nick"] = $data["nick"];
959 $prof_data["dfrn-request"] = defaults($data, 'request', null);
960 $prof_data["dfrn-confirm"] = defaults($data, 'confirm', null);
961 $prof_data["dfrn-notify"] = defaults($data, 'notify' , null);
962 $prof_data["dfrn-poll"] = defaults($data, 'poll' , null);
963 $prof_data["photo"] = defaults($data, 'photo' , null);
964 $prof_data["fn"] = defaults($data, 'name' , null);
965 $prof_data["key"] = defaults($data, 'pubkey' , null);
967 Logger::log("Result for profile ".$profile_link.": ".print_r($prof_data, true), Logger::DEBUG);
973 * @brief Check for DFRN contact
975 * @param array $webfinger Webfinger data
977 * @return array DFRN data
978 * @throws HTTPException\InternalServerErrorException
980 private static function dfrn($webfinger)
984 // The array is reversed to take into account the order of preference for same-rel links
985 // See: https://tools.ietf.org/html/rfc7033#section-4.4.4
986 foreach (array_reverse($webfinger["links"]) as $link) {
987 if (($link["rel"] == NAMESPACE_DFRN) && !empty($link["href"])) {
988 $data["network"] = Protocol::DFRN;
989 } elseif (($link["rel"] == NAMESPACE_FEED) && !empty($link["href"])) {
990 $data["poll"] = $link["href"];
991 } elseif (($link["rel"] == "http://webfinger.net/rel/profile-page") && (defaults($link, "type", "") == "text/html") && !empty($link["href"])) {
992 $data["url"] = $link["href"];
993 } elseif (($link["rel"] == "http://microformats.org/profile/hcard") && !empty($link["href"])) {
994 $hcard_url = $link["href"];
995 } elseif (($link["rel"] == NAMESPACE_POCO) && !empty($link["href"])) {
996 $data["poco"] = $link["href"];
997 } elseif (($link["rel"] == "http://webfinger.net/rel/avatar") && !empty($link["href"])) {
998 $data["photo"] = $link["href"];
999 } elseif (($link["rel"] == "http://joindiaspora.com/seed_location") && !empty($link["href"])) {
1000 $data["baseurl"] = trim($link["href"], '/');
1001 } elseif (($link["rel"] == "http://joindiaspora.com/guid") && !empty($link["href"])) {
1002 $data["guid"] = $link["href"];
1003 } elseif (($link["rel"] == "diaspora-public-key") && !empty($link["href"])) {
1004 $data["pubkey"] = base64_decode($link["href"]);
1006 //if (strstr($data["pubkey"], 'RSA ') || ($link["type"] == "RSA"))
1007 if (strstr($data["pubkey"], 'RSA ')) {
1008 $data["pubkey"] = Crypto::rsaToPem($data["pubkey"]);
1013 if (!empty($webfinger["aliases"]) && is_array($webfinger["aliases"])) {
1014 foreach ($webfinger["aliases"] as $alias) {
1015 if (empty($data["url"]) && !strstr($alias, "@")) {
1016 $data["url"] = $alias;
1017 } elseif (!strstr($alias, "@") && Strings::normaliseLink($alias) != Strings::normaliseLink($data["url"])) {
1018 $data["alias"] = $alias;
1019 } elseif (substr($alias, 0, 5) == 'acct:') {
1020 $data["addr"] = substr($alias, 5);
1025 if (!empty($webfinger["subject"]) && (substr($webfinger["subject"], 0, 5) == "acct:")) {
1026 $data["addr"] = substr($webfinger["subject"], 5);
1029 if (!isset($data["network"]) || ($hcard_url == "")) {
1033 // Fetch data via noscrape - this is faster
1034 $noscrape_url = str_replace("/hcard/", "/noscrape/", $hcard_url);
1035 $data = self::pollNoscrape($noscrape_url, $data);
1037 if (isset($data["notify"])
1038 && isset($data["confirm"])
1039 && isset($data["request"])
1040 && isset($data["poll"])
1041 && isset($data["name"])
1042 && isset($data["photo"])
1047 $data = self::pollHcard($hcard_url, $data, true);
1053 * @brief Poll the hcard page (Diaspora and Friendica specific)
1055 * @param string $hcard_url Link to the hcard page
1056 * @param array $data The already fetched data
1057 * @param boolean $dfrn Poll DFRN specific data
1059 * @return array hcard data
1060 * @throws HTTPException\InternalServerErrorException
1062 private static function pollHcard($hcard_url, $data, $dfrn = false)
1064 $curlResult = Network::curl($hcard_url);
1065 if ($curlResult->isTimeout()) {
1066 self::$istimeout = true;
1069 $content = $curlResult->getBody();
1074 $doc = new DOMDocument();
1075 if (!@$doc->loadHTML($content)) {
1079 $xpath = new DomXPath($doc);
1081 $vcards = $xpath->query("//div[contains(concat(' ', @class, ' '), ' vcard ')]");
1082 if (!is_object($vcards)) {
1086 if (!isset($data["baseurl"])) {
1087 $data["baseurl"] = "";
1090 if ($vcards->length > 0) {
1091 $vcard = $vcards->item(0);
1093 // We have to discard the guid from the hcard in favour of the guid from lrdd
1094 // Reason: Hubzilla doesn't use the value "uid" in the hcard like Diaspora does.
1095 $search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' uid ')]", $vcard); // */
1096 if (($search->length > 0) && empty($data["guid"])) {
1097 $data["guid"] = $search->item(0)->nodeValue;
1100 $search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' nickname ')]", $vcard); // */
1101 if ($search->length > 0) {
1102 $data["nick"] = $search->item(0)->nodeValue;
1105 $search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' fn ')]", $vcard); // */
1106 if ($search->length > 0) {
1107 $data["name"] = $search->item(0)->nodeValue;
1110 $search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' searchable ')]", $vcard); // */
1111 if ($search->length > 0) {
1112 $data["searchable"] = $search->item(0)->nodeValue;
1115 $search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' key ')]", $vcard); // */
1116 if ($search->length > 0) {
1117 $data["pubkey"] = $search->item(0)->nodeValue;
1118 if (strstr($data["pubkey"], 'RSA ')) {
1119 $data["pubkey"] = Crypto::rsaToPem($data["pubkey"]);
1123 $search = $xpath->query("//*[@id='pod_location']", $vcard); // */
1124 if ($search->length > 0) {
1125 $data["baseurl"] = trim($search->item(0)->nodeValue, "/");
1130 if (!empty($vcard)) {
1131 $photos = $xpath->query("//*[contains(concat(' ', @class, ' '), ' photo ') or contains(concat(' ', @class, ' '), ' avatar ')]", $vcard); // */
1132 foreach ($photos as $photo) {
1134 foreach ($photo->attributes as $attribute) {
1135 $attr[$attribute->name] = trim($attribute->value);
1138 if (isset($attr["src"]) && isset($attr["width"])) {
1139 $avatar[$attr["width"]] = $attr["src"];
1142 // We don't have a width. So we just take everything that we got.
1143 // This is a Hubzilla workaround which doesn't send a width.
1144 if ((sizeof($avatar) == 0) && !empty($attr["src"])) {
1145 $avatar[] = $attr["src"];
1150 if (sizeof($avatar)) {
1152 $data["photo"] = self::fixAvatar(array_pop($avatar), $data["baseurl"]);
1156 // Poll DFRN specific data
1157 $search = $xpath->query("//link[contains(concat(' ', @rel), ' dfrn-')]");
1158 if ($search->length > 0) {
1159 foreach ($search as $link) {
1160 //$data["request"] = $search->item(0)->nodeValue;
1162 foreach ($link->attributes as $attribute) {
1163 $attr[$attribute->name] = trim($attribute->value);
1166 $data[substr($attr["rel"], 5)] = $attr["href"];
1170 // Older Friendica versions had used the "uid" field differently than newer versions
1171 if (!empty($data["nick"]) && !empty($data["guid"]) && ($data["nick"] == $data["guid"])) {
1172 unset($data["guid"]);
1181 * @brief Check for Diaspora contact
1183 * @param array $webfinger Webfinger data
1185 * @return array Diaspora data
1186 * @throws HTTPException\InternalServerErrorException
1188 private static function diaspora($webfinger)
1192 // The array is reversed to take into account the order of preference for same-rel links
1193 // See: https://tools.ietf.org/html/rfc7033#section-4.4.4
1194 foreach (array_reverse($webfinger["links"]) as $link) {
1195 if (($link["rel"] == "http://microformats.org/profile/hcard") && !empty($link["href"])) {
1196 $hcard_url = $link["href"];
1197 } elseif (($link["rel"] == "http://joindiaspora.com/seed_location") && !empty($link["href"])) {
1198 $data["baseurl"] = trim($link["href"], '/');
1199 } elseif (($link["rel"] == "http://joindiaspora.com/guid") && !empty($link["href"])) {
1200 $data["guid"] = $link["href"];
1201 } elseif (($link["rel"] == "http://webfinger.net/rel/profile-page") && (defaults($link, "type", "") == "text/html") && !empty($link["href"])) {
1202 $data["url"] = $link["href"];
1203 } elseif (($link["rel"] == NAMESPACE_FEED) && !empty($link["href"])) {
1204 $data["poll"] = $link["href"];
1205 } elseif (($link["rel"] == NAMESPACE_POCO) && !empty($link["href"])) {
1206 $data["poco"] = $link["href"];
1207 } elseif (($link["rel"] == "salmon") && !empty($link["href"])) {
1208 $data["notify"] = $link["href"];
1209 } elseif (($link["rel"] == "diaspora-public-key") && !empty($link["href"])) {
1210 $data["pubkey"] = base64_decode($link["href"]);
1212 //if (strstr($data["pubkey"], 'RSA ') || ($link["type"] == "RSA"))
1213 if (strstr($data["pubkey"], 'RSA ')) {
1214 $data["pubkey"] = Crypto::rsaToPem($data["pubkey"]);
1219 if (!isset($data["url"]) || ($hcard_url == "")) {
1223 if (!empty($webfinger["aliases"]) && is_array($webfinger["aliases"])) {
1224 foreach ($webfinger["aliases"] as $alias) {
1225 if (Strings::normaliseLink($alias) != Strings::normaliseLink($data["url"]) && ! strstr($alias, "@")) {
1226 $data["alias"] = $alias;
1227 } elseif (substr($alias, 0, 5) == 'acct:') {
1228 $data["addr"] = substr($alias, 5);
1233 if (!empty($webfinger["subject"]) && (substr($webfinger["subject"], 0, 5) == 'acct:')) {
1234 $data["addr"] = substr($webfinger["subject"], 5);
1237 // Fetch further information from the hcard
1238 $data = self::pollHcard($hcard_url, $data);
1244 if (isset($data["url"])
1245 && isset($data["guid"])
1246 && isset($data["baseurl"])
1247 && isset($data["pubkey"])
1248 && ($hcard_url != "")
1250 $data["network"] = Protocol::DIASPORA;
1252 // The Diaspora handle must always be lowercase
1253 if (!empty($data["addr"])) {
1254 $data["addr"] = strtolower($data["addr"]);
1257 // We have to overwrite the detected value for "notify" since Hubzilla doesn't send it
1258 $data["notify"] = $data["baseurl"] . "/receive/users/" . $data["guid"];
1259 $data["batch"] = $data["baseurl"] . "/receive/public";
1268 * @brief Check for OStatus contact
1270 * @param array $webfinger Webfinger data
1271 * @param bool $short Short detection mode
1273 * @return array|bool OStatus data or "false" on error or "true" on short mode
1274 * @throws HTTPException\InternalServerErrorException
1276 private static function ostatus($webfinger, $short = false)
1280 if (!empty($webfinger["aliases"]) && is_array($webfinger["aliases"])) {
1281 foreach ($webfinger["aliases"] as $alias) {
1282 if (strstr($alias, "@") && !strstr(Strings::normaliseLink($alias), "http://")) {
1283 $data["addr"] = str_replace('acct:', '', $alias);
1288 if (!empty($webfinger["subject"]) && strstr($webfinger["subject"], "@")
1289 && !strstr(Strings::normaliseLink($webfinger["subject"]), "http://")
1291 $data["addr"] = str_replace('acct:', '', $webfinger["subject"]);
1294 if (is_array($webfinger["links"])) {
1295 // The array is reversed to take into account the order of preference for same-rel links
1296 // See: https://tools.ietf.org/html/rfc7033#section-4.4.4
1297 foreach (array_reverse($webfinger["links"]) as $link) {
1298 if (($link["rel"] == "http://webfinger.net/rel/profile-page")
1299 && (defaults($link, "type", "") == "text/html")
1300 && ($link["href"] != "")
1302 $data["url"] = $link["href"];
1303 } elseif (($link["rel"] == "salmon") && !empty($link["href"])) {
1304 $data["notify"] = $link["href"];
1305 } elseif (($link["rel"] == NAMESPACE_FEED) && !empty($link["href"])) {
1306 $data["poll"] = $link["href"];
1307 } elseif (($link["rel"] == "magic-public-key") && !empty($link["href"])) {
1308 $pubkey = $link["href"];
1310 if (substr($pubkey, 0, 5) === 'data:') {
1311 if (strstr($pubkey, ',')) {
1312 $pubkey = substr($pubkey, strpos($pubkey, ',') + 1);
1314 $pubkey = substr($pubkey, 5);
1316 } elseif (Strings::normaliseLink($pubkey) == 'http://') {
1317 $curlResult = Network::curl($pubkey);
1318 if ($curlResult->isTimeout()) {
1319 self::$istimeout = true;
1322 $pubkey = $curlResult->getBody();
1325 $key = explode(".", $pubkey);
1327 if (sizeof($key) >= 3) {
1328 $m = Strings::base64UrlDecode($key[1]);
1329 $e = Strings::base64UrlDecode($key[2]);
1330 $data["pubkey"] = Crypto::meToPem($m, $e);
1336 if (isset($data["notify"]) && isset($data["pubkey"])
1337 && isset($data["poll"])
1338 && isset($data["url"])
1340 $data["network"] = Protocol::OSTATUS;
1349 // Fetch all additional data from the feed
1350 $curlResult = Network::curl($data["poll"]);
1351 if ($curlResult->isTimeout()) {
1352 self::$istimeout = true;
1355 $feed = $curlResult->getBody();
1359 $feed_data = Feed::import($feed, $dummy1, $dummy2, $dummy3, true);
1364 if (!empty($feed_data["header"]["author-name"])) {
1365 $data["name"] = $feed_data["header"]["author-name"];
1367 if (!empty($feed_data["header"]["author-nick"])) {
1368 $data["nick"] = $feed_data["header"]["author-nick"];
1370 if (!empty($feed_data["header"]["author-avatar"])) {
1371 $data["photo"] = self::fixAvatar($feed_data["header"]["author-avatar"], $data["url"]);
1373 if (!empty($feed_data["header"]["author-id"])) {
1374 $data["alias"] = $feed_data["header"]["author-id"];
1376 if (!empty($feed_data["header"]["author-location"])) {
1377 $data["location"] = $feed_data["header"]["author-location"];
1379 if (!empty($feed_data["header"]["author-about"])) {
1380 $data["about"] = $feed_data["header"]["author-about"];
1382 // OStatus has serious issues when the the url doesn't fit (ssl vs. non ssl)
1383 // So we take the value that we just fetched, although the other one worked as well
1384 if (!empty($feed_data["header"]["author-link"])) {
1385 $data["url"] = $feed_data["header"]["author-link"];
1388 if (($data['poll'] == $data['url']) && ($data["alias"] != '')) {
1389 $data['url'] = $data["alias"];
1390 $data["alias"] = '';
1393 /// @todo Fetch location and "about" from the feed as well
1398 * @brief Fetch data from a pump.io profile page
1400 * @param string $profile_link Link to the profile page
1402 * @return array profile data
1404 private static function pumpioProfileData($profile_link)
1406 $doc = new DOMDocument();
1407 if (!@$doc->loadHTMLFile($profile_link)) {
1411 $xpath = new DomXPath($doc);
1415 $data["name"] = $xpath->query("//span[contains(@class, 'p-name')]")->item(0)->nodeValue;
1417 if ($data["name"] == '') {
1418 // This is ugly - but pump.io doesn't seem to know a better way for it
1419 $data["name"] = trim($xpath->query("//h1[@class='media-header']")->item(0)->nodeValue);
1420 $pos = strpos($data["name"], chr(10));
1422 $data["name"] = trim(substr($data["name"], 0, $pos));
1426 $data["location"] = XML::getFirstNodeValue($xpath, "//p[contains(@class, 'p-locality')]");
1428 if ($data["location"] == '') {
1429 $data["location"] = XML::getFirstNodeValue($xpath, "//p[contains(@class, 'location')]");
1432 $data["about"] = XML::getFirstNodeValue($xpath, "//p[contains(@class, 'p-note')]");
1434 if ($data["about"] == '') {
1435 $data["about"] = XML::getFirstNodeValue($xpath, "//p[contains(@class, 'summary')]");
1438 $avatar = $xpath->query("//img[contains(@class, 'u-photo')]")->item(0);
1440 $avatar = $xpath->query("//img[@class='img-rounded media-object']")->item(0);
1443 foreach ($avatar->attributes as $attribute) {
1444 if ($attribute->name == "src") {
1445 $data["photo"] = trim($attribute->value);
1454 * @brief Check for pump.io contact
1456 * @param array $webfinger Webfinger data
1459 * @return array pump.io data
1461 private static function pumpio($webfinger, $addr)
1464 // The array is reversed to take into account the order of preference for same-rel links
1465 // See: https://tools.ietf.org/html/rfc7033#section-4.4.4
1466 foreach (array_reverse($webfinger["links"]) as $link) {
1467 if (($link["rel"] == "http://webfinger.net/rel/profile-page")
1468 && (defaults($link, "type", "") == "text/html")
1469 && ($link["href"] != "")
1471 $data["url"] = $link["href"];
1472 } elseif (($link["rel"] == "activity-inbox") && ($link["href"] != "")) {
1473 $data["notify"] = $link["href"];
1474 } elseif (($link["rel"] == "activity-outbox") && ($link["href"] != "")) {
1475 $data["poll"] = $link["href"];
1476 } elseif (($link["rel"] == "dialback") && ($link["href"] != "")) {
1477 $data["dialback"] = $link["href"];
1480 if (isset($data["poll"]) && isset($data["notify"])
1481 && isset($data["dialback"])
1482 && isset($data["url"])
1484 // by now we use these fields only for the network type detection
1485 // So we unset all data that isn't used at the moment
1486 unset($data["dialback"]);
1488 $data["network"] = Protocol::PUMPIO;
1493 $profile_data = self::pumpioProfileData($data["url"]);
1495 if (!$profile_data) {
1499 $data = array_merge($data, $profile_data);
1501 if (($addr != '') && ($data['name'] != '')) {
1502 $name = trim(str_replace($addr, '', $data['name']));
1504 $data['name'] = $name;
1512 * @brief Check page for feed link
1514 * @param string $url Page link
1516 * @return string feed link
1518 private static function getFeedLink($url)
1520 $doc = new DOMDocument();
1522 if (!@$doc->loadHTMLFile($url)) {
1526 $xpath = new DomXPath($doc);
1528 //$feeds = $xpath->query("/html/head/link[@type='application/rss+xml']");
1529 $feeds = $xpath->query("/html/head/link[@type='application/rss+xml' and @rel='alternate']");
1530 if (!is_object($feeds)) {
1534 if ($feeds->length == 0) {
1540 foreach ($feeds as $feed) {
1542 foreach ($feed->attributes as $attribute) {
1543 $attr[$attribute->name] = trim($attribute->value);
1546 if ($feed_url == "") {
1547 $feed_url = $attr["href"];
1555 * @brief Check for feed contact
1557 * @param string $url Profile link
1558 * @param boolean $probe Do a probe if the page contains a feed link
1560 * @return array feed data
1561 * @throws HTTPException\InternalServerErrorException
1563 private static function feed($url, $probe = true)
1565 $curlResult = Network::curl($url);
1566 if ($curlResult->isTimeout()) {
1567 self::$istimeout = true;
1570 $feed = $curlResult->getBody();
1571 $dummy1 = $dummy2 = $dummy3 = null;
1572 $feed_data = Feed::import($feed, $dummy1, $dummy2, $dummy3, true);
1579 $feed_url = self::getFeedLink($url);
1585 return self::feed($feed_url, false);
1588 if (!empty($feed_data["header"]["author-name"])) {
1589 $data["name"] = $feed_data["header"]["author-name"];
1592 if (!empty($feed_data["header"]["author-nick"])) {
1593 $data["nick"] = $feed_data["header"]["author-nick"];
1596 if (!empty($feed_data["header"]["author-avatar"])) {
1597 $data["photo"] = $feed_data["header"]["author-avatar"];
1600 if (!empty($feed_data["header"]["author-id"])) {
1601 $data["alias"] = $feed_data["header"]["author-id"];
1604 $data["url"] = $url;
1605 $data["poll"] = $url;
1607 if (!empty($feed_data["header"]["author-link"])) {
1608 $data["baseurl"] = $feed_data["header"]["author-link"];
1610 $data["baseurl"] = $data["url"];
1613 $data["network"] = Protocol::FEED;
1619 * @brief Check for mail contact
1621 * @param string $uri Profile link
1622 * @param integer $uid User ID
1624 * @return array mail data
1625 * @throws \Exception
1627 private static function mail($uri, $uid)
1629 if (!Network::isEmailDomainValid($uri)) {
1637 $user = DBA::selectFirst('user', ['prvkey'], ['uid' => $uid]);
1639 $condition = ["`uid` = ? AND `server` != ''", $uid];
1640 $fields = ['pass', 'user', 'server', 'port', 'ssltype', 'mailbox'];
1641 $mailacct = DBA::selectFirst('mailacct', $fields, $condition);
1643 if (!DBA::isResult($user) || !DBA::isResult($mailacct)) {
1647 $mailbox = Email::constructMailboxName($mailacct);
1649 openssl_private_decrypt(hex2bin($mailacct['pass']), $password, $user['prvkey']);
1650 $mbox = Email::connect($mailbox, $mailacct['user'], $password);
1655 $msgs = Email::poll($mbox, $uri);
1656 Logger::log('searching '.$uri.', '.count($msgs).' messages found.', Logger::DEBUG);
1658 if (!count($msgs)) {
1662 $phost = substr($uri, strpos($uri, '@') + 1);
1665 $data["addr"] = $uri;
1666 $data["network"] = Protocol::MAIL;
1667 $data["name"] = substr($uri, 0, strpos($uri, '@'));
1668 $data["nick"] = $data["name"];
1669 $data["photo"] = Network::lookupAvatarByEmail($uri);
1670 $data["url"] = 'mailto:'.$uri;
1671 $data["notify"] = 'smtp ' . Strings::getRandomHex();
1672 $data["poll"] = 'email ' . Strings::getRandomHex();
1674 $x = Email::messageMeta($mbox, $msgs[0]);
1675 if (stristr($x[0]->from, $uri)) {
1676 $adr = imap_rfc822_parse_adrlist($x[0]->from, '');
1677 } elseif (stristr($x[0]->to, $uri)) {
1678 $adr = imap_rfc822_parse_adrlist($x[0]->to, '');
1681 foreach ($adr as $feadr) {
1682 if ((strcasecmp($feadr->mailbox, $data["name"]) == 0)
1683 &&(strcasecmp($feadr->host, $phost) == 0)
1684 && (strlen($feadr->personal))
1686 $personal = imap_mime_header_decode($feadr->personal);
1688 foreach ($personal as $perspart) {
1689 if ($perspart->charset != "default") {
1690 $data["name"] .= iconv($perspart->charset, 'UTF-8//IGNORE', $perspart->text);
1692 $data["name"] .= $perspart->text;
1696 $data["name"] = Strings::escapeTags($data["name"]);
1700 if (!empty($mbox)) {
1707 * @brief Mix two paths together to possibly fix missing parts
1709 * @param string $avatar Path to the avatar
1710 * @param string $base Another path that is hopefully complete
1712 * @return string fixed avatar path
1713 * @throws \Exception
1715 public static function fixAvatar($avatar, $base)
1717 $base_parts = parse_url($base);
1719 // Remove all parts that could create a problem
1720 unset($base_parts['path']);
1721 unset($base_parts['query']);
1722 unset($base_parts['fragment']);
1724 $avatar_parts = parse_url($avatar);
1727 $parts = array_merge($base_parts, $avatar_parts);
1729 // And put them together again
1730 $scheme = isset($parts['scheme']) ? $parts['scheme'] . '://' : '';
1731 $host = isset($parts['host']) ? $parts['host'] : '';
1732 $port = isset($parts['port']) ? ':' . $parts['port'] : '';
1733 $path = isset($parts['path']) ? $parts['path'] : '';
1734 $query = isset($parts['query']) ? '?' . $parts['query'] : '';
1735 $fragment = isset($parts['fragment']) ? '#' . $parts['fragment'] : '';
1737 $fixed = $scheme.$host.$port.$path.$query.$fragment;
1739 Logger::log('Base: '.$base.' - Avatar: '.$avatar.' - Fixed: '.$fixed, Logger::DATA);