From: Hypolite Petovan Date: Mon, 5 Feb 2018 17:57:41 +0000 (-0500) Subject: Rename Core\Network to Core\Protocol X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a0cdd9c67446b8e7a5a81e64e72478310a235d65;p=friendica.git Rename Core\Network to Core\Protocol --- diff --git a/boot.php b/boot.php index c996d06e39..a553698e5e 100644 --- a/boot.php +++ b/boot.php @@ -23,7 +23,7 @@ use Friendica\App; use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\L10n; -use Friendica\Core\Network; +use Friendica\Core\Protocol; use Friendica\Core\PConfig; use Friendica\Core\System; use Friendica\Core\Worker; @@ -249,33 +249,33 @@ define('PROTOCOL_SPLITTED_CONV', 6); */ /** - * @name Network + * @name Network constants * @deprecated since version 3.6 - * @see Friendica\Core\Network + * @see Friendica\Core\Protocol * * Network and protocol family types * @{ */ -define('NETWORK_DFRN' , Network::DFRN); // Friendica, Mistpark, other DFRN implementations -define('NETWORK_ZOT' , Network::ZOT); // Zot! - Currently unsupported -define('NETWORK_OSTATUS' , Network::OSTATUS); // GNU-social, Pleroma, Mastodon, other OStatus implementations -define('NETWORK_FEED' , Network::FEED); // RSS/Atom feeds with no known "post/notify" protocol -define('NETWORK_DIASPORA' , Network::DIASPORA); // Diaspora -define('NETWORK_MAIL' , Network::MAIL); // IMAP/POP -define('NETWORK_FACEBOOK' , Network::FACEBOOK); // Facebook API -define('NETWORK_LINKEDIN' , Network::LINKEDIN); // LinkedIn -define('NETWORK_XMPP' , Network::XMPP); // XMPP - Currently unsupported -define('NETWORK_MYSPACE' , Network::MYSPACE); // MySpace - Currently unsupported -define('NETWORK_GPLUS' , Network::GPLUS); // Google+ -define('NETWORK_PUMPIO' , Network::PUMPIO); // pump.io -define('NETWORK_TWITTER' , Network::TWITTER); // Twitter -define('NETWORK_DIASPORA2', Network::DIASPORA2); // Diaspora connector -define('NETWORK_STATUSNET', Network::STATUSNET); // Statusnet connector -define('NETWORK_APPNET' , Network::APPNET); // app.net - Dead protocol -define('NETWORK_NEWS' , Network::NEWS); // Network News Transfer Protocol - Currently unsupported -define('NETWORK_ICALENDAR', Network::ICALENDAR); // iCalendar - Currently unsupported -define('NETWORK_PNUT' , Network::PNUT); // pnut.io - Currently unsupported -define('NETWORK_PHANTOM' , Network::PHANTOM); // Place holder +define('NETWORK_DFRN' , Protocol::DFRN); // Friendica, Mistpark, other DFRN implementations +define('NETWORK_ZOT' , Protocol::ZOT); // Zot! - Currently unsupported +define('NETWORK_OSTATUS' , Protocol::OSTATUS); // GNU-social, Pleroma, Mastodon, other OStatus implementations +define('NETWORK_FEED' , Protocol::FEED); // RSS/Atom feeds with no known "post/notify" protocol +define('NETWORK_DIASPORA' , Protocol::DIASPORA); // Diaspora +define('NETWORK_MAIL' , Protocol::MAIL); // IMAP/POP +define('NETWORK_FACEBOOK' , Protocol::FACEBOOK); // Facebook API +define('NETWORK_LINKEDIN' , Protocol::LINKEDIN); // LinkedIn +define('NETWORK_XMPP' , Protocol::XMPP); // XMPP - Currently unsupported +define('NETWORK_MYSPACE' , Protocol::MYSPACE); // MySpace - Currently unsupported +define('NETWORK_GPLUS' , Protocol::GPLUS); // Google+ +define('NETWORK_PUMPIO' , Protocol::PUMPIO); // pump.io +define('NETWORK_TWITTER' , Protocol::TWITTER); // Twitter +define('NETWORK_DIASPORA2', Protocol::DIASPORA2); // Diaspora connector +define('NETWORK_STATUSNET', Protocol::STATUSNET); // Statusnet connector +define('NETWORK_APPNET' , Protocol::APPNET); // app.net - Dead protocol +define('NETWORK_NEWS' , Protocol::NEWS); // Network News Transfer Protocol - Currently unsupported +define('NETWORK_ICALENDAR', Protocol::ICALENDAR); // iCalendar - Currently unsupported +define('NETWORK_PNUT' , Protocol::PNUT); // pnut.io - Currently unsupported +define('NETWORK_PHANTOM' , Protocol::PHANTOM); // Place holder /** * @} */ diff --git a/include/acl_selectors.php b/include/acl_selectors.php index 166cf97197..076bb2a498 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -9,11 +9,11 @@ use Friendica\Content\Widget; use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\L10n; -use Friendica\Core\Network; +use Friendica\Core\Protocol; use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Model\GContact; -use Friendica\Util\Network as NetworkUtil; +use Friendica\Util\Network; require_once "mod/proxy.php"; @@ -250,7 +250,7 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p } if ($privmail) { - $trimmed = Network::formatMention($rr['url'], $rr['name']); + $trimmed = Protocol::formatMention($rr['url'], $rr['name']); } else { $trimmed = mb_substr($rr['name'],0,20); } @@ -736,7 +736,7 @@ function navbar_complete(App $a) { if (! $localsearch) { $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : ''); - $x = NetworkUtil::curl(get_server() . '/lsearch?f=' . $p . '&search=' . urlencode($search)); + $x = Network::curl(get_server() . '/lsearch?f=' . $p . '&search=' . urlencode($search)); if ($x['success']) { $j = json_decode($x['body'],true); if ($j && isset($j['results'])) { diff --git a/mod/display.php b/mod/display.php index dd6b8b709c..eb196b0979 100644 --- a/mod/display.php +++ b/mod/display.php @@ -6,7 +6,7 @@ use Friendica\App; use Friendica\Core\Config; use Friendica\Core\L10n; -use Friendica\Core\Network; +use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Model\Contact; @@ -173,7 +173,7 @@ function display_fetchauthor($a, $item) { $profiledata["photo"] = $matches[1]; } $profiledata["nickname"] = $profiledata["name"]; - $profiledata["network"] = Network::matchByProfileUrl($profiledata["url"]); + $profiledata["network"] = Protocol::matchByProfileUrl($profiledata["url"]); $profiledata["address"] = ""; $profiledata["about"] = ""; diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index d68208a60f..d2df3cee2f 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -13,13 +13,13 @@ use Friendica\Core\Addon; use Friendica\Core\Cache; use Friendica\Core\Config; use Friendica\Core\L10n; -use Friendica\Core\Network; +use Friendica\Core\Protocol; use Friendica\Core\PConfig; use Friendica\Core\System; use Friendica\Model\Contact; use Friendica\Object\Image; use Friendica\Util\Map; -use Friendica\Util\Network as NetworkUtil; +use Friendica\Util\Network; use Friendica\Util\ParseUrl; require_once "include/bbcode.php"; @@ -521,7 +521,7 @@ class BBCode } else { $scaled = $mtch[1]; } - $i = NetworkUtil::fetchUrl($scaled); + $i = Network::fetchUrl($scaled); if (!$i) { return $srctext; } @@ -1084,13 +1084,13 @@ class BBCode if (x($data, "name") && x($data, "addr")) { $userid_compact = $data["name"] . " (" . $data["addr"] . ")"; } else { - $userid_compact = Network::getAddrFromProfileUrl($profile, $author); + $userid_compact = Protocol::getAddrFromProfileUrl($profile, $author); } if (x($data, "addr")) { $userid = $data["addr"]; } else { - $userid = Network::formatMention($profile, $author); + $userid = Protocol::formatMention($profile, $author); } if (x($data, "name")) { diff --git a/src/Core/Network.php b/src/Core/Network.php deleted file mode 100644 index 0d59c7e85e..0000000000 --- a/src/Core/Network.php +++ /dev/null @@ -1,126 +0,0 @@ - - */ -class Network -{ - const DFRN = 'dfrn'; // Friendica, Mistpark, other DFRN implementations - const DIASPORA = 'dspr'; // Diaspora - const DIASPORA2 = 'dspc'; // Diaspora connector - const STATUSNET = 'stac'; // Statusnet connector - const OSTATUS = 'stat'; // GNU-social, Pleroma, Mastodon, other OStatus implementations - const FEED = 'feed'; // RSS/Atom feeds with no known "post/notify" protocol - const MAIL = 'mail'; // IMAP/POP - const XMPP = 'xmpp'; // XMPP - Currently unsupported - - const FACEBOOK = 'face'; // Facebook API - const LINKEDIN = 'lnkd'; // LinkedIn - const MYSPACE = 'mysp'; // MySpace - Currently unsupported - const GPLUS = 'goog'; // Google+ - const PUMPIO = 'pump'; // pump.io - const TWITTER = 'twit'; // Twitter - const APPNET = 'apdn'; // app.net - Dead protocol - - const NEWS = 'nntp'; // Network News Transfer Protocol - Currently unsupported - const ICALENDAR = 'ical'; // iCalendar - Currently unsupported - const PNUT = 'pnut'; // pnut.io - Currently unsupported - const ZOT = 'zot!'; // Zot! - Currently unsupported - - const PHANTOM = 'unkn'; // Place holder - - /** - * Returns the address string for the provided profile URL - * - * @param string $profile_url - * @return string - * @throws Exception - */ - public static function getAddrFromProfileUrl($profile_url) - { - $network = self::matchByProfileUrl($profile_url, $matches); - - if ($network === self::PHANTOM) { - throw new Exception('Unknown network for profile URL: ' . $profile_url); - } - - $addr = $matches[2] . '@' . $matches[1]; - - return $addr; - } - - /** - * Guesses the network from a profile URL - * - * @param string $profile_url - * @param array $matches preg_match return array: [0] => Full match [1] => hostname [2] => username - * @return type - */ - public static function matchByProfileUrl($profile_url, &$matches = []) - { - if (preg_match('=https?://(twitter\.com)/(.*)=ism', $profile_url, $matches)) { - return self::TWITTER; - } - - if (preg_match('=https?://(alpha\.app\.net)/(.*)=ism', $profile_url, $matches)) { - return self::APPNET; - } - - if (preg_match('=https?://(plus\.google\.com)/(.*)=ism', $profile_url, $matches)) { - return self::GPLUS; - } - - if (preg_match('=https?://(.*)/profile/(.*)=ism', $profile_url, $matches)) { - return self::DFRN; - } - - if (preg_match('=https?://(.*)/u/(.*)=ism', $profile_url, $matches)) { - return self::DIASPORA; - } - - if (preg_match('=https?://(.*)/channel/(.*)=ism', $profile_url, $matches)) { - // RedMatrix/Hubzilla is identified as Diaspora - friendica can't connect directly to it - return self::DIASPORA; - } - - if (preg_match('=https?://(.*)/user/(.*)=ism', $profile_url, $matches)) { - $statusnet_host = $matches[1]; - $statusnet_user = $matches[2]; - $UserData = Util\Network::fetchUrl('http://' . $statusnet_host . '/api/users/show.json?user_id=' . $statusnet_user); - $user = json_decode($UserData); - if ($user) { - $matches[2] = $user->screen_name; - return self::STATUSNET; - } - } - - // pumpio (http://host.name/user) - if (preg_match('=https?://([\.\w]+)/([\.\w]+)$=ism', $profile_url, $matches)) { - return self::PUMPIO; - } - - return self::PHANTOM; - } - - /** - * Returns a formatted mention from a profile URL and a display name - * - * @param string $profile_url - * @param string $display_name - * @return string - */ - public static function formatMention($profile_url, $display_name) - { - return $display_name . '(' . self::getAddrFromProfileUrl($profile_url) . ')'; - } -} diff --git a/src/Core/Protocol.php b/src/Core/Protocol.php new file mode 100644 index 0000000000..9caa0ab152 --- /dev/null +++ b/src/Core/Protocol.php @@ -0,0 +1,124 @@ + + */ +class Protocol +{ + const DFRN = 'dfrn'; // Friendica, Mistpark, other DFRN implementations + const DIASPORA = 'dspr'; // Diaspora + const DIASPORA2 = 'dspc'; // Diaspora connector + const STATUSNET = 'stac'; // Statusnet connector + const OSTATUS = 'stat'; // GNU-social, Pleroma, Mastodon, other OStatus implementations + const FEED = 'feed'; // RSS/Atom feeds with no known "post/notify" protocol + const MAIL = 'mail'; // IMAP/POP + const XMPP = 'xmpp'; // XMPP - Currently unsupported + + const FACEBOOK = 'face'; // Facebook API + const LINKEDIN = 'lnkd'; // LinkedIn + const MYSPACE = 'mysp'; // MySpace - Currently unsupported + const GPLUS = 'goog'; // Google+ + const PUMPIO = 'pump'; // pump.io + const TWITTER = 'twit'; // Twitter + const APPNET = 'apdn'; // app.net - Dead protocol + + const NEWS = 'nntp'; // Network News Transfer Protocol - Currently unsupported + const ICALENDAR = 'ical'; // iCalendar - Currently unsupported + const PNUT = 'pnut'; // pnut.io - Currently unsupported + const ZOT = 'zot!'; // Zot! - Currently unsupported + + const PHANTOM = 'unkn'; // Place holder + + /** + * Returns the address string for the provided profile URL + * + * @param string $profile_url + * @return string + * @throws Exception + */ + public static function getAddrFromProfileUrl($profile_url) + { + $network = self::matchByProfileUrl($profile_url, $matches); + + if ($network === self::PHANTOM) { + throw new Exception('Unknown network for profile URL: ' . $profile_url); + } + + $addr = $matches[2] . '@' . $matches[1]; + + return $addr; + } + + /** + * Guesses the network from a profile URL + * + * @param string $profile_url + * @param array $matches preg_match return array: [0] => Full match [1] => hostname [2] => username + * @return type + */ + public static function matchByProfileUrl($profile_url, &$matches = []) + { + if (preg_match('=https?://(twitter\.com)/(.*)=ism', $profile_url, $matches)) { + return self::TWITTER; + } + + if (preg_match('=https?://(alpha\.app\.net)/(.*)=ism', $profile_url, $matches)) { + return self::APPNET; + } + + if (preg_match('=https?://(plus\.google\.com)/(.*)=ism', $profile_url, $matches)) { + return self::GPLUS; + } + + if (preg_match('=https?://(.*)/profile/(.*)=ism', $profile_url, $matches)) { + return self::DFRN; + } + + if (preg_match('=https?://(.*)/u/(.*)=ism', $profile_url, $matches)) { + return self::DIASPORA; + } + + if (preg_match('=https?://(.*)/channel/(.*)=ism', $profile_url, $matches)) { + // RedMatrix/Hubzilla is identified as Diaspora - friendica can't connect directly to it + return self::DIASPORA; + } + + if (preg_match('=https?://(.*)/user/(.*)=ism', $profile_url, $matches)) { + $statusnet_host = $matches[1]; + $statusnet_user = $matches[2]; + $UserData = Network::fetchUrl('http://' . $statusnet_host . '/api/users/show.json?user_id=' . $statusnet_user); + $user = json_decode($UserData); + if ($user) { + $matches[2] = $user->screen_name; + return self::STATUSNET; + } + } + + // pumpio (http://host.name/user) + if (preg_match('=https?://([\.\w]+)/([\.\w]+)$=ism', $profile_url, $matches)) { + return self::PUMPIO; + } + + return self::PHANTOM; + } + + /** + * Returns a formatted mention from a profile URL and a display name + * + * @param string $profile_url + * @param string $display_name + * @return string + */ + public static function formatMention($profile_url, $display_name) + { + return $display_name . '(' . self::getAddrFromProfileUrl($profile_url) . ')'; + } +}