3 * @file src/Core/Protocol.php
5 namespace Friendica\Core;
7 use Friendica\Util\Network;
10 * Manage compatibility with federated networks
12 * @author Hypolite Petovan <hypolite@mrpetovan.com>
17 const ACTIVITYPUB = 'apub'; // ActivityPub (Pleroma, Mastodon, Osada, ...)
18 const DFRN = 'dfrn'; // Friendica, Mistpark, other DFRN implementations
19 const DIASPORA = 'dspr'; // Diaspora, Hubzilla, Socialhome, Ganggo
20 const FEED = 'feed'; // RSS/Atom feeds with no known "post/notify" protocol
21 const MAIL = 'mail'; // IMAP/POP
22 const OSTATUS = 'stat'; // GNU Social and other OStatus implementations
24 const NATIVE_SUPPORT = [self::DFRN, self::DIASPORA, self::OSTATUS, self::FEED, self::MAIL, self::ACTIVITYPUB];
26 const FEDERATED = [self::DFRN, self::DIASPORA, self::OSTATUS, self::ACTIVITYPUB];
28 // Supported through a connector
29 const DIASPORA2 = 'dspc'; // Diaspora connector
30 const LINKEDIN = 'lnkd'; // LinkedIn
31 const PUMPIO = 'pump'; // pump.io
32 const STATUSNET = 'stac'; // Statusnet connector
33 const TWITTER = 'twit'; // Twitter
36 const APPNET = 'apdn'; // app.net - Dead protocol
37 const FACEBOOK = 'face'; // Facebook API - Not working anymore, API is closed
38 const GPLUS = 'goog'; // Google+ - Dead in 2019
40 // Currently unsupported
41 const ICALENDAR = 'ical'; // iCalendar
42 const MYSPACE = 'mysp'; // MySpace
43 const NEWS = 'nntp'; // Network News Transfer Protocol
44 const PNUT = 'pnut'; // pnut.io
45 const XMPP = 'xmpp'; // XMPP
46 const ZOT = 'zot!'; // Zot!
48 const PHANTOM = 'unkn'; // Place holder
51 * Returns the address string for the provided profile URL
53 * @param string $profile_url
57 public static function getAddrFromProfileUrl($profile_url)
59 $network = self::matchByProfileUrl($profile_url, $matches);
61 if ($network === self::PHANTOM) {
65 $addr = $matches[2] . '@' . $matches[1];
71 * Guesses the network from a profile URL
73 * @param string $profile_url
74 * @param array $matches preg_match return array: [0] => Full match [1] => hostname [2] => username
76 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
78 public static function matchByProfileUrl($profile_url, &$matches = [])
80 if (preg_match('=https?://(twitter\.com)/(.*)=ism', $profile_url, $matches)) {
84 if (preg_match('=https?://(alpha\.app\.net)/(.*)=ism', $profile_url, $matches)) {
88 if (preg_match('=https?://(plus\.google\.com)/(.*)=ism', $profile_url, $matches)) {
92 if (preg_match('=https?://(.*)/profile/(.*)=ism', $profile_url, $matches)) {
96 if (preg_match('=https?://(.*)/u/(.*)=ism', $profile_url, $matches)) {
97 return self::DIASPORA;
100 if (preg_match('=https?://(.*)/channel/(.*)=ism', $profile_url, $matches)) {
101 // RedMatrix/Hubzilla is identified as Diaspora - friendica can't connect directly to it
102 return self::DIASPORA;
105 if (preg_match('=https?://(.*)/user/(.*)=ism', $profile_url, $matches)) {
106 $statusnet_host = $matches[1];
107 $statusnet_user = $matches[2];
108 $UserData = Network::fetchUrl('http://' . $statusnet_host . '/api/users/show.json?user_id=' . $statusnet_user);
109 $user = json_decode($UserData);
111 $matches[2] = $user->screen_name;
112 return self::STATUSNET;
117 if (preg_match('=https?://(.+?)/users/(.+)=ism', $profile_url, $matches)
118 || preg_match('=https?://(.+?)/@(.+)=ism', $profile_url, $matches)
120 return self::ACTIVITYPUB;
123 // pumpio (http://host.name/user)
124 if (preg_match('=https?://([\.\w]+)/([\.\w]+)$=ism', $profile_url, $matches)) {
128 return self::PHANTOM;
132 * Returns a formatted mention from a profile URL and a display name
134 * @param string $profile_url
135 * @param string $display_name
139 public static function formatMention($profile_url, $display_name)
141 return $display_name . ' (' . self::getAddrFromProfileUrl($profile_url) . ')';