]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #7000 from MrPetovan/task/6999-no-probe-magic-link
authorPhilipp <admin+Github@philipp.info>
Fri, 3 May 2019 06:43:26 +0000 (08:43 +0200)
committerGitHub <noreply@github.com>
Fri, 3 May 2019 06:43:26 +0000 (08:43 +0200)
Remove probing in magic link construction

1  2 
src/Model/Contact.php

diff --combined src/Model/Contact.php
index 6e7860c8aae96d58541d59cbfc40e763cb9866cb,24c2bf878c82e326fb288a17dba393cb2a6de4cd..f4c62fea809d554e220e180b292a9e1004f9268f
@@@ -110,20 -110,6 +110,20 @@@ class Contact extends BaseObjec
         * @}
         */
  
 +      /**
 +       * @param array $fields    Array of selected fields, empty for all
 +       * @param array $condition Array of fields for condition
 +       * @param array $params    Array of several parameters
 +       * @return array
 +       * @throws \Exception
 +       */
 +      public static function select(array $fields = [], array $condition = [], array $params = [])
 +      {
 +              $statement = DBA::select('contact', $fields, $condition, $params);
 +
 +              return DBA::toArray($statement);
 +      }
 +
        /**
         * @param  integer       $id
         * @return array|boolean Contact record if it exists, false otherwise
                return ['public' => $pcid, 'user' => $ucid];
        }
  
 +      /**
 +       * Returns contact details for a given contact id in combination with a user id
 +       *
 +       * @param int $cid A contact ID
 +       * @param int $uid The User ID
 +       * @param array $fields The selected fields for the contact
 +       *
 +       * @return array The contact details
 +       *
 +       * @throws \Exception
 +       */
 +      public static function getContactForUser($cid, $uid, array $fields = [])
 +      {
 +              $contact = DBA::selectFirst('contact', $fields, ['id' => $cid, 'uid' => $uid]);
 +
 +              if (!DBA::isResult($contact)) {
 +                      return [];
 +              } else {
 +                      return $contact;
 +              }
 +      }
 +
        /**
         * @brief Block contact id for user id
         *
         *
         * @return array Contact array in the "probe" structure
        */
-       private static function getProbeDataFromDatabase($url, $cid)
+       private static function getProbeDataFromDatabase($url, $cid = null)
        {
                // The link could be provided as http although we stored it as https
                $ssl_url = str_replace('http://', 'https://', $url);
                        return $url ?: $contact_url; // Equivalent to: ($url != '') ? $url : $contact_url;
                }
  
-               $cid = self::getIdForURL($contact_url, 0, true);
-               if (empty($cid)) {
+               $data = self::getProbeDataFromDatabase($contact_url);
+               if (empty($data)) {
                        return $url ?: $contact_url; // Equivalent to: ($url != '') ? $url : $contact_url;
                }
  
-               return self::magicLinkbyId($cid, $url);
+               return self::magicLinkByContact($data, $contact_url);
        }
  
        /**