2020-01-23 14:08:37 +00:00
|
|
|
<?php
|
2020-02-09 14:45:36 +00:00
|
|
|
/**
|
2022-01-02 07:27:47 +00:00
|
|
|
* @copyright Copyright (C) 2010-2022, the Friendica project
|
2020-02-09 14:45:36 +00:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2020-01-23 14:08:37 +00:00
|
|
|
|
|
|
|
namespace Friendica\Module\Api\Friendica\Profile;
|
|
|
|
|
2021-10-08 17:45:20 +00:00
|
|
|
use Friendica\Profile\ProfileField\Collection\ProfileFields;
|
2020-01-23 14:08:37 +00:00
|
|
|
use Friendica\Content\Text\BBCode;
|
|
|
|
use Friendica\DI;
|
|
|
|
use Friendica\Model\Profile;
|
|
|
|
use Friendica\Module\BaseApi;
|
|
|
|
use Friendica\Network\HTTPException;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* API endpoint: /api/friendica/profile/show
|
|
|
|
*/
|
|
|
|
class Show extends BaseApi
|
|
|
|
{
|
2021-11-20 14:38:03 +00:00
|
|
|
protected function rawContent(array $request = [])
|
2020-01-23 14:08:37 +00:00
|
|
|
{
|
2021-06-08 12:00:22 +00:00
|
|
|
self::checkAllowedScope(self::SCOPE_READ);
|
2021-06-08 06:32:24 +00:00
|
|
|
$uid = self::getCurrentUserID();
|
2020-01-23 14:08:37 +00:00
|
|
|
|
|
|
|
// retrieve general information about profiles for user
|
|
|
|
$directory = DI::config()->get('system', 'directory');
|
|
|
|
|
2021-06-08 06:32:24 +00:00
|
|
|
$profile = Profile::getByUID($uid);
|
2020-01-23 14:08:37 +00:00
|
|
|
|
2021-10-10 18:54:29 +00:00
|
|
|
$profileFields = DI::profileField()->selectPublicFieldsByUserId($uid);
|
2020-01-23 14:08:37 +00:00
|
|
|
|
|
|
|
$profile = self::formatProfile($profile, $profileFields);
|
|
|
|
|
|
|
|
$profiles = [];
|
2022-01-16 19:38:59 +00:00
|
|
|
if ($this->parameters['extension'] ?? '' == 'xml') {
|
2020-01-23 14:08:37 +00:00
|
|
|
$profiles['0:profile'] = $profile;
|
|
|
|
} else {
|
|
|
|
$profiles[] = $profile;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = [
|
|
|
|
'multi_profiles' => false,
|
|
|
|
'global_dir' => $directory,
|
2021-11-18 14:49:12 +00:00
|
|
|
'friendica_owner' => DI::twitterUser()->createFromUserId($uid),
|
2020-01-23 14:08:37 +00:00
|
|
|
'profiles' => $profiles
|
|
|
|
];
|
|
|
|
|
2021-11-21 20:52:36 +00:00
|
|
|
$this->response->exit('friendica_profiles', ['$result' => $result], $this->parameters['extension'] ?? null);
|
2020-01-23 14:08:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $profile_row array containing data from db table 'profile'
|
|
|
|
* @param ProfileFields $profileFields
|
|
|
|
* @return array
|
|
|
|
* @throws HTTPException\InternalServerErrorException
|
|
|
|
*/
|
|
|
|
private static function formatProfile($profile_row, ProfileFields $profileFields)
|
|
|
|
{
|
|
|
|
$custom_fields = [];
|
|
|
|
foreach ($profileFields as $profileField) {
|
|
|
|
$custom_fields[] = [
|
|
|
|
'label' => $profileField->label,
|
2020-05-16 16:28:15 +00:00
|
|
|
'value' => BBCode::convert($profileField->value, false, BBCode::API),
|
2020-01-23 14:08:37 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
'profile_id' => $profile_row['id'],
|
|
|
|
'profile_name' => null,
|
|
|
|
'is_default' => null,
|
|
|
|
'hide_friends' => $profile_row['hide-friends'] ? true : false,
|
|
|
|
'profile_photo' => $profile_row['photo'],
|
|
|
|
'profile_thumb' => $profile_row['thumb'],
|
|
|
|
'publish' => $profile_row['publish'] ? true : false,
|
|
|
|
'net_publish' => $profile_row['net-publish'] ? true : false,
|
2020-02-09 07:36:19 +00:00
|
|
|
'description' => $profile_row['about'],
|
2020-01-23 14:08:37 +00:00
|
|
|
'date_of_birth' => $profile_row['dob'],
|
|
|
|
'address' => $profile_row['address'],
|
|
|
|
'city' => $profile_row['locality'],
|
|
|
|
'region' => $profile_row['region'],
|
|
|
|
'postal_code' => $profile_row['postal-code'],
|
|
|
|
'country' => $profile_row['country-name'],
|
|
|
|
'hometown' => null,
|
|
|
|
'gender' => null,
|
|
|
|
'marital' => null,
|
|
|
|
'marital_with' => null,
|
|
|
|
'marital_since' => null,
|
|
|
|
'sexual' => null,
|
|
|
|
'politic' => null,
|
|
|
|
'religion' => null,
|
|
|
|
'public_keywords' => $profile_row['pub_keywords'],
|
|
|
|
'private_keywords' => $profile_row['prv_keywords'],
|
|
|
|
'likes' => null,
|
|
|
|
'dislikes' => null,
|
|
|
|
'about' => null,
|
|
|
|
'music' => null,
|
|
|
|
'book' => null,
|
|
|
|
'tv' => null,
|
|
|
|
'film' => null,
|
|
|
|
'interest' => null,
|
|
|
|
'romance' => null,
|
|
|
|
'work' => null,
|
|
|
|
'education' => null,
|
|
|
|
'social_networks' => null,
|
|
|
|
'homepage' => $profile_row['homepage'],
|
|
|
|
'users' => [],
|
|
|
|
'custom_fields' => $custom_fields,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|