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 // Supported through a connector
27 const DIASPORA2 = 'dspc'; // Diaspora connector
28 const LINKEDIN = 'lnkd'; // LinkedIn
29 const PUMPIO = 'pump'; // pump.io
30 const STATUSNET = 'stac'; // Statusnet connector
31 const TWITTER = 'twit'; // Twitter
34 const APPNET = 'apdn'; // app.net - Dead protocol
35 const FACEBOOK = 'face'; // Facebook API - Not working anymore, API is closed
36 const GPLUS = 'goog'; // Google+ - Dead in 2019
38 // Currently unsupported
39 const ICALENDAR = 'ical'; // iCalendar
40 const MYSPACE = 'mysp'; // MySpace
41 const NEWS = 'nntp'; // Network News Transfer Protocol
42 const PNUT = 'pnut'; // pnut.io
43 const XMPP = 'xmpp'; // XMPP
44 const ZOT = 'zot!'; // Zot!
46 const PHANTOM = 'unkn'; // Place holder
49 * Returns the address string for the provided profile URL
51 * @param string $profile_url
55 public static function getAddrFromProfileUrl($profile_url)
57 $network = self::matchByProfileUrl($profile_url, $matches);
59 if ($network === self::PHANTOM) {
63 $addr = $matches[2] . '@' . $matches[1];
69 * Guesses the network from a profile URL
71 * @param string $profile_url
72 * @param array $matches preg_match return array: [0] => Full match [1] => hostname [2] => username
74 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
76 public static function matchByProfileUrl($profile_url, &$matches = [])
78 if (preg_match('=https?://(twitter\.com)/(.*)=ism', $profile_url, $matches)) {
82 if (preg_match('=https?://(alpha\.app\.net)/(.*)=ism', $profile_url, $matches)) {
86 if (preg_match('=https?://(plus\.google\.com)/(.*)=ism', $profile_url, $matches)) {
90 if (preg_match('=https?://(.*)/profile/(.*)=ism', $profile_url, $matches)) {
94 if (preg_match('=https?://(.*)/u/(.*)=ism', $profile_url, $matches)) {
95 return self::DIASPORA;
98 if (preg_match('=https?://(.*)/channel/(.*)=ism', $profile_url, $matches)) {
99 // RedMatrix/Hubzilla is identified as Diaspora - friendica can't connect directly to it
100 return self::DIASPORA;
103 if (preg_match('=https?://(.*)/user/(.*)=ism', $profile_url, $matches)) {
104 $statusnet_host = $matches[1];
105 $statusnet_user = $matches[2];
106 $UserData = Network::fetchUrl('http://' . $statusnet_host . '/api/users/show.json?user_id=' . $statusnet_user);
107 $user = json_decode($UserData);
109 $matches[2] = $user->screen_name;
110 return self::STATUSNET;
115 if (preg_match('=https?://(.+?)/users/(.+)=ism', $profile_url, $matches)
116 || preg_match('=https?://(.+?)/@(.+)=ism', $profile_url, $matches)
118 return self::ACTIVITYPUB;
121 // pumpio (http://host.name/user)
122 if (preg_match('=https?://([\.\w]+)/([\.\w]+)$=ism', $profile_url, $matches)) {
126 return self::PHANTOM;
130 * Returns a formatted mention from a profile URL and a display name
132 * @param string $profile_url
133 * @param string $display_name
137 public static function formatMention($profile_url, $display_name)
139 return $display_name . ' (' . self::getAddrFromProfileUrl($profile_url) . ')';