3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Module\Api\Friendica\Profile;
24 use Friendica\Profile\ProfileField\Collection\ProfileFields;
25 use Friendica\Content\Text\BBCode;
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;
34 * API endpoint: /api/friendica/profile/show
36 class Show extends BaseApi
38 public static function rawContent(array $parameters = [])
40 self::checkAllowedScope(self::SCOPE_READ);
41 $uid = self::getCurrentUserID();
43 // retrieve general information about profiles for user
44 $directory = DI::config()->get('system', 'directory');
46 $profile = Profile::getByUID($uid);
48 $profileFields = DI::profileField()->selectPublicFieldsByUserId($uid);
50 $profile = self::formatProfile($profile, $profileFields);
53 if (self::$format == 'xml') {
54 $profiles['0:profile'] = $profile;
56 $profiles[] = $profile;
59 // return settings, authenticated user and profiles data
60 $self = Contact::selectFirst(['nurl'], ['uid' => $uid, 'self' => true]);
63 'multi_profiles' => false,
64 'global_dir' => $directory,
65 'friendica_owner' => self::getUser($self['nurl']),
66 'profiles' => $profiles
69 echo self::format('friendica_profiles', ['$result' => $result]);
74 * @param array $profile_row array containing data from db table 'profile'
75 * @param ProfileFields $profileFields
77 * @throws HTTPException\InternalServerErrorException
79 private static function formatProfile($profile_row, ProfileFields $profileFields)
82 foreach ($profileFields as $profileField) {
84 'label' => $profileField->label,
85 'value' => BBCode::convert($profileField->value, false, BBCode::API),
90 'profile_id' => $profile_row['id'],
91 'profile_name' => 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'],
108 'marital_with' => null,
109 'marital_since' => null,
113 'public_keywords' => $profile_row['pub_keywords'],
114 'private_keywords' => $profile_row['prv_keywords'],
126 'social_networks' => null,
127 'homepage' => $profile_row['homepage'],
129 'custom_fields' => $custom_fields,