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