]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/PortableContact.php
BBCode - fixed syntax error
[friendica.git] / src / Protocol / PortableContact.php
index cd85c1c0ae0f6b6c6b107c12bc1840535aa5b780..0bc17d3dce17000b33dbf5e799ca84a6f60292f0 100644 (file)
@@ -20,14 +20,13 @@ use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\Model\GContact;
 use Friendica\Model\Profile;
+use Friendica\Module\Register;
 use Friendica\Network\Probe;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\Strings;
 use Friendica\Util\XML;
 
-require_once 'include/dba.php';
-
 class PortableContact
 {
        /**
@@ -46,7 +45,7 @@ class PortableContact
         * Once the global contact is stored add (if necessary) the contact linkage which associates
         * the given uid, cid to the global contact entry. There can be many uid/cid combinations
         * pointing to the same global contact id.
-        *
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        public static function loadWorker($cid, $uid = 0, $zcid = 0, $url = null)
        {
@@ -61,12 +60,10 @@ class PortableContact
         * @param integer $uid  User ID
         * @param integer $zcid Global Contact ID
         * @param integer $url  POCO address that should be polled
-        *
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        public static function load($cid, $uid, $zcid, $url)
        {
-               $a = get_app();
-
                if ($cid) {
                        if (!$url || !$uid) {
                                $contact = DBA::selectFirst('contact', ['poco', 'uid'], ['id' => $cid]);
@@ -232,7 +229,6 @@ class PortableContact
                        $friendica = preg_replace("=(https?://)(.*)/profile/(.*)=ism", "$1$2", $profile);
                        if ($friendica != $profile) {
                                $server_url = $friendica;
-                               $network = Protocol::DFRN;
                        }
                }
 
@@ -240,7 +236,6 @@ class PortableContact
                        $diaspora = preg_replace("=(https?://)(.*)/u/(.*)=ism", "$1$2", $profile);
                        if ($diaspora != $profile) {
                                $server_url = $diaspora;
-                               $network = Protocol::DIASPORA;
                        }
                }
 
@@ -248,7 +243,6 @@ class PortableContact
                        $red = preg_replace("=(https?://)(.*)/channel/(.*)=ism", "$1$2", $profile);
                        if ($red != $profile) {
                                $server_url = $red;
-                               $network = Protocol::DIASPORA;
                        }
                }
 
@@ -257,7 +251,6 @@ class PortableContact
                        $mastodon = preg_replace("=(https?://)(.*)/users/(.*)=ism", "$1$2", $profile);
                        if ($mastodon != $profile) {
                                $server_url = $mastodon;
-                               $network = Protocol::OSTATUS;
                        }
                }
 
@@ -266,7 +259,6 @@ class PortableContact
                        $ostatus = preg_replace("=(https?://)(.*)/user/(.*)=ism", "$1$2", $profile);
                        if ($ostatus != $profile) {
                                $server_url = $ostatus;
-                               $network = Protocol::OSTATUS;
                        }
                }
 
@@ -275,7 +267,6 @@ class PortableContact
                        $base = preg_replace("=(https?://)(.*?)/(.*)=ism", "$1$2", $profile);
                        if ($base != $profile) {
                                $server_url = $base;
-                               $network = Protocol::PHANTOM;
                        }
                }
 
@@ -336,7 +327,7 @@ class PortableContact
                        $server_url = Strings::normaliseLink(self::detectServer($profile));
                }
 
-               if (!in_array($gcontacts[0]["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::FEED, Protocol::OSTATUS, ""])) {
+               if (!in_array($gcontacts[0]["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::FEED, Protocol::OSTATUS, ""])) {
                        Logger::log("Profile ".$profile.": Network type ".$gcontacts[0]["network"]." can't be checked", Logger::DEBUG);
                        return false;
                }
@@ -611,8 +602,6 @@ class PortableContact
         */
        private static function detectPocoData(array $data)
        {
-               $server = false;
-
                if (!isset($data['entry'])) {
                        return false;
                }
@@ -645,6 +634,7 @@ class PortableContact
         *
         * @param string $server_url address of the server
         * @return array Server data
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        private static function fetchNodeinfo($server_url)
        {
@@ -698,6 +688,7 @@ class PortableContact
         *
         * @param string $nodeinfo_url address of the nodeinfo path
         * @return array Server data
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        private static function parseNodeinfo1($nodeinfo_url)
        {
@@ -715,10 +706,10 @@ class PortableContact
 
                $server = [];
 
-               $server['register_policy'] = REGISTER_CLOSED;
+               $server['register_policy'] = Register::CLOSED;
 
                if (is_bool($nodeinfo['openRegistrations']) && $nodeinfo['openRegistrations']) {
-                       $server['register_policy'] = REGISTER_OPEN;
+                       $server['register_policy'] = Register::OPEN;
                }
 
                if (is_array($nodeinfo['software'])) {
@@ -782,6 +773,7 @@ class PortableContact
         *
         * @param string $nodeinfo_url address of the nodeinfo path
         * @return array Server data
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        private static function parseNodeinfo2($nodeinfo_url)
        {
@@ -798,10 +790,10 @@ class PortableContact
 
                $server = [];
 
-               $server['register_policy'] = REGISTER_CLOSED;
+               $server['register_policy'] = Register::CLOSED;
 
                if (is_bool($nodeinfo['openRegistrations']) && $nodeinfo['openRegistrations']) {
-                       $server['register_policy'] = REGISTER_OPEN;
+                       $server['register_policy'] = Register::OPEN;
                }
 
                if (is_array($nodeinfo['software'])) {
@@ -1201,16 +1193,16 @@ class PortableContact
                                if (!empty($data['register_policy'])) {
                                        switch ($data['register_policy']) {
                                                case "REGISTER_OPEN":
-                                                       $register_policy = REGISTER_OPEN;
+                                                       $register_policy = Register::OPEN;
                                                        break;
 
                                                case "REGISTER_APPROVE":
-                                                       $register_policy = REGISTER_APPROVE;
+                                                       $register_policy = Register::APPROVE;
                                                        break;
 
                                                case "REGISTER_CLOSED":
                                                default:
-                                                       $register_policy = REGISTER_CLOSED;
+                                                       $register_policy = Register::CLOSED;
                                                        break;
                                        }
                                }
@@ -1276,11 +1268,11 @@ class PortableContact
                                                }
 
                                                if (!$closed && !$private and $inviteonly) {
-                                                       $register_policy = REGISTER_APPROVE;
+                                                       $register_policy = Register::APPROVE;
                                                } elseif (!$closed && !$private) {
-                                                       $register_policy = REGISTER_OPEN;
+                                                       $register_policy = Register::OPEN;
                                                } else {
-                                                       $register_policy = REGISTER_CLOSED;
+                                                       $register_policy = Register::CLOSED;
                                                }
                                        }
                                }
@@ -1314,9 +1306,9 @@ class PortableContact
                                }
 
                                if (!empty($data['registrations_open']) && $data['registrations_open']) {
-                                       $register_policy = REGISTER_OPEN;
+                                       $register_policy = Register::OPEN;
                                } else {
-                                       $register_policy = REGISTER_CLOSED;
+                                       $register_policy = Register::CLOSED;
                                }
                        }
                }
@@ -1376,13 +1368,27 @@ class PortableContact
                                        }
 
                                        $info = defaults($data, 'info', '');
