]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/BaseApi.php
Move sending follow message to remote server to Protocol class
[friendica.git] / src / Module / BaseApi.php
index 87a69081420d5639f1ee2f3a9e361de3fd678858..9732fdfcd3d2aa9353dcf2952cea70ba0eac92fb 100644 (file)
@@ -25,16 +25,14 @@ use Friendica\BaseModule;
 use Friendica\Core\Logger;
 use Friendica\Core\System;
 use Friendica\DI;
+use Friendica\Model\Contact;
 use Friendica\Model\Post;
+use Friendica\Model\User;
 use Friendica\Network\HTTPException;
 use Friendica\Security\BasicAuth;
 use Friendica\Security\OAuth;
-use Friendica\Util\Arrays;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\HTTPInputData;
-use Friendica\Util\XML;
-
-require_once __DIR__ . '/../../include/api.php';
 
 class BaseApi extends BaseModule
 {
@@ -295,18 +293,25 @@ class BaseApi extends BaseModule
                }
        }
 
-       /**
-        * Get user info array.
-        *
-        * @param int|string $contact_id Contact ID or URL
-        * @return array|bool
-        * @throws HTTPException\BadRequestException
-        * @throws HTTPException\InternalServerErrorException
-        * @throws HTTPException\UnauthorizedException
-        * @throws \ImagickException
-        */
-       protected static function getUser($contact_id = null)
+       public static function getContactIDForSearchterm(string $screen_name = null, int $cid = null, int $uid)
        {
-               return api_get_user($contact_id);
+               if (!empty($cid)) {
+                       return $cid;
+               }
+
+               if (strpos($screen_name, '@') !== false) {
+                       $cid = Contact::getIdForURL($screen_name, 0, false);
+               } else {
+                       $user = User::getByNickname($screen_name, ['uid']);
+                       if (!empty($user['uid'])) {
+                               $cid = Contact::getPublicIdByUserId($user['uid']);
+                       }
+               }
+
+               if (empty($cid) && ($uid != 0)) {
+                       $cid = Contact::getPublicIdByUserId($uid);
+               }
+
+               return $cid;
        }
 }