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 <mrpetovan@gmail.com>
17 const ACTIVITYPUB = 'apub'; // ActivityPub
18 const DFRN = 'dfrn'; // Friendica, Mistpark, other DFRN implementations
19 const DIASPORA = 'dspr'; // Diaspora
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, Pleroma, Mastodon, 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 APPNET = 'apdn'; // app.net - Dead protocol
28 const DIASPORA2 = 'dspc'; // Diaspora connector
29 const FACEBOOK = 'face'; // Facebook API
30 const GPLUS = 'goog'; // Google+
31 const LINKEDIN = 'lnkd'; // LinkedIn
32 const PUMPIO = 'pump'; // pump.io
33 const STATUSNET = 'stac'; // Statusnet connector
34 const TWITTER = 'twit'; // Twitter
36 // Currently unsupported
37 const ICALENDAR = 'ical'; // iCalendar
38 const MYSPACE = 'mysp'; // MySpace
39 const NEWS = 'nntp'; // Network News Transfer Protocol
40 const PNUT = 'pnut'; // pnut.io
41 const XMPP = 'xmpp'; // XMPP
42 const ZOT = 'zot!'; // Zot!
44 const PHANTOM = 'unkn'; // Place holder
47 * Returns the address string for the provided profile URL
49 * @param string $profile_url
53 public static function getAddrFromProfileUrl($profile_url)
55 $network = self::matchByProfileUrl($profile_url, $matches);
57 if ($network === self::PHANTOM) {
61 $addr = $matches[2] . '@' . $matches[1];
67 * Guesses the network from a profile URL
69 * @param string $profile_url
70 * @param array $matches preg_match return array: [0] => Full match [1] => hostname [2] => username
73 public static function matchByProfileUrl($profile_url, &$matches = [])
75 if (preg_match('=https?://(twitter\.com)/(.*)=ism', $profile_url, $matches)) {
79 if (preg_match('=https?://(alpha\.app\.net)/(.*)=ism', $profile_url, $matches)) {
83 if (preg_match('=https?://(plus\.google\.com)/(.*)=ism', $profile_url, $matches)) {
87 if (preg_match('=https?://(.*)/profile/(.*)=ism', $profile_url, $matches)) {
91 if (preg_match('=https?://(.*)/u/(.*)=ism', $profile_url, $matches)) {
92 return self::DIASPORA;
95 if (preg_match('=https?://(.*)/channel/(.*)=ism', $profile_url, $matches)) {
96 // RedMatrix/Hubzilla is identified as Diaspora - friendica can't connect directly to it
97 return self::DIASPORA;
100 if (preg_match('=https?://(.*)/user/(.*)=ism', $profile_url, $matches)) {
101 $statusnet_host = $matches[1];
102 $statusnet_user = $matches[2];
103 $UserData = Network::fetchUrl('http://' . $statusnet_host . '/api/users/show.json?user_id=' . $statusnet_user);
104 $user = json_decode($UserData);
106 $matches[2] = $user->screen_name;
107 return self::STATUSNET;
111 // pumpio (http://host.name/user)
112 if (preg_match('=https?://([\.\w]+)/([\.\w]+)$=ism', $profile_url, $matches)) {
116 return self::PHANTOM;
120 * Returns a formatted mention from a profile URL and a display name
122 * @param string $profile_url
123 * @param string $display_name
126 public static function formatMention($profile_url, $display_name)
128 return $display_name . ' (' . self::getAddrFromProfileUrl($profile_url) . ')';