-                                       $register_policy = defaults($data, 'register_policy', REGISTER_CLOSED);
-                                       if (in_array($register_policy, ['REGISTER_CLOSED', 'REGISTER_APPROVE', 'REGISTER_OPEN'])) {
-                                               $register_policy = constant($data['register_policy']);
-                                       } else {
-                                               Logger::log("Register policy '$register_policy' from $server_url is invalid.");
-                                               $register_policy = REGISTER_CLOSED; // set a default value
+
+                                       $register_policy = defaults($data, 'register_policy', 'REGISTER_CLOSED');
+                                       switch ($register_policy) {
+                                               case 'REGISTER_OPEN':
+                                                       $register_policy = Register::OPEN;
+                                                       break;
+
+                                               case 'REGISTER_APPROVE':
+                                                       $register_policy = Register::APPROVE;
+                                                       break;
+
+                                               default:
+                                                       Logger::log("Register policy '$register_policy' from $server_url is invalid.");
+                                                       // Defaulting to closed
+
+                                               case 'REGISTER_CLOSED':
+                                               case 'REGISTER_INVITATION':
+                                                       $register_policy = Register::CLOSED;
+                                                       break;
                                        }
+
                                        $platform = defaults($data, 'platform', '');
                                }
                        }
@@ -1446,6 +1452,7 @@ class PortableContact
         * @brief Fetch relay data from a given server url
         *
         * @param string $server_url address of the server
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        private static function discoverRelay($server_url)
        {
@@ -1520,6 +1527,7 @@ class PortableContact
        /**
         * @brief Returns a list of all known servers
         * @return array List of server urls
+        * @throws Exception
         */
        public static function serverlist()
        {
@@ -1544,6 +1552,7 @@ class PortableContact
         * @brief Fetch server list from remote servers and adds them when they are new.
         *
         * @param string $poco URL to the POCO endpoint
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        private static function fetchServerlist($poco)
        {