3 * @file src/Network/Probe.php
5 namespace Friendica\Network;
8 * @file src/Network/Probe.php
9 * @brief Functions for probing URL
13 use Friendica\Core\Cache;
14 use Friendica\Core\Config;
15 use Friendica\Core\Logger;
16 use Friendica\Core\Protocol;
17 use Friendica\Core\System;
18 use Friendica\Database\DBA;
19 use Friendica\Model\Contact;
20 use Friendica\Model\Profile;
21 use Friendica\Protocol\Email;
22 use Friendica\Protocol\Feed;
23 use Friendica\Protocol\ActivityPub;
24 use Friendica\Util\Crypto;
25 use Friendica\Util\DateTimeFormat;
26 use Friendica\Util\Network;
27 use Friendica\Util\Strings;
28 use Friendica\Util\XML;
32 * @brief This class contain functions for probing URL
37 private static $baseurl;
40 * @brief Rearrange the array so that it always has the same order
42 * @param array $data Unordered data
44 * @return array Ordered data
46 private static function rearrangeData($data)
48 $fields = ["name", "nick", "guid", "url", "addr", "alias",
49 "photo", "community", "keywords", "location", "about",
50 "batch", "notify", "poll", "request", "confirm", "poco",
51 "priority", "network", "pubkey", "baseurl"];
54 foreach ($fields as $field) {
55 if (isset($data[$field])) {
56 $newdata[$field] = $data[$field];
58 $newdata[$field] = "";
62 // We don't use the "priority" field anymore and replace it with a dummy.
63 $newdata["priority"] = 0;
69 * @brief Check if the hostname belongs to the own server
71 * @param string $host The hostname that is to be checked
73 * @return bool Does the testes hostname belongs to the own server?
75 private static function ownHost($host)
77 $own_host = \get_app()->getHostName();
79 $parts = parse_url($host);
81 if (!isset($parts['scheme'])) {
82 $parts = parse_url('http://'.$host);
85 if (!isset($parts['host'])) {
88 return $parts['host'] == $own_host;
92 * @brief Probes for webfinger path via "host-meta"
94 * We have to check if the servers in the future still will offer this.
95 * It seems as if it was dropped from the standard.
97 * @param string $host The host part of an url
99 * @return array with template and type of the webfinger template for JSON or XML
100 * @throws HTTPException\InternalServerErrorException
102 private static function hostMeta($host)
104 // Reset the static variable
107 $ssl_url = "https://".$host."/.well-known/host-meta";
108 $url = "http://".$host."/.well-known/host-meta";
110 $xrd_timeout = Config::get('system', 'xrd_timeout', 20);
113 Logger::log("Probing for ".$host, Logger::DEBUG);
116 $curlResult = Network::curl($ssl_url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
117 if ($curlResult->isSuccess()) {
118 $xml = $curlResult->getBody();
119 $xrd = XML::parseString($xml, false);
120 $host_url = 'https://'.$host;
123 if (!is_object($xrd)) {
124 $curlResult = Network::curl($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
125 if ($curlResult->isTimeout()) {
126 Logger::log("Probing timeout for " . $url, Logger::DEBUG);
129 $xml = $curlResult->getBody();
130 $xrd = XML::parseString($xml, false);
131 $host_url = 'http://'.$host;
133 if (!is_object($xrd)) {
134 Logger::log("No xrd object found for ".$host, Logger::DEBUG);
138 $links = XML::elementToArray($xrd);
139 if (!isset($links["xrd"]["link"])) {
140 Logger::log("No xrd data found for ".$host, Logger::DEBUG);
145 // The following webfinger path is defined in RFC 7033 https://tools.ietf.org/html/rfc7033
146 // Problem is that Hubzilla currently doesn't provide all data in the JSON webfinger
147 // compared to the XML webfinger. So this is commented out by now.
148 // $lrdd = array("application/jrd+json" => $host_url.'/.well-known/webfinger?resource={uri}');
150 foreach ($links["xrd"]["link"] as $value => $link) {
151 if (!empty($link["@attributes"])) {
152 $attributes = $link["@attributes"];
153 } elseif ($value == "@attributes") {
159 if (($attributes["rel"] == "lrdd") && !empty($attributes["template"])) {
160 $type = (empty($attributes["type"]) ? '' : $attributes["type"]);
162 $lrdd[$type] = $attributes["template"];
166 self::$baseurl = $host_url;
168 Logger::log("Probing successful for ".$host, Logger::DEBUG);
174 * @brief Perform Webfinger lookup and return DFRN data
176 * Given an email style address, perform webfinger lookup and
177 * return the resulting DFRN profile URL, or if no DFRN profile URL
178 * is located, returns an OStatus subscription template (prefixed
179 * with the string 'stat:' to identify it as on OStatus template).
180 * If this isn't an email style address just return $webbie.
181 * Return an empty string if email-style addresses but webfinger fails,
182 * or if the resultant personal XRD doesn't contain a supported
183 * subscription/friend-request attribute.
185 * amended 7/9/2011 to return an hcard which could save potentially loading
186 * a lengthy content page to scrape dfrn attributes
188 * @param string $webbie Address that should be probed
189 * @param string $hcard_url Link to the hcard - is returned by reference
191 * @return string profile link
192 * @throws HTTPException\InternalServerErrorException
194 public static function webfingerDfrn($webbie, &$hcard_url)
198 $links = self::lrdd($webbie);
199 Logger::log('webfingerDfrn: '.$webbie.':'.print_r($links, true), Logger::DATA);
201 foreach ($links as $link) {
202 if ($link['@attributes']['rel'] === NAMESPACE_DFRN) {
203 $profile_link = $link['@attributes']['href'];
205 if (($link['@attributes']['rel'] === NAMESPACE_OSTATUSSUB) && ($profile_link == "")) {
206 $profile_link = 'stat:'.$link['@attributes']['template'];
208 if ($link['@attributes']['rel'] === 'http://microformats.org/profile/hcard') {
209 $hcard_url = $link['@attributes']['href'];
213 return $profile_link;
217 * @brief Check an URI for LRDD data
219 * this is a replacement for the "lrdd" function.
220 * It isn't used in this class and has some redundancies in the code.
221 * When time comes we can check the existing calls for "lrdd" if we can rework them.
223 * @param string $uri Address that should be probed
225 * @return array uri data
226 * @throws HTTPException\InternalServerErrorException
228 public static function lrdd($uri)
230 $lrdd = self::hostMeta($uri);
233 if (is_bool($lrdd)) {
238 $parts = @parse_url($uri);
239 if (!$parts || empty($parts["host"]) || empty($parts["path"])) {
243 $host = $parts["host"];
244 if (!empty($parts["port"])) {
245 $host .= ':'.$parts["port"];
248 $path_parts = explode("/", trim($parts["path"], "/"));
250 $nick = array_pop($path_parts);
253 $lrdd = self::hostMeta($host);
254 $host .= "/".array_shift($path_parts);
255 } while (!$lrdd && (sizeof($path_parts) > 0));
259 Logger::log("No lrdd data found for ".$uri, Logger::DEBUG);
263 foreach ($lrdd as $type => $template) {
268 $path = str_replace('{uri}', urlencode($uri), $template);
269 $webfinger = self::webfinger($path, $type);
271 if (!$webfinger && (strstr($uri, "@"))) {
272 $path = str_replace('{uri}', urlencode("acct:".$uri), $template);
273 $webfinger = self::webfinger($path, $type);
276 // Special treatment for Mastodon
277 // Problem is that Mastodon uses an URL format like http://domain.tld/@nick
278 // But the webfinger for this format fails.
279 if (!$webfinger && !empty($nick)) {
280 // Mastodon uses a "@" as prefix for usernames in their url format
281 $nick = ltrim($nick, '@');
283 $addr = $nick."@".$host;
285 $path = str_replace('{uri}', urlencode("acct:".$addr), $template);
286 $webfinger = self::webfinger($path, $type);
290 if (!is_array($webfinger["links"])) {
291 Logger::log("No webfinger links found for ".$uri, Logger::DEBUG);
297 foreach ($webfinger["links"] as $link) {
298 $data[] = ["@attributes" => $link];
301 if (is_array($webfinger["aliases"])) {
302 foreach ($webfinger["aliases"] as $alias) {
303 $data[] = ["@attributes" =>
313 * @brief Fetch information (protocol endpoints and user information) about a given uri
315 * @param string $uri Address that should be probed
316 * @param string $network Test for this specific network
317 * @param integer $uid User ID for the probe (only used for mails)
318 * @param boolean $cache Use cached values?
320 * @return array uri data
321 * @throws HTTPException\InternalServerErrorException
322 * @throws \ImagickException
324 public static function uri($uri, $network = '', $uid = -1, $cache = true)
327 $result = Cache::get('Probe::uri:' . $network . ':' . $uri);
328 if (!is_null($result)) {
337 if ($network != Protocol::ACTIVITYPUB) {
338 $data = self::detect($uri, $network, $uid);
343 $ap_profile = ActivityPub::probeProfile($uri);
345 if (!empty($ap_profile) && empty($network) && (defaults($data, 'network', '') != Protocol::DFRN)) {
349 if (!isset($data['url'])) {
353 if (!empty($data['photo'])) {
354 $data['baseurl'] = Network::getUrlMatch(Strings::normaliseLink(defaults($data, 'baseurl', '')), Strings::normaliseLink($data['photo']));
356 $data['photo'] = System::baseUrl() . '/images/person-300.jpg';
359 if (empty($data['name'])) {
360 if (!empty($data['nick'])) {
361 $data['name'] = $data['nick'];
364 if (empty($data['name'])) {
365 $data['name'] = $data['url'];
369 if (empty($data['nick'])) {
370 $data['nick'] = strtolower($data['name']);
372 if (strpos($data['nick'], ' ')) {
373 $data['nick'] = trim(substr($data['nick'], 0, strpos($data['nick'], ' ')));
377 if (!empty(self::$baseurl)) {
378 $data['baseurl'] = self::$baseurl;
381 if (empty($data['network'])) {
382 $data['network'] = Protocol::PHANTOM;
385 $data = self::rearrangeData($data);
387 // Only store into the cache if the value seems to be valid
388 if (!in_array($data['network'], [Protocol::PHANTOM, Protocol::MAIL])) {
389 Cache::set('Probe::uri:' . $network . ':' . $uri, $data, Cache::DAY);
391 /// @todo temporary fix - we need a real contact update function that updates only changing fields
392 /// The biggest problem is the avatar picture that could have a reduced image size.
393 /// It should only be updated if the existing picture isn't existing anymore.
394 /// We only update the contact when it is no probing for a specific network.
395 if (($data['network'] != Protocol::FEED)
404 'name' => $data['name'],
405 'nick' => $data['nick'],
406 'url' => $data['url'],
407 'addr' => $data['addr'],
408 'photo' => $data['photo'],
409 'keywords' => $data['keywords'],
410 'location' => $data['location'],
411 'about' => $data['about'],
412 'notify' => $data['notify'],
413 'network' => $data['network'],
414 'server_url' => $data['baseurl']
417 // This doesn't cover the case when a community isn't a community anymore
418 if (!empty($data['community']) && $data['community']) {
419 $fields['community'] = $data['community'];
420 $fields['contact-type'] = Contact::TYPE_COMMUNITY;
425 foreach ($fields as $key => $val) {
427 unset($fields[$key]);
429 $fieldnames[] = $key;
433 $fields['updated'] = DateTimeFormat::utcNow();
435 $condition = ['nurl' => Strings::normaliseLink($data['url'])];
437 $old_fields = DBA::selectFirst('gcontact', $fieldnames, $condition);
439 // When the gcontact doesn't exist, the value "true" will trigger an insert.
440 // In difference to the public contacts we want to have every contact
441 // in the world in our global contacts.
445 // These values have to be set only on insert
446 $fields['photo'] = $data['photo'];
447 $fields['created'] = DateTimeFormat::utcNow();
450 DBA::update('gcontact', $fields, $condition, $old_fields);
453 'name' => $data['name'],
454 'nick' => $data['nick'],
455 'url' => $data['url'],
456 'addr' => $data['addr'],
457 'alias' => $data['alias'],
458 'keywords' => $data['keywords'],
459 'location' => $data['location'],
460 'about' => $data['about'],
461 'batch' => $data['batch'],
462 'notify' => $data['notify'],
463 'poll' => $data['poll'],
464 'request' => $data['request'],
465 'confirm' => $data['confirm'],
466 'poco' => $data['poco'],
467 'network' => $data['network'],
468 'pubkey' => $data['pubkey'],
469 'priority' => $data['priority'],
471 'rel' => Contact::SHARING
476 foreach ($fields as $key => $val) {
478 unset($fields[$key]);
480 $fieldnames[] = $key;
484 $condition = ['nurl' => Strings::normaliseLink($data['url']), 'self' => false, 'uid' => 0];
486 // "$old_fields" will return a "false" when the contact doesn't exist.
487 // This won't trigger an insert. This is intended, since we only need
488 // public contacts for everyone we store items from.
489 // We don't need to store every contact on the planet.
490 $old_fields = DBA::selectFirst('contact', $fieldnames, $condition);
492 $fields['name-date'] = DateTimeFormat::utcNow();
493 $fields['uri-date'] = DateTimeFormat::utcNow();
494 $fields['success_update'] = DateTimeFormat::utcNow();
496 DBA::update('contact', $fields, $condition, $old_fields);
504 * @brief Switch the scheme of an url between http and https
506 * @param string $url URL
508 * @return string switched URL
510 private static function switchScheme($url)
512 $parts = parse_url($url);
514 if (!isset($parts['scheme'])) {
518 if ($parts['scheme'] == 'http') {
519 $url = str_replace('http://', 'https://', $url);
520 } elseif ($parts['scheme'] == 'https') {
521 $url = str_replace('https://', 'http://', $url);
528 * @brief Checks if a profile url should be OStatus but only provides partial information
530 * @param array $webfinger Webfinger data
531 * @param string $lrdd Path template for webfinger request
532 * @param string $type type
534 * @return array fixed webfinger data
535 * @throws HTTPException\InternalServerErrorException
537 private static function fixOStatus($webfinger, $lrdd, $type)
539 if (empty($webfinger['links']) || empty($webfinger['subject'])) {
546 foreach ($webfinger['links'] as $link) {
547 if ($link['rel'] == NAMESPACE_OSTATUSSUB) {
550 if ($link['rel'] == 'magic-public-key') {
555 if (!$is_ostatus || $has_key) {
559 $url = self::switchScheme($webfinger['subject']);
560 $path = str_replace('{uri}', urlencode($url), $lrdd);
561 $webfinger2 = self::webfinger($path, $type);
563 // Is the new webfinger detectable as OStatus?
564 if (self::ostatus($webfinger2, true)) {
565 $webfinger = $webfinger2;
572 * @brief Fetch information (protocol endpoints and user information) about a given uri
574 * This function is only called by the "uri" function that adds caching and rearranging of data.
576 * @param string $uri Address that should be probed
577 * @param string $network Test for this specific network
578 * @param integer $uid User ID for the probe (only used for mails)
580 * @return array uri data
581 * @throws HTTPException\InternalServerErrorException
583 private static function detect($uri, $network, $uid)
585 $parts = parse_url($uri);
587 if (!empty($parts["scheme"]) && !empty($parts["host"])) {
588 $host = $parts["host"];
589 if (!empty($parts["port"])) {
590 $host .= ':'.$parts["port"];
593 if ($host == 'twitter.com') {
594 return ["network" => Protocol::TWITTER];
596 $lrdd = self::hostMeta($host);
598 if (is_bool($lrdd)) {
602 $path_parts = explode("/", trim(defaults($parts, 'path', ''), "/"));
604 while (!$lrdd && (sizeof($path_parts) > 1)) {
605 $host .= "/".array_shift($path_parts);
606 $lrdd = self::hostMeta($host);
609 Logger::log('No XRD data was found for '.$uri, Logger::DEBUG);
610 return self::feed($uri);
612 $nick = array_pop($path_parts);
614 // Mastodon uses a "@" as prefix for usernames in their url format
615 $nick = ltrim($nick, '@');
617 $addr = $nick."@".$host;
618 } elseif (strstr($uri, '@')) {
619 // If the URI starts with "mailto:" then jump directly to the mail detection
620 if (strpos($uri, 'mailto:') !== false) {
621 $uri = str_replace('mailto:', '', $uri);
622 return self::mail($uri, $uid);
625 if ($network == Protocol::MAIL) {
626 return self::mail($uri, $uid);
628 // Remove "acct:" from the URI
629 $uri = str_replace('acct:', '', $uri);
631 $host = substr($uri, strpos($uri, '@') + 1);
632 $nick = substr($uri, 0, strpos($uri, '@'));
634 if (strpos($uri, '@twitter.com')) {
635 return ["network" => Protocol::TWITTER];
637 $lrdd = self::hostMeta($host);
639 if (is_bool($lrdd)) {
644 Logger::log('No XRD data was found for '.$uri, Logger::DEBUG);
645 return self::mail($uri, $uid);
649 Logger::log("Uri ".$uri." was not detectable", Logger::DEBUG);
655 /// @todo Do we need the prefix "acct:" or "acct://"?
657 foreach ($lrdd as $type => $template) {
662 // At first try it with the given uri
663 $path = str_replace('{uri}', urlencode($uri), $template);
664 $webfinger = self::webfinger($path, $type);
666 // Fix possible problems with GNU Social probing to wrong scheme
667 $webfinger = self::fixOStatus($webfinger, $template, $type);
669 // We cannot be sure that the detected address was correct, so we don't use the values
670 if ($webfinger && ($uri != $addr)) {
675 // Try webfinger with the address (user@domain.tld)
677 $path = str_replace('{uri}', urlencode($addr), $template);
678 $webfinger = self::webfinger($path, $type);
681 // Mastodon needs to have it with "acct:"
683 $path = str_replace('{uri}', urlencode("acct:".$addr), $template);
684 $webfinger = self::webfinger($path, $type);
689 return self::feed($uri);
694 Logger::log("Probing ".$uri, Logger::DEBUG);
696 if (in_array($network, ["", Protocol::DFRN])) {
697 $result = self::dfrn($webfinger);
699 if ((!$result && ($network == "")) || ($network == Protocol::DIASPORA)) {
700 $result = self::diaspora($webfinger);
702 if ((!$result && ($network == "")) || ($network == Protocol::OSTATUS)) {
703 $result = self::ostatus($webfinger);
705 if ((!$result && ($network == "")) || ($network == Protocol::PUMPIO)) {
706 $result = self::pumpio($webfinger, $addr);
708 if ((!$result && ($network == "")) || ($network == Protocol::FEED)) {
709 $result = self::feed($uri);
711 // We overwrite the detected nick with our try if the previois routines hadn't detected it.
712 // Additionally it is overwritten when the nickname doesn't make sense (contains spaces).
713 if ((empty($result["nick"]) || (strstr($result["nick"], " "))) && ($nick != "")) {
714 $result["nick"] = $nick;
717 if (empty($result["addr"]) && ($addr != "")) {
718 $result["addr"] = $addr;
722 if (empty($result["network"])) {
723 $result["network"] = Protocol::PHANTOM;
726 if (empty($result["url"])) {
727 $result["url"] = $uri;
730 Logger::log($uri." is ".$result["network"], Logger::DEBUG);
732 if (empty($result["baseurl"])) {
733 $pos = strpos($result["url"], $host);
735 $result["baseurl"] = substr($result["url"], 0, $pos).$host;
742 * @brief Perform a webfinger request.
744 * For details see RFC 7033: <https://tools.ietf.org/html/rfc7033>
746 * @param string $url Address that should be probed
747 * @param string $type type
749 * @return array webfinger data
750 * @throws HTTPException\InternalServerErrorException
752 private static function webfinger($url, $type)
754 $xrd_timeout = Config::get('system', 'xrd_timeout', 20);
757 $curlResult = Network::curl($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => $type]);
758 if ($curlResult->isTimeout()) {
761 $data = $curlResult->getBody();
763 $webfinger = json_decode($data, true);
764 if (is_array($webfinger)) {
765 if (!isset($webfinger["links"])) {
766 Logger::log("No json webfinger links for ".$url, Logger::DEBUG);
772 // If it is not JSON, maybe it is XML
773 $xrd = XML::parseString($data, false);
774 if (!is_object($xrd)) {
775 Logger::log("No webfinger data retrievable for ".$url, Logger::DEBUG);
779 $xrd_arr = XML::elementToArray($xrd);
780 if (!isset($xrd_arr["xrd"]["link"])) {
781 Logger::log("No XML webfinger links for ".$url, Logger::DEBUG);
787 if (!empty($xrd_arr["xrd"]["subject"])) {
788 $webfinger["subject"] = $xrd_arr["xrd"]["subject"];
791 if (!empty($xrd_arr["xrd"]["alias"])) {
792 $webfinger["aliases"] = $xrd_arr["xrd"]["alias"];
795 $webfinger["links"] = [];
797 foreach ($xrd_arr["xrd"]["link"] as $value => $data) {
798 if (!empty($data["@attributes"])) {
799 $attributes = $data["@attributes"];
800 } elseif ($value == "@attributes") {
806 $webfinger["links"][] = $attributes;
812 * @brief Poll the Friendica specific noscrape page.
814 * "noscrape" is a faster alternative to fetch the data from the hcard.
815 * This functionality was originally created for the directory.
817 * @param string $noscrape_url Link to the noscrape page
818 * @param array $data The already fetched data
820 * @return array noscrape data
821 * @throws HTTPException\InternalServerErrorException
823 private static function pollNoscrape($noscrape_url, $data)
825 $curlResult = Network::curl($noscrape_url);
826 if ($curlResult->isTimeout()) {
829 $content = $curlResult->getBody();
831 Logger::log("Empty body for ".$noscrape_url, Logger::DEBUG);
835 $json = json_decode($content, true);
836 if (!is_array($json)) {
837 Logger::log("No json data for ".$noscrape_url, Logger::DEBUG);
841 if (!empty($json["fn"])) {
842 $data["name"] = $json["fn"];
845 if (!empty($json["addr"])) {
846 $data["addr"] = $json["addr"];
849 if (!empty($json["nick"])) {
850 $data["nick"] = $json["nick"];
853 if (!empty($json["guid"])) {
854 $data["guid"] = $json["guid"];
857 if (!empty($json["comm"])) {
858 $data["community"] = $json["comm"];
861 if (!empty($json["tags"])) {
862 $keywords = implode(" ", $json["tags"]);
863 if ($keywords != "") {
864 $data["keywords"] = $keywords;
868 $location = Profile::formatLocation($json);
870 $data["location"] = $location;
873 if (!empty($json["about"])) {
874 $data["about"] = $json["about"];
877 if (!empty($json["key"])) {
878 $data["pubkey"] = $json["key"];
881 if (!empty($json["photo"])) {
882 $data["photo"] = $json["photo"];
885 if (!empty($json["dfrn-request"])) {
886 $data["request"] = $json["dfrn-request"];
889 if (!empty($json["dfrn-confirm"])) {
890 $data["confirm"] = $json["dfrn-confirm"];
893 if (!empty($json["dfrn-notify"])) {
894 $data["notify"] = $json["dfrn-notify"];
897 if (!empty($json["dfrn-poll"])) {
898 $data["poll"] = $json["dfrn-poll"];
905 * @brief Check for valid DFRN data
907 * @param array $data DFRN data
909 * @return int Number of errors
911 public static function validDfrn($data)
914 if (!isset($data['key'])) {
917 if (!isset($data['dfrn-request'])) {
920 if (!isset($data['dfrn-confirm'])) {
923 if (!isset($data['dfrn-notify'])) {
926 if (!isset($data['dfrn-poll'])) {
933 * @brief Fetch data from a DFRN profile page and via "noscrape"
935 * @param string $profile_link Link to the profile page
937 * @return array profile data
938 * @throws HTTPException\InternalServerErrorException
939 * @throws \ImagickException
941 public static function profile($profile_link)
945 Logger::log("Check profile ".$profile_link, Logger::DEBUG);
947 // Fetch data via noscrape - this is faster
948 $noscrape_url = str_replace(["/hcard/", "/profile/"], "/noscrape/", $profile_link);
949 $data = self::pollNoscrape($noscrape_url, $data);
951 if (!isset($data["notify"])
952 || !isset($data["confirm"])
953 || !isset($data["request"])
954 || !isset($data["poll"])
955 || !isset($data["name"])
956 || !isset($data["photo"])
958 $data = self::pollHcard($profile_link, $data, true);
963 if (empty($data["addr"]) || empty($data["nick"])) {
964 $probe_data = self::uri($profile_link);
965 $data["addr"] = defaults($data, "addr", $probe_data["addr"]);
966 $data["nick"] = defaults($data, "nick", $probe_data["nick"]);
969 $prof_data["addr"] = $data["addr"];
970 $prof_data["nick"] = $data["nick"];
971 $prof_data["dfrn-request"] = defaults($data, 'request', null);
972 $prof_data["dfrn-confirm"] = defaults($data, 'confirm', null);
973 $prof_data["dfrn-notify"] = defaults($data, 'notify' , null);
974 $prof_data["dfrn-poll"] = defaults($data, 'poll' , null);
975 $prof_data["photo"] = defaults($data, 'photo' , null);
976 $prof_data["fn"] = defaults($data, 'name' , null);
977 $prof_data["key"] = defaults($data, 'pubkey' , null);
979 Logger::log("Result for profile ".$profile_link.": ".print_r($prof_data, true), Logger::DEBUG);
985 * @brief Check for DFRN contact
987 * @param array $webfinger Webfinger data
989 * @return array DFRN data
990 * @throws HTTPException\InternalServerErrorException
992 private static function dfrn($webfinger)
996 // The array is reversed to take into account the order of preference for same-rel links
997 // See: https://tools.ietf.org/html/rfc7033#section-4.4.4
998 foreach (array_reverse($webfinger["links"]) as $link) {
999 if (($link["rel"] == NAMESPACE_DFRN) && !empty($link["href"])) {
1000 $data["network"] = Protocol::DFRN;
1001 } elseif (($link["rel"] == NAMESPACE_FEED) && !empty($link["href"])) {
1002 $data["poll"] = $link["href"];
1003 } elseif (($link["rel"] == "http://webfinger.net/rel/profile-page") && (defaults($link, "type", "") == "text/html") && !empty($link["href"])) {
1004 $data["url"] = $link["href"];
1005 } elseif (($link["rel"] == "http://microformats.org/profile/hcard") && !empty($link["href"])) {
1006 $hcard_url = $link["href"];
1007 } elseif (($link["rel"] == NAMESPACE_POCO) && !empty($link["href"])) {
1008 $data["poco"] = $link["href"];
1009 } elseif (($link["rel"] == "http://webfinger.net/rel/avatar") && !empty($link["href"])) {
1010 $data["photo"] = $link["href"];
1011 } elseif (($link["rel"] == "http://joindiaspora.com/seed_location") && !empty($link["href"])) {
1012 $data["baseurl"] = trim($link["href"], '/');
1013 } elseif (($link["rel"] == "http://joindiaspora.com/guid") && !empty($link["href"])) {
1014 $data["guid"] = $link["href"];
1015 } elseif (($link["rel"] == "diaspora-public-key") && !empty($link["href"])) {
1016 $data["pubkey"] = base64_decode($link["href"]);
1018 //if (strstr($data["pubkey"], 'RSA ') || ($link["type"] == "RSA"))
1019 if (strstr($data["pubkey"], 'RSA ')) {
1020 $data["pubkey"] = Crypto::rsaToPem($data["pubkey"]);
1025 if (!empty($webfinger["aliases"]) && is_array($webfinger["aliases"])) {
1026 foreach ($webfinger["aliases"] as $alias) {
1027 if (empty($data["url"]) && !strstr($alias, "@")) {
1028 $data["url"] = $alias;
1029 } elseif (!strstr($alias, "@") && Strings::normaliseLink($alias) != Strings::normaliseLink($data["url"])) {
1030 $data["alias"] = $alias;
1031 } elseif (substr($alias, 0, 5) == 'acct:') {
1032 $data["addr"] = substr($alias, 5);
1037 if (!empty($webfinger["subject"]) && (substr($webfinger["subject"], 0, 5) == "acct:")) {
1038 $data["addr"] = substr($webfinger["subject"], 5);
1041 if (!isset($data["network"]) || ($hcard_url == "")) {
1045 // Fetch data via noscrape - this is faster
1046 $noscrape_url = str_replace("/hcard/", "/noscrape/", $hcard_url);
1047 $data = self::pollNoscrape($noscrape_url, $data);
1049 if (isset($data["notify"])
1050 && isset($data["confirm"])
1051 && isset($data["request"])
1052 && isset($data["poll"])
1053 && isset($data["name"])
1054 && isset($data["photo"])
1059 $data = self::pollHcard($hcard_url, $data, true);
1065 * @brief Poll the hcard page (Diaspora and Friendica specific)
1067 * @param string $hcard_url Link to the hcard page
1068 * @param array $data The already fetched data
1069 * @param boolean $dfrn Poll DFRN specific data
1071 * @return array hcard data
1072 * @throws HTTPException\InternalServerErrorException
1074 private static function pollHcard($hcard_url, $data, $dfrn = false)
1076 $curlResult = Network::curl($hcard_url);
1077 if ($curlResult->isTimeout()) {
1080 $content = $curlResult->getBody();
1085 $doc = new DOMDocument();
1086 if (!@$doc->loadHTML($content)) {
1090 $xpath = new DomXPath($doc);
1092 $vcards = $xpath->query("//div[contains(concat(' ', @class, ' '), ' vcard ')]");
1093 if (!is_object($vcards)) {
1097 if (!isset($data["baseurl"])) {
1098 $data["baseurl"] = "";
1101 if ($vcards->length > 0) {
1102 $vcard = $vcards->item(0);
1104 // We have to discard the guid from the hcard in favour of the guid from lrdd
1105 // Reason: Hubzilla doesn't use the value "uid" in the hcard like Diaspora does.
1106 $search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' uid ')]", $vcard); // */
1107 if (($search->length > 0) && empty($data["guid"])) {
1108 $data["guid"] = $search->item(0)->nodeValue;
1111 $search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' nickname ')]", $vcard); // */
1112 if ($search->length > 0) {
1113 $data["nick"] = $search->item(0)->nodeValue;
1116 $search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' fn ')]", $vcard); // */
1117 if ($search->length > 0) {
1118 $data["name"] = $search->item(0)->nodeValue;
1121 $search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' searchable ')]", $vcard); // */
1122 if ($search->length > 0) {
1123 $data["searchable"] = $search->item(0)->nodeValue;
1126 $search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' key ')]", $vcard); // */
1127 if ($search->length > 0) {
1128 $data["pubkey"] = $search->item(0)->nodeValue;
1129 if (strstr($data["pubkey"], 'RSA ')) {
1130 $data["pubkey"] = Crypto::rsaToPem($data["pubkey"]);
1134 $search = $xpath->query("//*[@id='pod_location']", $vcard); // */
1135 if ($search->length > 0) {
1136 $data["baseurl"] = trim($search->item(0)->nodeValue, "/");
1141 if (!empty($vcard)) {
1142 $photos = $xpath->query("//*[contains(concat(' ', @class, ' '), ' photo ') or contains(concat(' ', @class, ' '), ' avatar ')]", $vcard); // */
1143 foreach ($photos as $photo) {
1145 foreach ($photo->attributes as $attribute) {
1146 $attr[$attribute->name] = trim($attribute->value);
1149 if (isset($attr["src"]) && isset($attr["width"])) {
1150 $avatar[$attr["width"]] = $attr["src"];
1153 // We don't have a width. So we just take everything that we got.
1154 // This is a Hubzilla workaround which doesn't send a width.
1155 if ((sizeof($avatar) == 0) && !empty($attr["src"])) {
1156 $avatar[] = $attr["src"];
1161 if (sizeof($avatar)) {
1163 $data["photo"] = self::fixAvatar(array_pop($avatar), $data["baseurl"]);
1167 // Poll DFRN specific data
1168 $search = $xpath->query("//link[contains(concat(' ', @rel), ' dfrn-')]");
1169 if ($search->length > 0) {
1170 foreach ($search as $link) {
1171 //$data["request"] = $search->item(0)->nodeValue;
1173 foreach ($link->attributes as $attribute) {
1174 $attr[$attribute->name] = trim($attribute->value);
1177 $data[substr($attr["rel"], 5)] = $attr["href"];
1181 // Older Friendica versions had used the "uid" field differently than newer versions
1182 if (!empty($data["nick"]) && !empty($data["guid"]) && ($data["nick"] == $data["guid"])) {
1183 unset($data["guid"]);
1192 * @brief Check for Diaspora contact
1194 * @param array $webfinger Webfinger data
1196 * @return array Diaspora data
1197 * @throws HTTPException\InternalServerErrorException
1199 private static function diaspora($webfinger)
1203 // The array is reversed to take into account the order of preference for same-rel links
1204 // See: https://tools.ietf.org/html/rfc7033#section-4.4.4
1205 foreach (array_reverse($webfinger["links"]) as $link) {
1206 if (($link["rel"] == "http://microformats.org/profile/hcard") && !empty($link["href"])) {
1207 $hcard_url = $link["href"];
1208 } elseif (($link["rel"] == "http://joindiaspora.com/seed_location") && !empty($link["href"])) {
1209 $data["baseurl"] = trim($link["href"], '/');
1210 } elseif (($link["rel"] == "http://joindiaspora.com/guid") && !empty($link["href"])) {
1211 $data["guid"] = $link["href"];
1212 } elseif (($link["rel"] == "http://webfinger.net/rel/profile-page") && (defaults($link, "type", "") == "text/html") && !empty($link["href"])) {
1213 $data["url"] = $link["href"];
1214 } elseif (($link["rel"] == NAMESPACE_FEED) && !empty($link["href"])) {
1215 $data["poll"] = $link["href"];
1216 } elseif (($link["rel"] == NAMESPACE_POCO) && !empty($link["href"])) {
1217 $data["poco"] = $link["href"];
1218 } elseif (($link["rel"] == "salmon") && !empty($link["href"])) {
1219 $data["notify"] = $link["href"];
1220 } elseif (($link["rel"] == "diaspora-public-key") && !empty($link["href"])) {
1221 $data["pubkey"] = base64_decode($link["href"]);
1223 //if (strstr($data["pubkey"], 'RSA ') || ($link["type"] == "RSA"))
1224 if (strstr($data["pubkey"], 'RSA ')) {
1225 $data["pubkey"] = Crypto::rsaToPem($data["pubkey"]);
1230 if (!isset($data["url"]) || ($hcard_url == "")) {
1234 if (!empty($webfinger["aliases"]) && is_array($webfinger["aliases"])) {
1235 foreach ($webfinger["aliases"] as $alias) {
1236 if (Strings::normaliseLink($alias) != Strings::normaliseLink($data["url"]) && ! strstr($alias, "@")) {
1237 $data["alias"] = $alias;
1238 } elseif (substr($alias, 0, 5) == 'acct:') {
1239 $data["addr"] = substr($alias, 5);
1244 if (!empty($webfinger["subject"]) && (substr($webfinger["subject"], 0, 5) == 'acct:')) {
1245 $data["addr"] = substr($webfinger["subject"], 5);
1248 // Fetch further information from the hcard
1249 $data = self::pollHcard($hcard_url, $data);
1255 if (isset($data["url"])
1256 && isset($data["guid"])
1257 && isset($data["baseurl"])
1258 && isset($data["pubkey"])
1259 && ($hcard_url != "")
1261 $data["network"] = Protocol::DIASPORA;
1263 // The Diaspora handle must always be lowercase
1264 if (!empty($data["addr"])) {
1265 $data["addr"] = strtolower($data["addr"]);
1268 // We have to overwrite the detected value for "notify" since Hubzilla doesn't send it
1269 $data["notify"] = $data["baseurl"] . "/receive/users/" . $data["guid"];
1270 $data["batch"] = $data["baseurl"] . "/receive/public";
1279 * @brief Check for OStatus contact
1281 * @param array $webfinger Webfinger data
1282 * @param bool $short Short detection mode
1284 * @return array|bool OStatus data or "false" on error or "true" on short mode
1285 * @throws HTTPException\InternalServerErrorException
1287 private static function ostatus($webfinger, $short = false)
1291 if (!empty($webfinger["aliases"]) && is_array($webfinger["aliases"])) {
1292 foreach ($webfinger["aliases"] as $alias) {
1293 if (strstr($alias, "@") && !strstr(Strings::normaliseLink($alias), "http://")) {
1294 $data["addr"] = str_replace('acct:', '', $alias);
1299 if (!empty($webfinger["subject"]) && strstr($webfinger["subject"], "@")
1300 && !strstr(Strings::normaliseLink($webfinger["subject"]), "http://")
1302 $data["addr"] = str_replace('acct:', '', $webfinger["subject"]);
1305 if (is_array($webfinger["links"])) {
1306 // The array is reversed to take into account the order of preference for same-rel links
1307 // See: https://tools.ietf.org/html/rfc7033#section-4.4.4
1308 foreach (array_reverse($webfinger["links"]) as $link) {
1309 if (($link["rel"] == "http://webfinger.net/rel/profile-page")
1310 && (defaults($link, "type", "") == "text/html")
1311 && ($link["href"] != "")
1313 $data["url"] = $link["href"];
1314 } elseif (($link["rel"] == "salmon") && !empty($link["href"])) {
1315 $data["notify"] = $link["href"];
1316 } elseif (($link["rel"] == NAMESPACE_FEED) && !empty($link["href"])) {
1317 $data["poll"] = $link["href"];
1318 } elseif (($link["rel"] == "magic-public-key") && !empty($link["href"])) {
1319 $pubkey = $link["href"];
1321 if (substr($pubkey, 0, 5) === 'data:') {
1322 if (strstr($pubkey, ',')) {
1323 $pubkey = substr($pubkey, strpos($pubkey, ',') + 1);
1325 $pubkey = substr($pubkey, 5);
1327 } elseif (Strings::normaliseLink($pubkey) == 'http://') {
1328 $curlResult = Network::curl($pubkey);
1329 if ($curlResult->isTimeout()) {
1332 $pubkey = $curlResult->getBody();
1335 $key = explode(".", $pubkey);
1337 if (sizeof($key) >= 3) {
1338 $m = Strings::base64UrlDecode($key[1]);
1339 $e = Strings::base64UrlDecode($key[2]);
1340 $data["pubkey"] = Crypto::meToPem($m, $e);
1346 if (isset($data["notify"]) && isset($data["pubkey"])
1347 && isset($data["poll"])
1348 && isset($data["url"])
1350 $data["network"] = Protocol::OSTATUS;
1359 // Fetch all additional data from the feed
1360 $curlResult = Network::curl($data["poll"]);
1361 if ($curlResult->isTimeout()) {
1364 $feed = $curlResult->getBody();
1368 $feed_data = Feed::import($feed, $dummy1, $dummy2, $dummy3, true);
1373 if (!empty($feed_data["header"]["author-name"])) {
1374 $data["name"] = $feed_data["header"]["author-name"];
1376 if (!empty($feed_data["header"]["author-nick"])) {
1377 $data["nick"] = $feed_data["header"]["author-nick"];
1379 if (!empty($feed_data["header"]["author-avatar"])) {
1380 $data["photo"] = self::fixAvatar($feed_data["header"]["author-avatar"], $data["url"]);
1382 if (!empty($feed_data["header"]["author-id"])) {
1383 $data["alias"] = $feed_data["header"]["author-id"];
1385 if (!empty($feed_data["header"]["author-location"])) {
1386 $data["location"] = $feed_data["header"]["author-location"];
1388 if (!empty($feed_data["header"]["author-about"])) {
1389 $data["about"] = $feed_data["header"]["author-about"];
1391 // OStatus has serious issues when the the url doesn't fit (ssl vs. non ssl)
1392 // So we take the value that we just fetched, although the other one worked as well
1393 if (!empty($feed_data["header"]["author-link"])) {
1394 $data["url"] = $feed_data["header"]["author-link"];
1397 if (($data['poll'] == $data['url']) && ($data["alias"] != '')) {
1398 $data['url'] = $data["alias"];
1399 $data["alias"] = '';
1402 /// @todo Fetch location and "about" from the feed as well
1407 * @brief Fetch data from a pump.io profile page
1409 * @param string $profile_link Link to the profile page
1411 * @return array profile data
1413 private static function pumpioProfileData($profile_link)
1415 $doc = new DOMDocument();
1416 if (!@$doc->loadHTMLFile($profile_link)) {
1420 $xpath = new DomXPath($doc);
1424 $data["name"] = $xpath->query("//span[contains(@class, 'p-name')]")->item(0)->nodeValue;
1426 if ($data["name"] == '') {
1427 // This is ugly - but pump.io doesn't seem to know a better way for it
1428 $data["name"] = trim($xpath->query("//h1[@class='media-header']")->item(0)->nodeValue);
1429 $pos = strpos($data["name"], chr(10));
1431 $data["name"] = trim(substr($data["name"], 0, $pos));
1435 $data["location"] = XML::getFirstNodeValue($xpath, "//p[contains(@class, 'p-locality')]");
1437 if ($data["location"] == '') {
1438 $data["location"] = XML::getFirstNodeValue($xpath, "//p[contains(@class, 'location')]");
1441 $data["about"] = XML::getFirstNodeValue($xpath, "//p[contains(@class, 'p-note')]");
1443 if ($data["about"] == '') {
1444 $data["about"] = XML::getFirstNodeValue($xpath, "//p[contains(@class, 'summary')]");
1447 $avatar = $xpath->query("//img[contains(@class, 'u-photo')]")->item(0);
1449 $avatar = $xpath->query("//img[@class='img-rounded media-object']")->item(0);
1452 foreach ($avatar->attributes as $attribute) {
1453 if ($attribute->name == "src") {
1454 $data["photo"] = trim($attribute->value);
1463 * @brief Check for pump.io contact
1465 * @param array $webfinger Webfinger data
1468 * @return array pump.io data
1470 private static function pumpio($webfinger, $addr)
1473 // The array is reversed to take into account the order of preference for same-rel links
1474 // See: https://tools.ietf.org/html/rfc7033#section-4.4.4
1475 foreach (array_reverse($webfinger["links"]) as $link) {
1476 if (($link["rel"] == "http://webfinger.net/rel/profile-page")
1477 && (defaults($link, "type", "") == "text/html")
1478 && ($link["href"] != "")
1480 $data["url"] = $link["href"];
1481 } elseif (($link["rel"] == "activity-inbox") && ($link["href"] != "")) {
1482 $data["notify"] = $link["href"];
1483 } elseif (($link["rel"] == "activity-outbox") && ($link["href"] != "")) {
1484 $data["poll"] = $link["href"];
1485 } elseif (($link["rel"] == "dialback") && ($link["href"] != "")) {
1486 $data["dialback"] = $link["href"];
1489 if (isset($data["poll"]) && isset($data["notify"])
1490 && isset($data["dialback"])
1491 && isset($data["url"])
1493 // by now we use these fields only for the network type detection
1494 // So we unset all data that isn't used at the moment
1495 unset($data["dialback"]);
1497 $data["network"] = Protocol::PUMPIO;
1502 $profile_data = self::pumpioProfileData($data["url"]);
1504 if (!$profile_data) {
1508 $data = array_merge($data, $profile_data);
1510 if (($addr != '') && ($data['name'] != '')) {
1511 $name = trim(str_replace($addr, '', $data['name']));
1513 $data['name'] = $name;
1521 * @brief Check page for feed link
1523 * @param string $url Page link
1525 * @return string feed link
1527 private static function getFeedLink($url)
1529 $doc = new DOMDocument();
1531 if (!@$doc->loadHTMLFile($url)) {
1535 $xpath = new DomXPath($doc);
1537 //$feeds = $xpath->query("/html/head/link[@type='application/rss+xml']");
1538 $feeds = $xpath->query("/html/head/link[@type='application/rss+xml' and @rel='alternate']");
1539 if (!is_object($feeds)) {
1543 if ($feeds->length == 0) {
1549 foreach ($feeds as $feed) {
1551 foreach ($feed->attributes as $attribute) {
1552 $attr[$attribute->name] = trim($attribute->value);
1555 if ($feed_url == "") {
1556 $feed_url = $attr["href"];
1564 * @brief Check for feed contact
1566 * @param string $url Profile link
1567 * @param boolean $probe Do a probe if the page contains a feed link
1569 * @return array feed data
1570 * @throws HTTPException\InternalServerErrorException
1572 private static function feed($url, $probe = true)
1574 $curlResult = Network::curl($url);
1575 if ($curlResult->isTimeout()) {
1578 $feed = $curlResult->getBody();
1579 $dummy1 = $dummy2 = $dummy3 = null;
1580 $feed_data = Feed::import($feed, $dummy1, $dummy2, $dummy3, true);
1587 $feed_url = self::getFeedLink($url);
1593 return self::feed($feed_url, false);
1596 if (!empty($feed_data["header"]["author-name"])) {
1597 $data["name"] = $feed_data["header"]["author-name"];
1600 if (!empty($feed_data["header"]["author-nick"])) {
1601 $data["nick"] = $feed_data["header"]["author-nick"];
1604 if (!empty($feed_data["header"]["author-avatar"])) {
1605 $data["photo"] = $feed_data["header"]["author-avatar"];
1608 if (!empty($feed_data["header"]["author-id"])) {
1609 $data["alias"] = $feed_data["header"]["author-id"];
1612 $data["url"] = $url;
1613 $data["poll"] = $url;
1615 if (!empty($feed_data["header"]["author-link"])) {
1616 $data["baseurl"] = $feed_data["header"]["author-link"];
1618 $data["baseurl"] = $data["url"];
1621 $data["network"] = Protocol::FEED;
1627 * @brief Check for mail contact
1629 * @param string $uri Profile link
1630 * @param integer $uid User ID
1632 * @return array mail data
1633 * @throws \Exception
1635 private static function mail($uri, $uid)
1637 if (!Network::isEmailDomainValid($uri)) {
1645 $user = DBA::selectFirst('user', ['prvkey'], ['uid' => $uid]);
1647 $condition = ["`uid` = ? AND `server` != ''", $uid];
1648 $fields = ['pass', 'user', 'server', 'port', 'ssltype', 'mailbox'];
1649 $mailacct = DBA::selectFirst('mailacct', $fields, $condition);
1651 if (!DBA::isResult($user) || !DBA::isResult($mailacct)) {
1655 $mailbox = Email::constructMailboxName($mailacct);
1657 openssl_private_decrypt(hex2bin($mailacct['pass']), $password, $user['prvkey']);
1658 $mbox = Email::connect($mailbox, $mailacct['user'], $password);
1663 $msgs = Email::poll($mbox, $uri);
1664 Logger::log('searching '.$uri.', '.count($msgs).' messages found.', Logger::DEBUG);
1666 if (!count($msgs)) {
1670 $phost = substr($uri, strpos($uri, '@') + 1);
1673 $data["addr"] = $uri;
1674 $data["network"] = Protocol::MAIL;
1675 $data["name"] = substr($uri, 0, strpos($uri, '@'));
1676 $data["nick"] = $data["name"];
1677 $data["photo"] = Network::lookupAvatarByEmail($uri);
1678 $data["url"] = 'mailto:'.$uri;
1679 $data["notify"] = 'smtp ' . Strings::getRandomHex();
1680 $data["poll"] = 'email ' . Strings::getRandomHex();
1682 $x = Email::messageMeta($mbox, $msgs[0]);
1683 if (stristr($x[0]->from, $uri)) {
1684 $adr = imap_rfc822_parse_adrlist($x[0]->from, '');
1685 } elseif (stristr($x[0]->to, $uri)) {
1686 $adr = imap_rfc822_parse_adrlist($x[0]->to, '');
1689 foreach ($adr as $feadr) {
1690 if ((strcasecmp($feadr->mailbox, $data["name"]) == 0)
1691 &&(strcasecmp($feadr->host, $phost) == 0)
1692 && (strlen($feadr->personal))
1694 $personal = imap_mime_header_decode($feadr->personal);
1696 foreach ($personal as $perspart) {
1697 if ($perspart->charset != "default") {
1698 $data["name"] .= iconv($perspart->charset, 'UTF-8//IGNORE', $perspart->text);
1700 $data["name"] .= $perspart->text;
1704 $data["name"] = Strings::escapeTags($data["name"]);
1708 if (!empty($mbox)) {
1715 * @brief Mix two paths together to possibly fix missing parts
1717 * @param string $avatar Path to the avatar
1718 * @param string $base Another path that is hopefully complete
1720 * @return string fixed avatar path
1721 * @throws \Exception
1723 public static function fixAvatar($avatar, $base)
1725 $base_parts = parse_url($base);
1727 // Remove all parts that could create a problem
1728 unset($base_parts['path']);
1729 unset($base_parts['query']);
1730 unset($base_parts['fragment']);
1732 $avatar_parts = parse_url($avatar);
1735 $parts = array_merge($base_parts, $avatar_parts);
1737 // And put them together again
1738 $scheme = isset($parts['scheme']) ? $parts['scheme'] . '://' : '';
1739 $host = isset($parts['host']) ? $parts['host'] : '';
1740 $port = isset($parts['port']) ? ':' . $parts['port'] : '';
1741 $path = isset($parts['path']) ? $parts['path'] : '';
1742 $query = isset($parts['query']) ? '?' . $parts['query'] : '';
1743 $fragment = isset($parts['fragment']) ? '#' . $parts['fragment'] : '';
1745 $fixed = $scheme.$host.$port.$path.$query.$fragment;
1747 Logger::log('Base: '.$base.' - Avatar: '.$avatar.' - Fixed: '.$fixed, Logger::DATA);