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
36 const DISCOURSE = 'dscs'; // Discourse
39 const APPNET = 'apdn'; // app.net - Dead protocol
40 const FACEBOOK = 'face'; // Facebook API - Not working anymore, API is closed
41 const GPLUS = 'goog'; // Google+ - Dead in 2019
43 // Currently unsupported
44 const ICALENDAR = 'ical'; // iCalendar
45 const MYSPACE = 'mysp'; // MySpace
46 const NEWS = 'nntp'; // Network News Transfer Protocol
47 const PNUT = 'pnut'; // pnut.io
48 const XMPP = 'xmpp'; // XMPP
49 const ZOT = 'zot!'; // Zot!
51 const PHANTOM = 'unkn'; // Place holder
54 * Returns the address string for the provided profile URL
56 * @param string $profile_url
60 public static function getAddrFromProfileUrl($profile_url)
62 $network = self::matchByProfileUrl($profile_url, $matches);
64 if ($network === self::PHANTOM) {
68 $addr = $matches[2] . '@' . $matches[1];
74 * Guesses the network from a profile URL
76 * @param string $profile_url
77 * @param array $matches preg_match return array: [0] => Full match [1] => hostname [2] => username
79 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
81 public static function matchByProfileUrl($profile_url, &$matches = [])
83 if (preg_match('=https?://(twitter\.com)/(.*)=ism', $profile_url, $matches)) {
87 if (preg_match('=https?://(alpha\.app\.net)/(.*)=ism', $profile_url, $matches)) {
91 if (preg_match('=https?://(plus\.google\.com)/(.*)=ism', $profile_url, $matches)) {
95 if (preg_match('=https?://(.*)/profile/(.*)=ism', $profile_url, $matches)) {
99 if (preg_match('=https?://(.*)/u/(.*)=ism', $profile_url, $matches)) {
100 return self::DIASPORA;
103 if (preg_match('=https?://(.*)/channel/(.*)=ism', $profile_url, $matches)) {
104 // RedMatrix/Hubzilla is identified as Diaspora - friendica can't connect directly to it
105 return self::DIASPORA;
108 if (preg_match('=https?://(.*)/user/(.*)=ism', $profile_url, $matches)) {
109 $statusnet_host = $matches[1];
110 $statusnet_user = $matches[2];
111 $UserData = Network::fetchUrl('http://' . $statusnet_host . '/api/users/show.json?user_id=' . $statusnet_user);
112 $user = json_decode($UserData);
114 $matches[2] = $user->screen_name;
115 return self::STATUSNET;
120 if (preg_match('=https?://(.+?)/users/(.+)=ism', $profile_url, $matches)
121 || preg_match('=https?://(.+?)/@(.+)=ism', $profile_url, $matches)
123 return self::ACTIVITYPUB;
126 // pumpio (http://host.name/user)
127 if (preg_match('=https?://([\.\w]+)/([\.\w]+)$=ism', $profile_url, $matches)) {
131 return self::PHANTOM;
135 * Returns a formatted mention from a profile URL and a display name
137 * @param string $profile_url
138 * @param string $display_name
142 public static function formatMention($profile_url, $display_name)
144 return $display_name . ' (' . self::getAddrFromProfileUrl($profile_url) . ')';