]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Contact.php
Merge pull request #6065 from annando/fix-forum
[friendica.git] / src / Model / Contact.php
index f1260c7c44f090087b84d1080af7014f499d7f1b..5d571e30e1e8d7271e2a2587767cedd8923d5f58 100644 (file)
@@ -5,10 +5,11 @@
 namespace Friendica\Model;
 
 use Friendica\BaseObject;
+use Friendica\Content\Pager;
 use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
-use Friendica\Core\PConfig;
+use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
@@ -17,8 +18,8 @@ use Friendica\Model\Profile;
 use Friendica\Network\Probe;
 use Friendica\Object\Image;
 use Friendica\Protocol\ActivityPub;
-use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\DFRN;
+use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\OStatus;
 use Friendica\Protocol\PortableContact;
 use Friendica\Protocol\Salmon;
@@ -466,7 +467,7 @@ class Contact extends BaseObject
                        $fields['micro'] = $prefix . '6' . $suffix;
                } else {
                        // We hadn't found a photo entry, so we use the default avatar
-                       $fields['photo'] = System::baseUrl() . '/images/person-175.jpg';
+                       $fields['photo'] = System::baseUrl() . '/images/person-300.jpg';
                        $fields['thumb'] = System::baseUrl() . '/images/person-80.jpg';
                        $fields['micro'] = System::baseUrl() . '/images/person-48.jpg';
                }
@@ -586,7 +587,7 @@ class Contact extends BaseObject
                                return;
                        }
                } elseif (!isset($contact['url'])) {
-                       logger('Empty contact: ' . json_encode($contact) . ' - ' . System::callstack(20), LOGGER_DEBUG);
+                       Logger::log('Empty contact: ' . json_encode($contact) . ' - ' . System::callstack(20), Logger::DEBUG);
                }
 
                // Contact already archived or "self" contact? => nothing to do
@@ -594,9 +595,9 @@ class Contact extends BaseObject
                        return;
                }
 
-               if ($contact['term-date'] <= NULL_DATE) {
+               if ($contact['term-date'] <= DBA::NULL_DATETIME) {
                        DBA::update('contact', ['term-date' => DateTimeFormat::utcNow()], ['id' => $contact['id']]);
-                       DBA::update('contact', ['term-date' => DateTimeFormat::utcNow()], ['`nurl` = ? AND `term-date` <= ? AND NOT `self`', normalise_link($contact['url']), NULL_DATE]);
+                       DBA::update('contact', ['term-date' => DateTimeFormat::utcNow()], ['`nurl` = ? AND `term-date` <= ? AND NOT `self`', normalise_link($contact['url']), DBA::NULL_DATETIME]);
                } else {
                        /* @todo
                         * We really should send a notification to the owner after 2-3 weeks
@@ -629,7 +630,7 @@ class Contact extends BaseObject
         */
        public static function unmarkForArchival(array $contact)
        {
-               $condition = ['`id` = ? AND (`term-date` > ? OR `archive`)', $contact['id'], NULL_DATE];
+               $condition = ['`id` = ? AND (`term-date` > ? OR `archive`)', $contact['id'], DBA::NULL_DATETIME];
                $exists = DBA::exists('contact', $condition);
 
                // We don't need to update, we never marked this contact for archival
@@ -646,7 +647,7 @@ class Contact extends BaseObject
                }
 
                // It's a miracle. Our dead contact has inexplicably come back to life.
-               $fields = ['term-date' => NULL_DATE, 'archive' => false];
+               $fields = ['term-date' => DBA::NULL_DATETIME, 'archive' => false];
                DBA::update('contact', $fields, ['id' => $contact['id']]);
                DBA::update('contact', $fields, ['nurl' => normalise_link($contact['url'])]);
 
@@ -923,12 +924,12 @@ class Contact extends BaseObject
                        $poke_link = System::baseUrl() . '/poke/?f=&c=' . $contact['id'];
                }
 
-               $contact_url = System::baseUrl() . '/contacts/' . $contact['id'];
+               $contact_url = System::baseUrl() . '/contact/' . $contact['id'];
 
-               $posts_link = System::baseUrl() . '/contacts/' . $contact['id'] . '/conversations';
+               $posts_link = System::baseUrl() . '/contact/' . $contact['id'] . '/conversations';
 
                if (!$contact['self']) {
-                       $contact_drop_link = System::baseUrl() . '/contacts/' . $contact['id'] . '/drop?confirm=1';
+                       $contact_drop_link = System::baseUrl() . '/contact/' . $contact['id'] . '/drop?confirm=1';
                }
 
                /**
@@ -1021,12 +1022,13 @@ class Contact extends BaseObject
         * @param integer $uid       The user id for the contact (0 = public contact)
         * @param boolean $no_update Don't update the contact
         * @param array   $default   Default value for creating the contact when every else fails
+        * @param boolean $in_loop   Internally used variable to prevent an endless loop
         *
         * @return integer Contact ID
         */
-       public static function getIdForURL($url, $uid = 0, $no_update = false, $default = [])
+       public static function getIdForURL($url, $uid = 0, $no_update = false, $default = [], $in_loop = false)
        {
-               logger("Get contact data for url " . $url . " and user " . $uid . " - " . System::callstack(), LOGGER_DEBUG);
+               Logger::log("Get contact data for url " . $url . " and user " . $uid . " - " . System::callstack(), Logger::DEBUG);
 
                $contact_id = 0;
 
@@ -1138,8 +1140,8 @@ class Contact extends BaseObject
                        }
                }
 
