]> git.mxchange.org Git - friendica.git/blob - src/Module/Api/Friendica/Profile/Show.php
Merge pull request #10999 from nupplaphil/bug/configcache_set
[friendica.git] / src / Module / Api / Friendica / Profile / Show.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\Module\Api\Friendica\Profile;
23
24 use Friendica\Profile\ProfileField\Collection\ProfileFields;
25 use Friendica\Content\Text\BBCode;
26 use Friendica\DI;
27 use Friendica\Model\Profile;
28 use Friendica\Module\BaseApi;
29 use Friendica\Network\HTTPException;
30
31 /**
32  * API endpoint: /api/friendica/profile/show
33  */
34 class Show extends BaseApi
35 {
36         public function rawContent()
37         {
38                 self::checkAllowedScope(self::SCOPE_READ);
39                 $uid = self::getCurrentUserID();
40
41                 // retrieve general information about profiles for user
42                 $directory = DI::config()->get('system', 'directory');
43
44                 $profile = Profile::getByUID($uid);
45                 
46                 $profileFields = DI::profileField()->selectPublicFieldsByUserId($uid);
47
48                 $profile = self::formatProfile($profile, $profileFields);
49
50                 $profiles = [];
51                 if (!empty($this->parameters['extension']) && ($this->parameters['extension'] == 'xml')) {
52                         $profiles['0:profile'] = $profile;
53                 } else {
54                         $profiles[] = $profile;
55                 }
56
57                 $result = [
58                         'multi_profiles' => false,
59                         'global_dir' => $directory,
60                         'friendica_owner' => DI::twitterUser()->createFromUserId($uid),
61                         'profiles' => $profiles
62                 ];
63
64                 DI::apiResponse()->exit('friendica_profiles', ['$result' => $result], $this->parameters['extension'] ?? null);
65         }
66
67         /**
68          * @param array         $profile_row array containing data from db table 'profile'
69          * @param ProfileFields $profileFields
70          * @return array
71          * @throws HTTPException\InternalServerErrorException
72          */
73         private static function formatProfile($profile_row, ProfileFields $profileFields)
74         {
75                 $custom_fields = [];
76                 foreach ($profileFields as $profileField) {
77                         $custom_fields[] = [
78                                 'label' => $profileField->label,
79                                 'value' => BBCode::convert($profileField->value, false, BBCode::API),
80                         ];
81                 }
82
83                 return [
84                         'profile_id'       => $profile_row['id'],
85                         'profile_name'     => null,
86                         'is_default'       => null,
87                         'hide_friends'     => $profile_row['hide-friends'] ? true : false,
88                         'profile_photo'    => $profile_row['photo'],
89                         'profile_thumb'    => $profile_row['thumb'],
90                         'publish'          => $profile_row['publish'] ? true : false,
91                         'net_publish'      => $profile_row['net-publish'] ? true : false,
92                         'description'      => $profile_row['about'],
93                         'date_of_birth'    => $profile_row['dob'],
94                         'address'          => $profile_row['address'],
95                         'city'             => $profile_row['locality'],
96                         'region'           => $profile_row['region'],
97                         'postal_code'      => $profile_row['postal-code'],
98                         'country'          => $profile_row['country-name'],
99                         'hometown'         => null,
100                         'gender'           => null,
101                         'marital'          => null,
102                         'marital_with'     => null,
103                         'marital_since'    => null,
104                         'sexual'           => null,
105                         'politic'          => null,
106                         'religion'         => null,
107                         'public_keywords'  => $profile_row['pub_keywords'],
108                         'private_keywords' => $profile_row['prv_keywords'],
109                         'likes'            => null,
110                         'dislikes'         => null,
111                         'about'            => null,
112                         'music'            => null,
113                         'book'             => null,
114                         'tv'               => null,
115                         'film'             => null,
116                         'interest'         => null,
117                         'romance'          => null,
118                         'work'             => null,
119                         'education'        => null,
120                         'social_networks'  => null,
121                         'homepage'         => $profile_row['homepage'],
122                         'users'            => [],
123                         'custom_fields'    => $custom_fields,
124                 ];
125         }
126 }