]> git.mxchange.org Git - friendica.git/blob - src/Object/Api/Twitter/User.php
bbe6905ef659cc00b441cb186304f4b7481fda99
[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
28 /**
29  * @see https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/user-object
30  */
31 class User extends BaseDataTransferObject
32 {
33         /** @var int */
34         protected $id;
35         /** @var string */
36         protected $id_str;
37         /** @var string */
38         protected $name;
39         /** @var string */
40         protected $screen_name;
41         /** @var string|null */
42         protected $location;
43         /** @var array */
44         protected $derived;
45         /** @var string|null */
46         protected $url;
47         /** @var array */
48         protected $entities;
49         /** @var string|null */
50         protected $description;
51         /** @var bool */
52         protected $protected;
53         /** @var bool */
54         protected $verified;
55         /** @var int */
56         protected $followers_count;
57         /** @var int */
58         protected $friends_count;
59         /** @var int */
60         protected $listed_count;
61         /** @var int */
62         protected $favourites_count;
63         /** @var int */
64         protected $statuses_count;
65         /** @var string */
66         protected $created_at;
67         /** @var string */
68         protected $profile_banner_url;
69         /** @var string */
70         protected $profile_image_url_https;
71         /** @var bool */
72         protected $default_profile;
73         /** @var bool */
74         protected $default_profile_image;
75         /** @var Status */
76         protected $status;
77         /** @var array */
78         protected $withheld_in_countries;
79         /** @var string */
80         protected $withheld_scope;
81
82         /**
83          * @param array $publicContact         Full contact table record with uid = 0
84          * @param array $apcontact             Optional full apcontact table record
85          * @param array $userContact           Optional full contact table record with uid != 0
86          * @param bool  $skip_status           Whether to remove the last status property, currently unused
87          * @param bool  $include_user_entities Whether to add the entities property
88          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
89          */
90         public function __construct(array $publicContact, array $apcontact = [], array $userContact = [], $skip_status = false, $include_user_entities = true)
91         {
92                 $this->id                      = (int)$publicContact['id'];
93                 $this->id_str                  = (string) $publicContact['id'];
94                 $this->name                    = $publicContact['name'];
95                 $this->screen_name             = $publicContact['nick'] ?: $publicContact['name'];
96                 $this->location                = $publicContact['location'] ?:
97                         ContactSelector::networkToName($publicContact['network'], $publicContact['url'], $publicContact['protocol']);
98                 $this->derived                 = [];
99                 $this->url                     = $publicContact['url'];
100                 // No entities needed since we don't perform any shortening in the URL or description
101                 $this->entities            = [
102                         'url' => ['urls' => []],
103                         'description' => ['urls' => []],
104                 ];
105                 if (!$include_user_entities) {
106                         unset($this->entities);
107                 }
108                 $this->description             = BBCode::toPlaintext($publicContact['about']);
109                 $this->profile_image_url_https = $userContact['avatar'] ?? $publicContact['avatar'];
110                 $this->protected               = false;
111                 $this->followers_count         = $apcontact['followers_count'] ?? 0;
112                 $this->friends_count           = $apcontact['following_count'] ?? 0;
113                 $this->listed_count            = 0;
114                 $this->created_at              = api_date($publicContact['created']);
115                 $this->favourites_count        = 0;
116                 $this->verified                = false;
117                 $this->statuses_count          = $apcontact['statuses_count'] ?? 0;
118                 $this->profile_banner_url      = '';
119                 $this->default_profile         = false;
120                 $this->default_profile_image   = false;
121
122                 // @TODO Replace skip_status parameter with an optional Status parameter
123                 unset($this->status);
124
125                 //  Unused optional fields
126                 unset($this->withheld_in_countries);
127                 unset($this->withheld_scope);
128
129                 // Deprecated
130                 $this->profile_image_url              = $userContact['avatar'] ?? $publicContact['avatar'];
131                 $this->profile_image_url_profile_size = $publicContact['thumb'];
132                 $this->profile_image_url_large        = $publicContact['photo'];
133                 $this->utc_offset                     = 0;
134                 $this->time_zone                      = 'UTC';
135                 $this->geo_enabled                    = false;
136                 $this->lang                           = null;
137                 $this->contributors_enabled           = false;
138                 $this->is_translator                  = false;
139                 $this->is_translation_enabled         = false;
140                 $this->following                      = false;
141                 $this->follow_request_sent            = false;
142                 $this->statusnet_blocking             = false;
143                 $this->notifications                  = false;
144
145                 // Friendica-specific
146                 $this->uid                   = (int)$userContact['uid'] ?? 0;
147                 $this->cid                   = (int)$userContact['id'] ?? 0;
148                 $this->pid                   = (int)$publicContact['id'];
149                 $this->self                  = (boolean)$userContact['self'] ?? false;
150                 $this->network               = $publicContact['network'];
151                 $this->statusnet_profile_url = $publicContact['url'];
152         }
153 }