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\Profile;
28 use Friendica\Module\BaseApi;
29 use Friendica\Network\HTTPException;
32 * API endpoint: /api/friendica/profile/show
34 class Show extends BaseApi
36 public function rawContent()
38 self::checkAllowedScope(self::SCOPE_READ);
39 $uid = self::getCurrentUserID();
41 // retrieve general information about profiles for user
42 $directory = DI::config()->get('system', 'directory');
44 $profile = Profile::getByUID($uid);
46 $profileFields = DI::profileField()->selectPublicFieldsByUserId($uid);
48 $profile = self::formatProfile($profile, $profileFields);
51 if (!empty($this->parameters['extension']) && ($this->parameters['extension'] == 'xml')) {
52 $profiles['0:profile'] = $profile;
54 $profiles[] = $profile;
58 'multi_profiles' => false,
59 'global_dir' => $directory,
60 'friendica_owner' => DI::twitterUser()->createFromUserId($uid),
61 'profiles' => $profiles
64 DI::apiResponse()->exit('friendica_profiles', ['$result' => $result], $this->parameters['extension'] ?? null);
68 * @param array $profile_row array containing data from db table 'profile'
69 * @param ProfileFields $profileFields
71 * @throws HTTPException\InternalServerErrorException
73 private static function formatProfile($profile_row, ProfileFields $profileFields)
76 foreach ($profileFields as $profileField) {
78 'label' => $profileField->label,
79 'value' => BBCode::convert($profileField->value, false, BBCode::API),
84 'profile_id' => $profile_row['id'],
85 'profile_name' => 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'],
102 'marital_with' => null,
103 'marital_since' => null,
107 'public_keywords' => $profile_row['pub_keywords'],
108 'private_keywords' => $profile_row['prv_keywords'],
120 'social_networks' => null,
121 'homepage' => $profile_row['homepage'],
123 'custom_fields' => $custom_fields,