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>
16 const DFRN = 'dfrn'; // Friendica, Mistpark, other DFRN implementations
17 const DIASPORA = 'dspr'; // Diaspora
18 const DIASPORA2 = 'dspc'; // Diaspora connector
19 const STATUSNET = 'stac'; // Statusnet connector
20 const OSTATUS = 'stat'; // GNU-social, Pleroma, Mastodon, other OStatus implementations
21 const FEED = 'feed'; // RSS/Atom feeds with no known "post/notify" protocol
22 const MAIL = 'mail'; // IMAP/POP
23 const XMPP = 'xmpp'; // XMPP - Currently unsupported
25 const FACEBOOK = 'face'; // Facebook API
26 const LINKEDIN = 'lnkd'; // LinkedIn
27 const MYSPACE = 'mysp'; // MySpace - Currently unsupported
28 const GPLUS = 'goog'; // Google+
29 const PUMPIO = 'pump'; // pump.io
30 const TWITTER = 'twit'; // Twitter
31 const APPNET = 'apdn'; // app.net - Dead protocol
33 const NEWS = 'nntp'; // Network News Transfer Protocol - Currently unsupported
34 const ICALENDAR = 'ical'; // iCalendar - Currently unsupported
35 const PNUT = 'pnut'; // pnut.io - Currently unsupported
36 const ZOT = 'zot!'; // Zot! - Currently unsupported
38 const PHANTOM = 'unkn'; // Place holder
41 * Returns the address string for the provided profile URL
43 * @param string $profile_url
47 public static function getAddrFromProfileUrl($profile_url)
49 $network = self::matchByProfileUrl($profile_url, $matches);
51 if ($network === self::PHANTOM) {
55 $addr = $matches[2] . '@' . $matches[1];
61 * Guesses the network from a profile URL
63 * @param string $profile_url
64 * @param array $matches preg_match return array: [0] => Full match [1] => hostname [2] => username
67 public static function matchByProfileUrl($profile_url, &$matches = [])
69 if (preg_match('=https?://(twitter\.com)/(.*)=ism', $profile_url, $matches)) {
73 if (preg_match('=https?://(alpha\.app\.net)/(.*)=ism', $profile_url, $matches)) {
77 if (preg_match('=https?://(plus\.google\.com)/(.*)=ism', $profile_url, $matches)) {
81 if (preg_match('=https?://(.*)/profile/(.*)=ism', $profile_url, $matches)) {
85 if (preg_match('=https?://(.*)/u/(.*)=ism', $profile_url, $matches)) {
86 return self::DIASPORA;
89 if (preg_match('=https?://(.*)/channel/(.*)=ism', $profile_url, $matches)) {
90 // RedMatrix/Hubzilla is identified as Diaspora - friendica can't connect directly to it
91 return self::DIASPORA;
94 if (preg_match('=https?://(.*)/user/(.*)=ism', $profile_url, $matches)) {
95 $statusnet_host = $matches[1];
96 $statusnet_user = $matches[2];
97 $UserData = Network::fetchUrl('http://' . $statusnet_host . '/api/users/show.json?user_id=' . $statusnet_user);
98 $user = json_decode($UserData);
100 $matches[2] = $user->screen_name;
101 return self::STATUSNET;
105 // pumpio (http://host.name/user)
106 if (preg_match('=https?://([\.\w]+)/([\.\w]+)$=ism', $profile_url, $matches)) {
110 return self::PHANTOM;
114 * Returns a formatted mention from a profile URL and a display name
116 * @param string $profile_url
117 * @param string $display_name
120 public static function formatMention($profile_url, $display_name)
122 return $display_name . '(' . self::getAddrFromProfileUrl($profile_url) . ')';