]> git.mxchange.org Git - friendica.git/blobdiff - src/Object/Api/Twitter/User.php
Merge pull request #13676 from MrPetovan/bug/13673-markers-json-output
[friendica.git] / src / Object / Api / Twitter / User.php
index 7793fbc26fa1c79b1bd1141863e70f44bab56cca..3ad5c5461ec466ad97515677bd83ad5be44a9c2f 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -24,6 +24,10 @@ namespace Friendica\Object\Api\Twitter;
 use Friendica\BaseDataTransferObject;
 use Friendica\Content\ContactSelector;
 use Friendica\Content\Text\BBCode;
+use Friendica\Model\Contact;
+use Friendica\Network\HTTPException\InternalServerErrorException;
+use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Proxy;
 
 /**
  * @see https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/user-object
@@ -78,20 +82,67 @@ class User extends BaseDataTransferObject
        protected $withheld_in_countries;
        /** @var string */
        protected $withheld_scope;
+       /** @var string */
+       protected $profile_image_url;
+       /** @var bool */
+       protected $follow_request_sent;
+       /** @var string */
+       protected $profile_image_url_large;
+       /** @var string */
+       protected $profile_image_url_profile_size;
+       /** @var int */
+       protected $utc_offset;
+       /** @var string */
+       protected $time_zone;
+       /** @var bool */
+       protected $geo_enabled;
+       /** @var null */
+       protected $lang;
+       /** @var bool */
+       protected $contributors_enabled;
+       /** @var bool */
+       protected $is_translator;
+       /** @var bool */
+       protected $is_translation_enabled;
+       /** @var bool */
+       protected $following;
+       /** @var bool */
+       protected $statusnet_blocking;
+       /** @var bool */
+       protected $notifications;
+       /** @var int */
+       protected $uid;
+       /** @var int */
+       protected $pid;
+       /** @var int */
+       protected $cid;
+       /** @var mixed */
+       protected $statusnet_profile_url;
+
+       /**
+        * Missing fields:
+        *
+        * - profile_sidebar_fill_color
+        * - profile_link_color
+        * - profile_background_color
+        */
 
        /**
         * @param array $publicContact         Full contact table record with uid = 0
         * @param array $apcontact             Optional full apcontact table record
         * @param array $userContact           Optional full contact table record with uid != 0
-        * @param bool  $skip_status           Whether to remove the last status property, currently unused
+        * @param null  $status
         * @param bool  $include_user_entities Whether to add the entities property
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        *
+        * @throws InternalServerErrorException
         */
-       public function __construct(array $publicContact, array $apcontact = [], array $userContact = [], $skip_status = false, $include_user_entities = true)
+       public function __construct(array $publicContact, array $apcontact = [], array $userContact = [], $status = null, bool $include_user_entities = true)
        {
+               $uid = $userContact['uid'] ?? 0;
+
                $this->id                      = (int)$publicContact['id'];
                $this->id_str                  = (string) $publicContact['id'];
-               $this->name                    = $publicContact['name'];
+               $this->name                    = $publicContact['name'] ?: $publicContact['nick'];
                $this->screen_name             = $publicContact['nick'] ?: $publicContact['name'];
                $this->location                = $publicContact['location'] ?:
                        ContactSelector::networkToName($publicContact['network'], $publicContact['url'], $publicContact['protocol']);
@@ -105,31 +156,34 @@ class User extends BaseDataTransferObject
                if (!$include_user_entities) {
                        unset($this->entities);
                }
-               $this->description             = BBCode::toPlaintext($publicContact['about']);
-               $this->profile_image_url_https = $userContact['avatar'] ?? $publicContact['avatar'];
+               $this->description             = (!empty($publicContact['about']) ? BBCode::toPlaintext($publicContact['about']) : '');
+               $this->profile_image_url_https = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_MICRO);
                $this->protected               = false;
                $this->followers_count         = $apcontact['followers_count'] ?? 0;
                $this->friends_count           = $apcontact['following_count'] ?? 0;
                $this->listed_count            = 0;
-               $this->created_at              = api_date($publicContact['created']);
+               $this->created_at              = DateTimeFormat::utc($publicContact['created'], DateTimeFormat::API);
                $this->favourites_count        = 0;
-               $this->verified                = false;
+               $this->verified                = $uid != 0;
                $this->statuses_count          = $apcontact['statuses_count'] ?? 0;
-               $this->profile_banner_url      = '';
+               $this->profile_banner_url      = Contact::getHeaderUrlForId($publicContact['id'], '', $publicContact['updated']);
                $this->default_profile         = false;
                $this->default_profile_image   = false;
 
-               // @TODO Replace skip_status parameter with an optional Status parameter
-               unset($this->status);
+               if (!empty($status)) {
+                       $this->status = $status;
+               } else {
+                       unset($this->status);
+               }
 
                //  Unused optional fields
                unset($this->withheld_in_countries);
                unset($this->withheld_scope);
 
                // Deprecated
-               $this->profile_image_url              = $userContact['avatar'] ?? $publicContact['avatar'];
-               $this->profile_image_url_profile_size = $publicContact['thumb'];
-               $this->profile_image_url_large        = $publicContact['photo'];
+               $this->profile_image_url              = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_MICRO);
+               $this->profile_image_url_profile_size = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_THUMB);
+               $this->profile_image_url_large        = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_LARGE);
                $this->utc_offset                     = 0;
                $this->time_zone                      = 'UTC';
                $this->geo_enabled                    = false;
@@ -137,17 +191,15 @@ class User extends BaseDataTransferObject
                $this->contributors_enabled           = false;
                $this->is_translator                  = false;
                $this->is_translation_enabled         = false;
-               $this->following                      = false;
+               $this->following                      = in_array($userContact['rel'] ?? Contact::NOTHING, [Contact::FOLLOWER, Contact::FRIEND]);
                $this->follow_request_sent            = false;
                $this->statusnet_blocking             = false;
                $this->notifications                  = false;
 
                // Friendica-specific
-               $this->uid                   = (int)$userContact['uid'] ?? 0;
-               $this->cid                   = (int)$userContact['id'] ?? 0;
+               $this->uid                   = (int)$uid;
+               $this->cid                   = (int)($userContact['id'] ?? 0);
                $this->pid                   = (int)$publicContact['id'];
-               $this->self                  = (boolean)$userContact['self'] ?? false;
-               $this->network               = $publicContact['network'];
                $this->statusnet_profile_url = $publicContact['url'];
        }
 }