3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Core;
25 * Manage compatibility with federated networks
30 const ACTIVITYPUB = 'apub'; // ActivityPub (Pleroma, Mastodon, Osada, ...)
31 const DFRN = 'dfrn'; // Friendica, Mistpark, other DFRN implementations
32 const DIASPORA = 'dspr'; // Diaspora, Hubzilla, Socialhome, Ganggo
33 const FEED = 'feed'; // RSS/Atom feeds with no known "post/notify" protocol
34 const MAIL = 'mail'; // IMAP/POP
35 const OSTATUS = 'stat'; // GNU Social and other OStatus implementations
37 const NATIVE_SUPPORT = [self::DFRN, self::DIASPORA, self::OSTATUS, self::FEED, self::MAIL, self::ACTIVITYPUB];
39 const FEDERATED = [self::DFRN, self::DIASPORA, self::OSTATUS, self::ACTIVITYPUB];
41 const SUPPORT_PRIVATE = [self::DFRN, self::DIASPORA, self::MAIL, self::ACTIVITYPUB, self::PUMPIO];
43 // Supported through a connector
44 const DIASPORA2 = 'dspc'; // Diaspora connector
45 const LINKEDIN = 'lnkd'; // LinkedIn
46 const PUMPIO = 'pump'; // pump.io
47 const STATUSNET = 'stac'; // Statusnet connector
48 const TWITTER = 'twit'; // Twitter
49 const DISCOURSE = 'dscs'; // Discourse
52 const APPNET = 'apdn'; // app.net - Dead protocol
53 const FACEBOOK = 'face'; // Facebook API - Not working anymore, API is closed
54 const GPLUS = 'goog'; // Google+ - Dead in 2019
56 // Currently unsupported
57 const ICALENDAR = 'ical'; // iCalendar
58 const MYSPACE = 'mysp'; // MySpace
59 const NEWS = 'nntp'; // Network News Transfer Protocol
60 const PNUT = 'pnut'; // pnut.io
61 const XMPP = 'xmpp'; // XMPP
62 const ZOT = 'zot!'; // Zot!
64 const PHANTOM = 'unkn'; // Place holder
67 * Returns the address string for the provided profile URL
69 * @param string $profile_url
73 public static function getAddrFromProfileUrl($profile_url)
75 $network = self::matchByProfileUrl($profile_url, $matches);
77 if ($network === self::PHANTOM) {
81 $addr = $matches[2] . '@' . $matches[1];
87 * Guesses the network from a profile URL
89 * @param string $profile_url
90 * @param array $matches preg_match return array: [0] => Full match [1] => hostname [2] => username
92 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
94 public static function matchByProfileUrl($profile_url, &$matches = [])
96 if (preg_match('=https?://(twitter\.com)/(.*)=ism', $profile_url, $matches)) {
100 if (preg_match('=https?://(alpha\.app\.net)/(.*)=ism', $profile_url, $matches)) {
104 if (preg_match('=https?://(plus\.google\.com)/(.*)=ism', $profile_url, $matches)) {
108 if (preg_match('=https?://(.*)/profile/(.*)=ism', $profile_url, $matches)) {
112 if (preg_match('=https?://(.*)/u/(.*)=ism', $profile_url, $matches)) {
113 return self::DIASPORA;
116 if (preg_match('=https?://(.*)/channel/(.*)=ism', $profile_url, $matches)) {
117 // RedMatrix/Hubzilla is identified as Diaspora - friendica can't connect directly to it
118 return self::DIASPORA;
121 if (preg_match('=https?://(.*)/user/(.*)=ism', $profile_url, $matches)) {
122 $statusnet_host = $matches[1];
123 $statusnet_user = $matches[2];
124 $UserData = DI::httpRequest()->fetchUrl('http://' . $statusnet_host . '/api/users/show.json?user_id=' . $statusnet_user);
125 $user = json_decode($UserData);
127 $matches[2] = $user->screen_name;
128 return self::STATUSNET;
133 if (preg_match('=https?://(.+?)/users/(.+)=ism', $profile_url, $matches)
134 || preg_match('=https?://(.+?)/@(.+)=ism', $profile_url, $matches)
136 return self::ACTIVITYPUB;
139 // pumpio (http://host.name/user)
140 if (preg_match('=https?://([\.\w]+)/([\.\w]+)$=ism', $profile_url, $matches)) {
144 return self::PHANTOM;
148 * Returns a formatted mention from a profile URL and a display name
150 * @param string $profile_url
151 * @param string $display_name
155 public static function formatMention($profile_url, $display_name)
157 return $display_name . ' (' . self::getAddrFromProfileUrl($profile_url) . ')';