]> git.mxchange.org Git - friendica.git/blob - src/Object/Api/Twitter/User.php
Added profile picture
[friendica.git] / src / Object / Api / Twitter / User.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Object\Api\Twitter;
23
24 use Friendica\BaseDataTransferObject;
25 use Friendica\Content\ContactSelector;
26 use Friendica\Content\Text\BBCode;
27 use Friendica\Core\Protocol;
28 use Friendica\Model\Contact;
29 use Friendica\Util\Proxy;
30
31 /**
32  * @see https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/user-object
33  */
34 class User extends BaseDataTransferObject
35 {
36         /** @var int */
37         protected $id;
38         /** @var string */
39         protected $id_str;
40         /** @var string */
41         protected $name;
42         /** @var string */
43         protected $screen_name;
44         /** @var string|null */
45         protected $location;
46         /** @var array */
47         protected $derived;
48         /** @var string|null */
49         protected $url;
50         /** @var array */
51         protected $entities;
52         /** @var string|null */
53         protected $description;
54         /** @var bool */
55         protected $protected;
56         /** @var bool */
57         protected $verified;
58         /** @var int */
59         protected $followers_count;
60         /** @var int */
61         protected $friends_count;
62         /** @var int */
63         protected $listed_count;
64         /** @var int */
65         protected $favourites_count;
66         /** @var int */
67         protected $statuses_count;
68         /** @var string */
69         protected $created_at;
70         /** @var string */
71         protected $profile_banner_url;
72         /** @var string */
73         protected $profile_image_url_https;
74         /** @var bool */
75         protected $default_profile;
76         /** @var bool */
77         protected $default_profile_image;
78         /** @var Status */
79         protected $status;
80         /** @var array */
81         protected $withheld_in_countries;
82         /** @var string */
83         protected $withheld_scope;
84
85         /**
86          * Missing fields:
87          *
88          * - profile_sidebar_fill_color
89          * - profile_link_color
90          * - profile_background_color
91          */
92
93         /**
94          * @param array $publicContact         Full contact table record with uid = 0
95          * @param array $apcontact             Optional full apcontact table record
96          * @param array $userContact           Optional full contact table record with uid != 0
97          * @param bool  $skip_status           Whether to remove the last status property, currently unused
98          * @param bool  $include_user_entities Whether to add the entities property
99          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
100          */
101         public function __construct(array $publicContact, array $apcontact = [], array $userContact = [], $skip_status = false, $include_user_entities = true)
102         {
103                 $uid = $userContact['uid'] ?? 0;
104
105                 $this->id                      = (int)$publicContact['id'];
106                 $this->id_str                  = (string) $publicContact['id'];
107                 $this->name                    = $publicContact['name'] ?: $publicContact['nick'];
108                 $this->screen_name             = $publicContact['nick'] ?: $publicContact['name'];
109                 $this->location                = $publicContact['location'] ?:
110                         ContactSelector::networkToName($publicContact['network'], $publicContact['url'], $publicContact['protocol']);
111                 $this->derived                 = [];
112                 $this->url                     = $publicContact['url'];
113                 // No entities needed since we don't perform any shortening in the URL or description
114                 $this->entities            = [
115                         'url' => ['urls' => []],
116                         'description' => ['urls' => []],
117                 ];
118                 if (!$include_user_entities) {
119                         unset($this->entities);
120                 }
121                 $this->description             = BBCode::toPlaintext($publicContact['about']);
122                 $this->profile_image_url_https = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_MICRO);
123                 $this->protected               = false;
124                 $this->followers_count         = $apcontact['followers_count'] ?? 0;
125                 $this->friends_count           = $apcontact['following_count'] ?? 0;
126                 $this->listed_count            = 0;
127                 $this->created_at              = api_date($publicContact['created']);
128                 $this->favourites_count        = 0;
129                 $this->verified                = $uid != 0;
130                 $this->statuses_count          = $apcontact['statuses_count'] ?? 0;
131                 $this->profile_banner_url      = Contact::getHeaderUrlForId($publicContact['id'], '', $publicContact['updated']);
132                 $this->default_profile         = false;
133                 $this->default_profile_image   = false;
134
135                 // @TODO Replace skip_status parameter with an optional Status parameter
136                 unset($this->status);
137
138                 //  Unused optional fields
139                 unset($this->withheld_in_countries);
140                 unset($this->withheld_scope);
141
142                 // Deprecated
143                 $this->profile_image_url              = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_MICRO);
144                 $this->profile_image_url_profile_size = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_THUMB);
145                 $this->profile_image_url_large        = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_LARGE);
146                 $this->utc_offset                     = 0;
147                 $this->time_zone                      = 'UTC';
148                 $this->geo_enabled                    = false;
149                 $this->lang                           = null;
150                 $this->contributors_enabled           = false;
151                 $this->is_translator                  = false;
152                 $this->is_translation_enabled         = false;
153                 $this->following                      = in_array($userContact['rel'] ?? Contact::NOTHING, [Contact::FOLLOWER, Contact::FRIEND]);
154                 $this->follow_request_sent            = false;
155                 $this->statusnet_blocking             = false;
156                 $this->notifications                  = false;
157
158                 // Friendica-specific
159                 $this->uid                   = (int)$uid;
160                 $this->cid                   = (int)($userContact['id'] ?? 0);
161                 $this->pid                   = (int)$publicContact['id'];
162                 $this->self                  = (boolean)($userContact['self'] ?? false);
163                 $this->network               = $publicContact['network'] ?: Protocol::DFRN;
164                 $this->statusnet_profile_url = $publicContact['url'];
165         }
166 }