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