-               if (!$contact_id && ($data["alias"] != '') && ($data["alias"] != $url)) {
-                       $contact_id = self::getIdForURL($data["alias"], $uid, true);
+               if (!$contact_id && ($data["alias"] != '') && ($data["alias"] != $url) && !$in_loop) {
+                       $contact_id = self::getIdForURL($data["alias"], $uid, true, $default, true);
                }
 
                $url = $data["url"];
@@ -1345,25 +1347,27 @@ class Contact extends BaseObject
                                $cid, GRAVITY_PARENT, GRAVITY_COMMENT, local_user()];
                }
 
+               $pager = new Pager($a->query_string);
+
                $params = ['order' => ['created' => true],
-                       'limit' => [$a->pager['start'], $a->pager['itemspage']]];
+                       'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
 
                if ($thread_mode) {
                        $r = Item::selectThreadForUser(local_user(), ['uri'], $condition, $params);
 
                        $items = Item::inArray($r);
 
-                       $o = conversation($a, $items, 'contacts', $update);
+                       $o = conversation($a, $items, $pager, 'contacts', $update);
                } else {
                        $r = Item::selectForUser(local_user(), [], $condition, $params);
 
                        $items = Item::inArray($r);
 
-                       $o = conversation($a, $items, 'contact-posts', false);
+                       $o = conversation($a, $items, $pager, 'contact-posts', false);
                }
 
                if (!$update) {
-                       $o .= alt_pager($a, count($items));
+                       $o .= $pager->renderMinimal(count($items));
                }
 
                return $o;
@@ -1615,7 +1619,7 @@ class Contact extends BaseObject
                }
 
                if (($network != '') && ($ret['network'] != $network)) {
-                       logger('Expected network ' . $network . ' does not match actual network ' . $ret['network']);
+                       Logger::log('Expected network ' . $network . ' does not match actual network ' . $ret['network']);
                        return $result;
                }
 
@@ -1638,7 +1642,7 @@ class Contact extends BaseObject
                                        $myaddr = bin2hex($a->user['nickname'] . '@' . $a->getHostName());
                                }
 
-                               goaway($ret['request'] . "&addr=$myaddr");
+                               $a->internalRedirect($ret['request'] . "&addr=$myaddr");
 
                                // NOTREACHED
                        }
@@ -1767,10 +1771,10 @@ class Contact extends BaseObject
                                }
                        } elseif ($contact['network'] == Protocol::DIASPORA) {
                                $ret = Diaspora::sendShare($a->user, $contact);
-                               logger('share returns: ' . $ret);
+                               Logger::log('share returns: ' . $ret);
                        } elseif ($contact['network'] == Protocol::ACTIVITYPUB) {
                                $ret = ActivityPub\Transmitter::sendActivity('Follow', $contact['url'], $uid);
-                               logger('Follow returns: ' . $ret);
+                               Logger::log('Follow returns: ' . $ret);
                        }
                }
 
@@ -1852,7 +1856,7 @@ class Contact extends BaseObject
                        // send email notification to owner?
                } else {
                        if (DBA::exists('contact', ['nurl' => normalise_link($url), 'uid' => $importer['uid'], 'pending' => true])) {
-                               logger('ignoring duplicated connection request from pending contact ' . $url);
+                               Logger::log('ignoring duplicated connection request from pending contact ' . $url);
                                return;
                        }
                        // create contact record
@@ -1958,7 +1962,7 @@ class Contact extends BaseObject
                $r = q("SELECT * FROM `contact` WHERE `bd` != '' AND `bd` > '0001-01-01' AND SUBSTRING(`bd`, 1, 4) != `bdyear` ");
                if (DBA::isResult($r)) {
                        foreach ($r as $rr) {
-                               logger('update_contact_birthday: ' . $rr['bd']);
+                               Logger::log('update_contact_birthday: ' . $rr['bd']);
 
                                $nextbd = DateTimeFormat::utcNow('Y') . substr($rr['bd'], 4);
 
@@ -2023,8 +2027,10 @@ class Contact extends BaseObject
        /**
         * @brief Returns a magic link to authenticate remote visitors
         *
+        * @todo check if the return is either a fully qualified URL or a relative path to Friendica basedir
+        *
         * @param string $contact_url The address of the target contact profile
-        * @param integer $url An url that we will be redirected to after the authentication
+        * @param string $url An url that we will be redirected to after the authentication
         *
         * @return string with "redir" link
         */
@@ -2057,7 +2063,7 @@ class Contact extends BaseObject
         * @brief Returns a magic link to authenticate remote visitors
         *
         * @param array $contact The contact array with "uid", "network" and "url"
-        * @param integer $url An url that we will be redirected to after the authentication
+        * @param string $url An url that we will be redirected to after the authentication
         *
         * @return string with "redir" link
         */