]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/GlobalContact.php
Review
[friendica.git] / src / Model / GlobalContact.php
index dc62024bc4095120ca6f24aa11bb33bdc6c100bc..6ec1101775df0f636f838a7e6c29499fce4166ce 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 /**
  * @file src/Model/GlobalContact.php
  * @brief This file includes the GlobalContact class with directory related functions
@@ -8,8 +7,11 @@ namespace Friendica\Model;
 
 use Friendica\Core\Config;
 use Friendica\Core\System;
+use Friendica\Core\Worker;
 use Friendica\Database\DBM;
 use Friendica\Network\Probe;
+use Friendica\Object\Contact;
+use Friendica\Object\Profile;
 use Friendica\Protocol\PortableContact;
 use dba;
 use Exception;
@@ -17,8 +19,6 @@ use Exception;
 require_once 'include/datetime.php';
 require_once 'include/network.php';
 require_once 'include/html2bbcode.php';
-require_once 'include/Contact.php';
-require_once 'include/Photo.php';
 
 /**
  * @brief This class handles GlobalContact related functions
@@ -94,6 +94,7 @@ class GlobalContact
         * @param integer $uid  User ID
         * @param integer $cid  Contact ID
         * @param integer $zcid Global Contact ID
+        * @return void
         */
        public static function link($gcid, $uid = 0, $cid = 0, $zcid = 0)
        {
@@ -142,6 +143,7 @@ class GlobalContact
         *  2: Contacts of profiles on this server
         *  3: Contacts of contacts of profiles on this server
         *  4: ...
+        * @return array $gcontact
         */
        public static function sanitize($gcontact)
        {
@@ -169,7 +171,7 @@ class GlobalContact
                        $gcontact['url'] = self::cleanContactUrl($gcontact['url']);
                }
 
-               $alternate = poco_alternate_ostatus_url($gcontact['url']);
+               $alternate = PortableContact::alternateOStatusUrl($gcontact['url']);
 
                // The global contacts should contain the original picture, not the cached one
                if (($gcontact['generation'] != 1) && stristr(normalise_link($gcontact['photo']), normalise_link(System::baseUrl()."/photo/"))) {
@@ -223,7 +225,7 @@ class GlobalContact
                }
 
                if ((!isset($gcontact['network']) || !isset($gcontact['name']) || !isset($gcontact['addr']) || !isset($gcontact['photo']) || !isset($gcontact['server_url']) || $alternate)
-                       && poco_reachable($gcontact['url'], $gcontact['server_url'], $gcontact['network'], false)
+                       && PortableContact::reachable($gcontact['url'], $gcontact['server_url'], $gcontact['network'], false)
                ) {
                        $data = Probe::uri($gcontact['url']);
 
@@ -257,7 +259,7 @@ class GlobalContact
 
                if (!isset($gcontact['server_url'])) {
                        // We check the server url to be sure that it is a real one
-                       $server_url = poco_detect_server($gcontact['url']);
+                       $server_url = PortableContact::detectServer($gcontact['url']);
 
                        // We are now sure that it is a correct URL. So we use it in the future
                        if ($server_url != "") {
@@ -266,13 +268,18 @@ class GlobalContact
                }
 
                // The server URL doesn't seem to be valid, so we don't store it.
-               if (!poco_check_server($gcontact['server_url'], $gcontact['network'])) {
+               if (!PortableContact::checkServer($gcontact['server_url'], $gcontact['network'])) {
                        $gcontact['server_url'] = "";
                }
 
                return $gcontact;
        }
 
+       /**
+        * @param integer $uid id
+        * @param integer $cid id
+        * @return integer
+        */
        public static function countCommonFriends($uid, $cid)
        {
                $r = q(
@@ -295,6 +302,11 @@ class GlobalContact
                return 0;
        }
 
+       /**
+        * @param integer $uid  id
+        * @param integer $zcid zcid
+        * @return integer
+        */
        public static function countCommonFriendsZcid($uid, $zcid)
        {
                $r = q(
@@ -313,6 +325,14 @@ class GlobalContact
                return 0;
        }
 
+       /**
+        * @param object  $uid     user
+        * @param object  $cid     cid
+        * @param integer $start   optional, default 0
+        * @param integer $limit   optional, default 9999
+        * @param boolean $shuffle optional, default false
+        * @return object
+        */
        public static function commonFriends($uid, $cid, $start = 0, $limit = 9999, $shuffle = false)
        {
                if ($shuffle) {
@@ -343,7 +363,15 @@ class GlobalContact
                return $r;
        }
 
-       function commonFriendsZcid($uid, $zcid, $start = 0, $limit = 9999, $shuffle = false)
+       /**
+        * @param object  $uid     user
+        * @param object  $zcid    zcid
+        * @param integer $start   optional, default 0
+        * @param integer $limit   optional, default 9999
+        * @param boolean $shuffle optional, default false
+        * @return object
+        */
+       public static function commonFriendsZcid($uid, $zcid, $start = 0, $limit = 9999, $shuffle = false)
        {
                if ($shuffle) {
                        $sql_extra = " order by rand() ";
@@ -367,6 +395,11 @@ class GlobalContact
                return $r;
        }
 
+       /**
+        * @param object $uid user
+        * @param object $cid cid
+        * @return integer
+        */
        public static function countAllFriends($uid, $cid)
        {
                $r = q(
@@ -381,11 +414,17 @@ class GlobalContact
                if (DBM::is_result($r)) {
                        return $r[0]['total'];
                }
-               
+
                return 0;
        }
 
-
+       /**
+        * @param object  $uid   user
+        * @param object  $cid   cid
+        * @param integer $start optional, default 0
+        * @param integer $limit optional, default 80
+        * @return object
+        */
        public static function allFriends($uid, $cid, $start = 0, $limit = 80)
        {
                $r = q(
@@ -407,6 +446,12 @@ class GlobalContact
                return $r;
        }
 
+       /**
+        * @param object  $uid   user
+        * @param integer $start optional, default 0
+        * @param integer $limit optional, default 80
+        * @return array
+        */
        public static function suggestionQuery($uid, $start = 0, $limit = 80)
        {
                if (!$uid) {
@@ -507,6 +552,9 @@ class GlobalContact
                return $list;
        }
 
+       /**
+        * @return void
+        */
        public static function updateSuggestions()
        {
                $a = get_app();
@@ -524,7 +572,7 @@ class GlobalContact
                                $j = json_decode($x);
                                if ($j->entries) {
                                        foreach ($j->entries as $entry) {
-                                               poco_check_server($entry->url);
+                                               PortableContact::checkServer($entry->url);
 
                                                $url = $entry->url . '/poco';
                                                if (! in_array($url, $done)) {
@@ -588,10 +636,11 @@ class GlobalContact
         * @brief Replace alternate OStatus user format with the primary one
         *
         * @param arr $contact contact array (called by reference)
+        * @return void
         */
        public static function fixAlternateContactAddress(&$contact)
        {
-               if (($contact["network"] == NETWORK_OSTATUS) && poco_alternate_ostatus_url($contact["url"])) {
+               if (($contact["network"] == NETWORK_OSTATUS) && PortableContact::alternateOStatusUrl($contact["url"])) {
                        $data = Probe::uri($contact["url"]);
                        if ($contact["network"] == NETWORK_OSTATUS) {
                                logger("Fix primary url from ".$contact["url"]." to ".$data["url"]." - Called by: ".System::callstack(), LOGGER_DEBUG);
@@ -688,7 +737,7 @@ class GlobalContact
 
                if ($doprobing) {
                        logger("Last Contact: ". $last_contact_str." - Last Failure: ".$last_failure_str." - Checking: ".$contact["url"], LOGGER_DEBUG);
-                       Worker::add(PRIORITY_LOW, 'gprobe', $contact["url"]);
+                       Worker::add(PRIORITY_LOW, 'GProbe', $contact["url"]);
                }
 
                return $gcontact_id;
@@ -832,7 +881,7 @@ class GlobalContact
                        if (DBM::is_result($r)) {
                                logger("Update public contact ".$r[0]["id"], LOGGER_DEBUG);
 
-                               update_contact_avatar($contact["photo"], 0, $r[0]["id"]);
+                               Contact::updateAvatar($contact["photo"], 0, $r[0]["id"]);
 
                                $fields = array('name', 'nick', 'addr',
                                                'network', 'bd', 'gender',
@@ -859,6 +908,7 @@ class GlobalContact
         * @brief Updates the gcontact entry from probe
         *
         * @param str $url profile link
+        * @return void
         */
        public static function updateFromProbe($url)
        {
@@ -878,6 +928,7 @@ class GlobalContact
         * @brief Update the gcontact entry for a given user id
         *
         * @param int $uid User ID
+        * @return void
         */
        public static function updateForUser($uid)
        {
@@ -894,7 +945,7 @@ class GlobalContact
                        intval($uid)
                );
 
-               $location = formatted_location(
+               $location = Profile::formatLocation(
                        array("locality" => $r[0]["locality"], "region" => $r[0]["region"], "country-name" => $r[0]["country-name"])
                );
 
@@ -923,8 +974,9 @@ class GlobalContact
         * If the "Statistics" plugin is enabled (See http://gstools.org/ for details) we query user data with this.
         *
         * @param str $server Server address
+        * @return void
         */
-       public static function gsFetchUsers($server)
+       public static function fetchGsUsers($server)
        {
                logger("Fetching users from GNU Social server ".$server, LOGGER_DEBUG);
 
@@ -978,9 +1030,9 @@ class GlobalContact
 
        /**
         * @brief Asking GNU Social server on a regular base for their user data
-        *
+        * @return void
         */
-       public static function gsDiscover()
+       public static function discoverGsUsers()
        {
                $requery_days = intval(Config::get("system", "poco_requery_days"));
 
@@ -997,8 +1049,28 @@ class GlobalContact
                }
 
                foreach ($r as $server) {
-                       self::gsFetchUsers($server["url"]);
+                       self::fetchGsUsers($server["url"]);
                        q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"]));
                }
        }
+
+       /**
+        * @return string
+        */
+       public static function getRandomUrl()
+       {
+               $r = q(
+                       "SELECT `url` FROM `gcontact` WHERE `network` = '%s'
+                                       AND `last_contact` >= `last_failure`
+                                       AND `updated` > UTC_TIMESTAMP - INTERVAL 1 MONTH
+                               ORDER BY rand() LIMIT 1",
+                       dbesc(NETWORK_DFRN)
+               );
+
+               if (DBM::is_result($r)) {
+                       return dirname($r[0]['url']);
+               }
+
+               return '';
+       }
 }