4 * @file src/Core/Network.php
\r
7 namespace Friendica\Core;
\r
12 * Manage compatibility with federated networks
\r
14 * @author Hypolite Petovan <mrpetovan@gmail.com>
\r
18 const DFRN = 'dfrn'; // Friendica, Mistpark, other DFRN implementations
\r
19 const DIASPORA = 'dspr'; // Diaspora
\r
20 const DIASPORA2 = 'dspc'; // Diaspora connector
\r
21 const STATUSNET = 'stac'; // Statusnet connector
\r
22 const OSTATUS = 'stat'; // GNU-social, Pleroma, Mastodon, other OStatus implementations
\r
23 const FEED = 'feed'; // RSS/Atom feeds with no known "post/notify" protocol
\r
24 const MAIL = 'mail'; // IMAP/POP
\r
25 const XMPP = 'xmpp'; // XMPP - Currently unsupported
\r
27 const FACEBOOK = 'face'; // Facebook API
\r
28 const LINKEDIN = 'lnkd'; // LinkedIn
\r
29 const MYSPACE = 'mysp'; // MySpace - Currently unsupported
\r
30 const GPLUS = 'goog'; // Google+
\r
31 const PUMPIO = 'pump'; // pump.io
\r
32 const TWITTER = 'twit'; // Twitter
\r
33 const APPNET = 'apdn'; // app.net - Dead protocol
\r
35 const NEWS = 'nntp'; // Network News Transfer Protocol - Currently unsupported
\r
36 const ICALENDAR = 'ical'; // iCalendar - Currently unsupported
\r
37 const PNUT = 'pnut'; // pnut.io - Currently unsupported
\r
38 const ZOT = 'zot!'; // Zot! - Currently unsupported
\r
40 const PHANTOM = 'unkn'; // Place holder
\r
43 * Returns the address string for the provided profile URL
\r
45 * @param string $profile_url
\r
49 public static function getAddrFromProfileUrl($profile_url)
\r
51 $network = self::matchByProfileUrl($profile_url, $matches);
\r
53 if ($network === self::PHANTOM) {
\r
54 throw new Exception('Unknown network for profile URL: ' . $profile_url);
\r
57 $addr = $matches[2] . '@' . $matches[1];
\r
63 * Guesses the network from a profile URL
\r
65 * @param string $profile_url
\r
66 * @param array $matches preg_match return array: [0] => Full match [1] => hostname [2] => username
\r
69 public static function matchByProfileUrl($profile_url, &$matches = [])
\r
71 if (preg_match('=https?://(twitter\.com)/(.*)=ism', $profile_url, $matches)) {
\r
72 return self::TWITTER;
\r
75 if (preg_match('=https?://(alpha\.app\.net)/(.*)=ism', $profile_url, $matches)) {
\r
76 return self::APPNET;
\r
79 if (preg_match('=https?://(plus\.google\.com)/(.*)=ism', $profile_url, $matches)) {
\r
83 if (preg_match('=https?://(.*)/profile/(.*)=ism', $profile_url, $matches)) {
\r
87 if (preg_match('=https?://(.*)/u/(.*)=ism', $profile_url, $matches)) {
\r
88 return self::DIASPORA;
\r
91 if (preg_match('=https?://(.*)/channel/(.*)=ism', $profile_url, $matches)) {
\r
92 // RedMatrix/Hubzilla is identified as Diaspora - friendica can't connect directly to it
\r
93 return self::DIASPORA;
\r
96 if (preg_match('=https?://(.*)/user/(.*)=ism', $profile_url, $matches)) {
\r
97 $statusnet_host = $matches[1];
\r
98 $statusnet_user = $matches[2];
\r
99 $UserData = Util\Network::fetchUrl('http://' . $statusnet_host . '/api/users/show.json?user_id=' . $statusnet_user);
\r
100 $user = json_decode($UserData);
\r
102 $matches[2] = $user->screen_name;
\r
103 return self::STATUSNET;
\r
107 // pumpio (http://host.name/user)
\r
108 if (preg_match('=https?://([\.\w]+)/([\.\w]+)$=ism', $profile_url, $matches)) {
\r
109 return self::PUMPIO;
\r
112 return self::PHANTOM;
\r
116 * Returns a formatted mention from a profile URL and a display name
\r
118 * @param string $profile_url
\r
119 * @param string $display_name
\r
122 public static function formatMention($profile_url, $display_name)
\r
124 return $display_name . '(' . self::getAddrFromProfileUrl($profile_url) . ')';
\r