3 * @copyright Copyright (C) 2010-2022, 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;
26 use Friendica\Core\Search;
28 use Friendica\Model\Profile;
29 use Friendica\Module\BaseApi;
30 use Friendica\Network\HTTPException;
33 * API endpoint: /api/friendica/profile/show
35 class Show extends BaseApi
37 protected function rawContent(array $request = [])
39 self::checkAllowedScope(self::SCOPE_READ);
40 $uid = self::getCurrentUserID();
42 // retrieve general information about profiles for user
43 $directory = Search::getGlobalDirectory();
45 $profile = Profile::getByUID($uid);
47 $profileFields = DI::profileField()->selectPublicFieldsByUserId($uid);
49 $profile = self::formatProfile($profile, $profileFields);
52 if (($this->parameters['extension'] ?? '') == 'xml') {
53 $profiles['0:profile'] = $profile;
55 $profiles[] = $profile;
59 'multi_profiles' => false,
60 'global_dir' => $directory,
61 'friendica_owner' => DI::twitterUser()->createFromUserId($uid),
62 'profiles' => $profiles
65 $this->response->exit('friendica_profiles', ['$result' => $result], $this->parameters['extension'] ?? null);
69 * @param array $profile_row array containing data from db table 'profile'
70 * @param ProfileFields $profileFields
72 * @throws HTTPException\InternalServerErrorException
74 private static function formatProfile($profile_row, ProfileFields $profileFields)
77 foreach ($profileFields as $profileField) {
79 'label' => $profileField->label,
80 'value' => BBCode::convert($profileField->value, false, BBCode::API),
85 'profile_id' => $profile_row['id'],
86 'profile_name' => null,
88 'hide_friends' => $profile_row['hide-friends'] ? true : false,
89 'profile_photo' => $profile_row['photo'],
90 'profile_thumb' => $profile_row['thumb'],
91 'publish' => $profile_row['publish'] ? true : false,
92 'net_publish' => $profile_row['net-publish'] ? true : false,
93 'description' => $profile_row['about'],
94 'date_of_birth' => $profile_row['dob'],
95 'address' => $profile_row['address'],
96 'city' => $profile_row['locality'],
97 'region' => $profile_row['region'],
98 'postal_code' => $profile_row['postal-code'],
99 'country' => $profile_row['country-name'],
103 'marital_with' => null,
104 'marital_since' => null,
108 'public_keywords' => $profile_row['pub_keywords'],
109 'private_keywords' => $profile_row['prv_keywords'],
121 'social_networks' => null,
122 'homepage' => $profile_row['homepage'],
124 'custom_fields' => $custom_fields,