Merge pull request #8163 from MrPetovan/task/7817-custom-fields-part-3

New custom profile fields feature part 3: Updating the API
This commit is contained in:
Philipp 2020-01-31 22:39:11 +01:00 committed by GitHub
commit 0406fe7ade
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
47 changed files with 351 additions and 358 deletions

View File

@ -645,11 +645,7 @@ On error:
### GET api/friendica/profile/show
Returns the [Profile](help/API-Entities#Profile) data of all profiles or a single profile of the authenticated user.
#### Parameters
* `profile_id` (optional): id of the profile to be returned. If omitted all profiles are returned by default.
Returns the [Profile](help/API-Entities#Profile) data of the authenticated user.
#### Return values
@ -664,6 +660,23 @@ HTTP 403 Forbidden: when no authentication was provided
HTTP 400 Bad Request: if given profile_id is not in the database or is not assigned to the authenticated user
General description of profile data in API returns:
- hide_friends: true if friends are hidden
- profile_photo
- profile_thumb
- publish: true if published on the server's local directory
- net_publish: true if published to global_dir
- fullname
- date_of_birth
- description
- xmpp
- homepage
- address
- locality
- region
- postal_code
- country
- pub_keywords
- custom_fields: list of public custom fields
---

View File

@ -2906,60 +2906,6 @@ function api_format_items_activities($item, $type = "json")
return $activities;
}
/**
* return data from profiles
*
* @param array $profile_row array containing data from db table 'profile'
* @return array
* @throws InternalServerErrorException
*/
function api_format_items_profiles($profile_row)
{
$profile = [
'profile_id' => $profile_row['id'],
'profile_name' => $profile_row['profile-name'],
'is_default' => $profile_row['is-default'] ? true : false,
'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,
'description' => $profile_row['pdesc'],
'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' => $profile_row['hometown'],
'gender' => $profile_row['gender'],
'marital' => $profile_row['marital'],
'marital_with' => $profile_row['with'],
'marital_since' => $profile_row['howlong'],
'sexual' => $profile_row['sexual'],
'politic' => $profile_row['politic'],
'religion' => $profile_row['religion'],
'public_keywords' => $profile_row['pub_keywords'],
'private_keywords' => $profile_row['prv_keywords'],
'likes' => BBCode::convert(api_clean_plain_items($profile_row['likes']) , false, 2),
'dislikes' => BBCode::convert(api_clean_plain_items($profile_row['dislikes']) , false, 2),
'about' => BBCode::convert(api_clean_plain_items($profile_row['about']) , false, 2),
'music' => BBCode::convert(api_clean_plain_items($profile_row['music']) , false, 2),
'book' => BBCode::convert(api_clean_plain_items($profile_row['book']) , false, 2),
'tv' => BBCode::convert(api_clean_plain_items($profile_row['tv']) , false, 2),
'film' => BBCode::convert(api_clean_plain_items($profile_row['film']) , false, 2),
'interest' => BBCode::convert(api_clean_plain_items($profile_row['interest']) , false, 2),
'romance' => BBCode::convert(api_clean_plain_items($profile_row['romance']) , false, 2),
'work' => BBCode::convert(api_clean_plain_items($profile_row['work']) , false, 2),
'education' => BBCode::convert(api_clean_plain_items($profile_row['education']), false, 2),
'social_networks' => BBCode::convert(api_clean_plain_items($profile_row['contact']) , false, 2),
'homepage' => $profile_row['homepage'],
'users' => null
];
return $profile;
}
/**
* format items to be returned by api
*
@ -6104,78 +6050,6 @@ function api_friendica_direct_messages_search($type, $box = "")
/// @TODO move to top of file or somewhere better
api_register_func('api/friendica/direct_messages_search', 'api_friendica_direct_messages_search', true);
/**
* return data of all the profiles a user has to the client
*
* @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
* @return string|array
* @throws BadRequestException
* @throws ForbiddenException
* @throws ImagickException
* @throws InternalServerErrorException
* @throws UnauthorizedException
*/
function api_friendica_profile_show($type)
{
$a = DI::app();
if (api_user() === false) {
throw new ForbiddenException();
}
// input params
$profile_id = $_REQUEST['profile_id'] ?? 0;
// retrieve general information about profiles for user
$multi_profiles = Feature::isEnabled(api_user(), 'multi_profiles');
$directory = DI::config()->get('system', 'directory');
// get data of the specified profile id or all profiles of the user if not specified
if ($profile_id != 0) {
$r = Profile::getById(api_user(), $profile_id);
// error message if specified gid is not in database
if (!DBA::isResult($r)) {
throw new BadRequestException("profile_id not available");
}
} else {
$r = Profile::getListByUser(api_user());
}
// loop through all returned profiles and retrieve data and users
$k = 0;
$profiles = [];
if (DBA::isResult($r)) {
foreach ($r as $rr) {
$profile = api_format_items_profiles($rr);
// select all users from contact table, loop and prepare standard return for user data
$users = [];
$nurls = Contact::selectToArray(['id', 'nurl'], ['uid' => api_user(), 'profile-id' => $rr['id']]);
foreach ($nurls as $nurl) {
$user = api_get_user($a, $nurl['nurl']);
($type == "xml") ? $users[$k++ . ":user"] = $user : $users[] = $user;
}
$profile['users'] = $users;
// add prepared profile data to array for final return
if ($type == "xml") {
$profiles[$k++ . ":profile"] = $profile;
} else {
$profiles[] = $profile;
}
}
}
// return settings, authenticated user and profiles data
$self = DBA::selectFirst('contact', ['nurl'], ['uid' => api_user(), 'self' => true]);
$result = ['multi_profiles' => $multi_profiles ? true : false,
'global_dir' => $directory,
'friendica_owner' => api_get_user($a, $self['nurl']),
'profiles' => $profiles];
return api_format_data("friendica_profiles", $type, ['$result' => $result]);
}
api_register_func('api/friendica/profile/show', 'api_friendica_profile_show', true, API_METHOD_GET);
/**
* Returns a list of saved searches.
*

View File

@ -0,0 +1,20 @@
<?php
namespace Friendica\Collection\Api\Mastodon;
use Friendica\Api\Entity\Mastodon\Field;
use Friendica\BaseCollection;
class Fields extends BaseCollection
{
/**
* @param Field[] $entities
* @param int|null $totalCount
*/
public function __construct(array $entities = [], int $totalCount = null)
{
parent::__construct($entities);
$this->totalCount = $totalCount ?? count($entities);
}
}

View File

@ -236,6 +236,14 @@ abstract class DI
return self::$dice->create(Factory\Api\Mastodon\Emoji::class);
}
/**
* @return Factory\Api\Mastodon\Field
*/
public static function mstdnField()
{
return self::$dice->create(Factory\Api\Mastodon\Field::class);
}
/**
* @return Factory\Api\Mastodon\FollowRequest
*/

View File

@ -4,26 +4,35 @@ namespace Friendica\Factory\Api\Mastodon;
use Friendica\App\BaseURL;
use Friendica\BaseFactory;
use Friendica\Collection\Api\Mastodon\Fields;
use Friendica\Model\APContact;
use Friendica\Model\Contact;
use Friendica\Network\HTTPException;
use Friendica\Repository\PermissionSet;
use Friendica\Repository\ProfileField;
use Psr\Log\LoggerInterface;
class Account extends BaseFactory
{
/** @var BaseURL */
protected $baseUrl;
/** @var ProfileField */
protected $profileField;
/** @var Field */
protected $mstdnField;
public function __construct(LoggerInterface $logger, BaseURL $baseURL)
public function __construct(LoggerInterface $logger, BaseURL $baseURL, ProfileField $profileField, Field $mstdnField)
{
parent::__construct($logger);
$this->baseUrl = $baseURL;
$this->profileField = $profileField;
$this->mstdnField = $mstdnField;
}
/**
* @param int $contactId
* @param int $uid User Id
* @param int $uid Public contact (=0) or owner user id
* @return \Friendica\Object\Api\Mastodon\Account
* @throws HTTPException\InternalServerErrorException
* @throws \ImagickException
@ -41,6 +50,24 @@ class Account extends BaseFactory
$apcontact = APContact::getByURL($publicContact['url'], false);
return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $publicContact, $apcontact, $userContact);
return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $publicContact, new Fields(), $apcontact, $userContact);
}
/**
* @param int $userId
* @return \Friendica\Object\Api\Mastodon\Account
* @throws HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public function createFromUserId(int $userId)
{
$publicContact = Contact::selectFirst([], ['uid' => $userId, 'self' => true]);
$profileFields = $this->profileField->select(['uid' => $userId, 'psid' => PermissionSet::PUBLIC]);
$fields = $this->mstdnField->createFromProfileFields($profileFields);
$apcontact = APContact::getByURL($publicContact['url'], false);
return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $publicContact, $fields, $apcontact);
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace Friendica\Factory\Api\Mastodon;
use Friendica\BaseFactory;
use Friendica\Collection\Api\Mastodon\Fields;
use Friendica\Collection\ProfileFields;
use Friendica\Content\Text\BBCode;
use Friendica\Model\ProfileField;
use Friendica\Network\HTTPException;
class Field extends BaseFactory
{
/**
* @param ProfileField $profileField
* @return \Friendica\Api\Entity\Mastodon\Field
* @throws HTTPException\InternalServerErrorException
*/
public function createFromProfileField(ProfileField $profileField)
{
return new \Friendica\Api\Entity\Mastodon\Field($profileField->label, BBCode::convert($profileField->value, false, 9));
}
/**
* @param ProfileFields $profileFields
* @return Fields
* @throws HTTPException\InternalServerErrorException
*/
public function createFromProfileFields(ProfileFields $profileFields)
{
$fields = [];
foreach ($profileFields as $profileField) {
$fields[] = $this->createFromProfileField($profileField);
}
return new Fields($fields);
}
}

View File

@ -6,10 +6,10 @@ use Friendica\Content\Text\Markdown;
use Friendica\Core\Addon;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Module\BaseAdminModule;
use Friendica\Module\BaseAdmin;
use Friendica\Util\Strings;
class Details extends BaseAdminModule
class Details extends BaseAdmin
{
public static function post(array $parameters = [])
{

View File

@ -5,9 +5,9 @@ namespace Friendica\Module\Admin\Addons;
use Friendica\Core\Addon;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Module\BaseAdminModule;
use Friendica\Module\BaseAdmin;
class Index extends BaseAdminModule
class Index extends BaseAdmin
{
public static function content(array $parameters = [])
{

View File

@ -6,10 +6,10 @@ use Friendica\Content\Pager;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Module\BaseAdminModule;
use Friendica\Module\BaseAdmin;
use Friendica\Model;
class Contact extends BaseAdminModule
class Contact extends BaseAdmin
{
public static function post(array $parameters = [])
{

View File

@ -4,10 +4,10 @@ namespace Friendica\Module\Admin\Blocklist;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Module\BaseAdminModule;
use Friendica\Module\BaseAdmin;
use Friendica\Util\Strings;
class Server extends BaseAdminModule
class Server extends BaseAdmin
{
public static function post(array $parameters = [])
{

View File

@ -7,9 +7,9 @@ use Friendica\Core\Update;
use Friendica\Database\DBA;
use Friendica\Database\DBStructure;
use Friendica\DI;
use Friendica\Module\BaseAdminModule;
use Friendica\Module\BaseAdmin;
class DBSync extends BaseAdminModule
class DBSync extends BaseAdmin
{
public static function content(array $parameters = [])
{

View File

@ -5,9 +5,9 @@ namespace Friendica\Module\Admin;
use Friendica\Content\Feature;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Module\BaseAdminModule;
use Friendica\Module\BaseAdmin;
class Features extends BaseAdminModule
class Features extends BaseAdmin
{
public static function post(array $parameters = [])
{

View File

@ -5,9 +5,9 @@ namespace Friendica\Module\Admin;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Module\BaseAdminModule;
use Friendica\Module\BaseAdmin;
class Federation extends BaseAdminModule
class Federation extends BaseAdmin
{
public static function content(array $parameters = [])
{

View File

@ -5,10 +5,10 @@ namespace Friendica\Module\Admin\Item;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Module\BaseAdminModule;
use Friendica\Module\BaseAdmin;
use Friendica\Util\Strings;
class Delete extends BaseAdminModule
class Delete extends BaseAdmin
{
public static function post(array $parameters = [])
{

View File

@ -5,12 +5,12 @@ namespace Friendica\Module\Admin\Item;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Model;
use Friendica\Module\BaseAdminModule;
use Friendica\Module\BaseAdmin;
/**
* @author Hypolite Petovan <mrpetovan@gmail.com>
*/
class Source extends BaseAdminModule
class Source extends BaseAdmin
{
public static function content(array $parameters = [])

View File

@ -4,11 +4,11 @@ namespace Friendica\Module\Admin\Logs;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Module\BaseAdminModule;
use Friendica\Module\BaseAdmin;
use Friendica\Util\Strings;
use Psr\Log\LogLevel;
class Settings extends BaseAdminModule
class Settings extends BaseAdmin
{
public static function post(array $parameters = [])
{

View File

@ -4,10 +4,10 @@ namespace Friendica\Module\Admin\Logs;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Module\BaseAdminModule;
use Friendica\Module\BaseAdmin;
use Friendica\Util\Strings;
class View extends BaseAdminModule
class View extends BaseAdmin
{
public static function content(array $parameters = [])
{

View File

@ -2,9 +2,9 @@
namespace Friendica\Module\Admin;
use Friendica\Module\BaseAdminModule;
use Friendica\Module\BaseAdmin;
class PhpInfo extends BaseAdminModule
class PhpInfo extends BaseAdmin
{
public static function rawContent(array $parameters = [])
{

View File

@ -5,7 +5,7 @@ namespace Friendica\Module\Admin;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Module\BaseAdminModule;
use Friendica\Module\BaseAdmin;
use Friendica\Util\Arrays;
use Friendica\Util\DateTimeFormat;
@ -17,7 +17,7 @@ use Friendica\Util\DateTimeFormat;
*
* @return string
*/
class Queue extends BaseAdminModule
class Queue extends BaseAdmin
{
public static function content(array $parameters = [])
{

View File

@ -9,7 +9,7 @@ use Friendica\Core\Theme;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Module\BaseAdminModule;
use Friendica\Module\BaseAdmin;
use Friendica\Module\Register;
use Friendica\Protocol\PortableContact;
use Friendica\Util\BasePath;
@ -18,7 +18,7 @@ use Friendica\Worker\Delivery;
require_once __DIR__ . '/../../../boot.php';
class Site extends BaseAdminModule
class Site extends BaseAdmin
{
public static function post(array $parameters = [])
{

View File

@ -11,13 +11,13 @@ use Friendica\Database\DBA;
use Friendica\Database\DBStructure;
use Friendica\DI;
use Friendica\Model\Register;
use Friendica\Module\BaseAdminModule;
use Friendica\Module\BaseAdmin;
use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Util\ConfigFileLoader;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
class Summary extends BaseAdminModule
class Summary extends BaseAdmin
{
public static function content(array $parameters = [])
{

View File

@ -6,10 +6,10 @@ use Friendica\Content\Text\Markdown;
use Friendica\Core\Renderer;
use Friendica\Core\Theme;
use Friendica\DI;
use Friendica\Module\BaseAdminModule;
use Friendica\Module\BaseAdmin;
use Friendica\Util\Strings;
class Details extends BaseAdminModule
class Details extends BaseAdmin
{
public static function post(array $parameters = [])
{

View File

@ -4,10 +4,10 @@ namespace Friendica\Module\Admin\Themes;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Module\BaseAdminModule;
use Friendica\Module\BaseAdmin;
use Friendica\Util\Strings;
class Embed extends BaseAdminModule
class Embed extends BaseAdmin
{
public static function init(array $parameters = [])
{

View File

@ -5,10 +5,10 @@ namespace Friendica\Module\Admin\Themes;
use Friendica\Core\Renderer;
use Friendica\Core\Theme;
use Friendica\DI;
use Friendica\Module\BaseAdminModule;
use Friendica\Module\BaseAdmin;
use Friendica\Util\Strings;
class Index extends BaseAdminModule
class Index extends BaseAdmin
{
public static function content(array $parameters = [])
{

View File

@ -4,9 +4,9 @@ namespace Friendica\Module\Admin;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Module\BaseAdminModule;
use Friendica\Module\BaseAdmin;
class Tos extends BaseAdminModule
class Tos extends BaseAdmin
{
public static function post(array $parameters = [])
{

View File

@ -8,11 +8,11 @@ use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Register;
use Friendica\Model\User;
use Friendica\Module\BaseAdminModule;
use Friendica\Module\BaseAdmin;
use Friendica\Util\Strings;
use Friendica\Util\Temporal;
class Users extends BaseAdminModule
class Users extends BaseAdmin
{
public static function post(array $parameters = [])
{

View File

@ -0,0 +1,114 @@
<?php
namespace Friendica\Module\Api\Friendica\Profile;
use Friendica\Collection\ProfileFields;
use Friendica\Content\Text\BBCode;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Profile;
use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException;
use Friendica\Repository\PermissionSet;
/**
* API endpoint: /api/friendica/profile/show
*/
class Show extends BaseApi
{
public static function rawContent(array $parameters = [])
{
if (self::login() === false) {
throw new HTTPException\ForbiddenException();
}
// retrieve general information about profiles for user
$directory = DI::config()->get('system', 'directory');
$profile = Profile::getByUID(self::$current_user_id);
$profileFields = DI::profileField()->select(['uid' => self::$current_user_id, 'psid' => PermissionSet::PUBLIC]);
$profile = self::formatProfile($profile, $profileFields);
$profiles = [];
if (self::$format == 'xml') {
$profiles['0:profile'] = $profile;
} else {
$profiles[] = $profile;
}
// return settings, authenticated user and profiles data
$self = Contact::selectFirst(['nurl'], ['uid' => self::$current_user_id, 'self' => true]);
$result = [
'multi_profiles' => false,
'global_dir' => $directory,
'friendica_owner' => self::getUser($self['nurl']),
'profiles' => $profiles
];
echo self::format('friendica_profiles', ['$result' => $result]);
exit;
}
/**
* @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,
'value' => BBCode::convert($profileField->value, false, 2),
];
}
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,
'description' => $profile_row['pdesc'],
'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,
];
}
}

View File

@ -21,7 +21,7 @@ require_once 'boot.php';
*
* @package Friendica\Module
*/
abstract class BaseAdminModule extends BaseModule
abstract class BaseAdmin extends BaseModule
{
public static function post(array $parameters = [])
{

View File

@ -87,20 +87,53 @@ class BaseApi extends BaseModule
return api_get_user(DI::app(), $contact_id);
}
protected static function format($root_element, $data)
/**
* Formats the data according to the data type
*
* @param string $root_element
* @param array $data An array with a single element containing the returned result
* @return false|string
*/
protected static function format(string $root_element, array $data)
{
$return = api_format_data($root_element, self::$format, $data);
switch (self::$format) {
case "atom":
case "rss":
case "xml":
$ret = api_create_xml($data, $root_element);
header("Content-Type: text/xml");
break;
case "json":
default:
$ret = $data;
header("Content-Type: application/json");
if (!empty($return)) {
$json = json_encode(end($return));
if (!empty($_GET['callback'])) {
$json = $_GET['callback'] . "(" . $json . ")";
}
$return = $json;
}
break;
case "rss":
header("Content-Type: application/rss+xml");
$return = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . $return;
break;
case "atom":
header("Content-Type: application/atom+xml");
$return = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . $return;
break;
}
return $ret;
return $return;
}
/**
* Creates the XML from a JSON style array
*
* @param $data
* @param $root_element
* @return string
*/
protected static function createXml($data, $root_element)
{
return api_create_xml($data, $root_element);
}
}

View File

@ -17,7 +17,7 @@ use Friendica\Util\Proxy as ProxyUtils;
/**
* Base class for search modules
*/
class BaseSearchModule extends BaseModule
class BaseSearch extends BaseModule
{
/**
* Performs a contact search with an optional prefix

View File

@ -7,7 +7,7 @@ use Friendica\Content\Feature;
use Friendica\Core\Renderer;
use Friendica\DI;
class BaseSettingsModule extends BaseModule
class BaseSettings extends BaseModule
{
public static function content(array $parameters = [])
{

View File

@ -4,14 +4,14 @@ namespace Friendica\Module\Search;
use Friendica\Content\Widget;
use Friendica\DI;
use Friendica\Module\BaseSearchModule;
use Friendica\Module\BaseSearch;
use Friendica\Module\Security\Login;
use Friendica\Util\Strings;
/**
* Directory search module
*/
class Directory extends BaseSearchModule
class Directory extends BaseSearch
{
public static function content(array $parameters = [])
{

View File

@ -15,11 +15,11 @@ use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\Term;
use Friendica\Module\BaseSearchModule;
use Friendica\Module\BaseSearch;
use Friendica\Network\HTTPException;
use Friendica\Util\Strings;
class Index extends BaseSearchModule
class Index extends BaseSearch
{
public static function content(array $parameters = [])
{

View File

@ -8,14 +8,14 @@ use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\User;
use Friendica\Module\BaseSettingsModule;
use Friendica\Module\BaseSettings;
use Friendica\Network\HTTPException;
use Friendica\Util\Strings;
/**
* Account delegation settings module
*/
class Delegation extends BaseSettingsModule
class Delegation extends BaseSettings
{
public static function post(array $parameters = [])
{

View File

@ -16,14 +16,14 @@ use Friendica\Model\GContact;
use Friendica\Model\Profile;
use Friendica\Model\ProfileField;
use Friendica\Model\User;
use Friendica\Module\BaseSettingsModule;
use Friendica\Module\BaseSettings;
use Friendica\Module\Security\Login;
use Friendica\Network\HTTPException;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings;
use Friendica\Util\Temporal;
class Index extends BaseSettingsModule
class Index extends BaseSettings
{
public static function post(array $parameters = [])
{

View File

@ -9,10 +9,10 @@ use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Photo;
use Friendica\Module\BaseSettingsModule;
use Friendica\Module\BaseSettings;
use Friendica\Network\HTTPException;
class Crop extends BaseSettingsModule
class Crop extends BaseSettings
{
public static function post(array $parameters = [])
{

View File

@ -8,13 +8,13 @@ use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Photo;
use Friendica\Module\BaseSettingsModule;
use Friendica\Module\BaseSettings;
use Friendica\Network\HTTPException;
use Friendica\Object\Image;
use Friendica\Util\Images;
use Friendica\Util\Strings;
class Index extends BaseSettingsModule
class Index extends BaseSettings
{
public static function post(array $parameters = [])
{

View File

@ -5,7 +5,7 @@ namespace Friendica\Module\Settings\TwoFactor;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Model\TwoFactor\AppSpecificPassword;
use Friendica\Module\BaseSettingsModule;
use Friendica\Module\BaseSettings;
use Friendica\Module\Security\Login;
/**
@ -13,7 +13,7 @@ use Friendica\Module\Security\Login;
*
* @package Friendica\Module\TwoFactor
*/
class AppSpecific extends BaseSettingsModule
class AppSpecific extends BaseSettings
{
private static $appSpecificPassword = null;

View File

@ -8,11 +8,11 @@ use Friendica\DI;
use Friendica\Model\TwoFactor\AppSpecificPassword;
use Friendica\Model\TwoFactor\RecoveryCode;
use Friendica\Model\User;
use Friendica\Module\BaseSettingsModule;
use Friendica\Module\BaseSettings;
use Friendica\Module\Security\Login;
use PragmaRX\Google2FA\Google2FA;
class Index extends BaseSettingsModule
class Index extends BaseSettings
{
public static function post(array $parameters = [])
{

View File

@ -5,7 +5,7 @@ namespace Friendica\Module\Settings\TwoFactor;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Model\TwoFactor\RecoveryCode;
use Friendica\Module\BaseSettingsModule;
use Friendica\Module\BaseSettings;
use Friendica\Module\Security\Login;
/**
@ -13,7 +13,7 @@ use Friendica\Module\Security\Login;
*
* @package Friendica\Module\TwoFactor
*/
class Recovery extends BaseSettingsModule
class Recovery extends BaseSettings
{
public static function init(array $parameters = [])
{

View File

@ -9,7 +9,7 @@ use BaconQrCode\Writer;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Module\BaseSettingsModule;
use Friendica\Module\BaseSettings;
use Friendica\Module\Security\Login;
use PragmaRX\Google2FA\Google2FA;
@ -18,7 +18,7 @@ use PragmaRX\Google2FA\Google2FA;
*
* @package Friendica\Module\TwoFactor\Settings
*/
class Verify extends BaseSettingsModule
class Verify extends BaseSettings
{
public static function init(array $parameters = [])
{

View File

@ -11,12 +11,12 @@ use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\Database\DBStructure;
use Friendica\DI;
use Friendica\Module\BaseSettingsModule;
use Friendica\Module\BaseSettings;
/**
* Module to export user data
**/
class UserExport extends BaseSettingsModule
class UserExport extends BaseSettings
{
/**
* Handle the request to export data.

View File

@ -4,6 +4,7 @@ namespace Friendica\Object\Api\Mastodon;
use Friendica\App\BaseURL;
use Friendica\BaseEntity;
use Friendica\Collection\Api\Mastodon\Fields;
use Friendica\Content\Text\BBCode;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
@ -70,7 +71,7 @@ class Account extends BaseEntity
* @param array $userContact Optional full contact table record with uid != 0
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function __construct(BaseURL $baseUrl, array $publicContact, array $apcontact = [], array $userContact = [])
public function __construct(BaseURL $baseUrl, array $publicContact, Fields $fields, array $apcontact = [], array $userContact = [])
{
$this->id = $publicContact['id'];
$this->username = $publicContact['nick'];
@ -94,7 +95,7 @@ class Account extends BaseEntity
// No custom emojis per account in Friendica
$this->emojis = [];
// No metadata fields in Friendica
$this->fields = [];
$this->fields = $fields->getArrayCopy();
$this->bot = ($publicContact['contact-type'] == Contact::TYPE_NEWS);
$this->group = ($publicContact['contact-type'] == Contact::TYPE_COMMUNITY);
$this->discoverable = !$publicContact['unsearchable'];

View File

@ -7,7 +7,7 @@ use Friendica\BaseEntity;
/**
* Class Field
*
* @see https://docs.joinmastodon.org/api/entities/#field
* @see https://docs.joinmastodon.org/entities/field/
*/
class Field extends BaseEntity
{
@ -17,4 +17,12 @@ class Field extends BaseEntity
protected $value;
/** @var string (Datetime)*/
protected $verified_at;
public function __construct(string $name, string $value)
{
$this->name = $name;
$this->value = $value;
// Link verification unsupported
$this->verified_at = null;
}
}

View File

@ -3,6 +3,7 @@
namespace Friendica\Object\Api\Mastodon;
use Friendica\App\BaseURL;
use Friendica\Collection\Api\Mastodon\Fields;
/**
* Virtual entity to separate Accounts from Follow Requests.
@ -24,7 +25,7 @@ class FollowRequest extends Account
*/
public function __construct(BaseURL $baseUrl, int $introduction_id, array $publicContact, array $apcontact = [], array $userContact = [])
{
parent::__construct($baseUrl, $publicContact, $apcontact, $userContact);
parent::__construct($baseUrl, $publicContact, new Fields(), $apcontact, $userContact);
$this->id = $introduction_id;
}

View File

@ -35,6 +35,9 @@ return [
'/instance' => [Module\Api\Mastodon\Instance::class, [R::GET ]],
'/instance/peers' => [Module\Api\Mastodon\Instance\Peers::class, [R::GET ]],
],
'/friendica' => [
'/profile/show' => [Module\Api\Friendica\Profile\Show::class , [R::GET ]],
],
],
'/admin' => [

View File

@ -2489,102 +2489,6 @@ class ApiTest extends DatabaseTest
$this->assertArrayHasKey('friendica:attendmaybe', $result);
}
/**
* Test the api_format_items_profiles() function.
*
* @return void
*/
public function testApiFormatItemsProfiles()
{
$profile_row = [
'id' => 'profile_id',
'profile-name' => 'profile_name',
'is-default' => true,
'hide-friends' => true,
'photo' => 'profile_photo',
'thumb' => 'profile_thumb',
'publish' => true,
'net-publish' => true,
'pdesc' => 'description',
'dob' => 'date_of_birth',
'address' => 'address',
'locality' => 'city',
'region' => 'region',
'postal-code' => 'postal_code',
'country-name' => 'country',
'hometown' => 'hometown',
'gender' => 'gender',
'marital' => 'marital',
'with' => 'marital_with',
'howlong' => 'marital_since',
'sexual' => 'sexual',
'politic' => 'politic',
'religion' => 'religion',
'pub_keywords' => 'public_keywords',
'prv_keywords' => 'private_keywords',
'likes' => 'likes',
'dislikes' => 'dislikes',
'about' => 'about',
'music' => 'music',
'book' => 'book',
'tv' => 'tv',
'film' => 'film',
'interest' => 'interest',
'romance' => 'romance',
'work' => 'work',
'education' => 'education',
'contact' => 'social_networks',
'homepage' => 'homepage'
];
$result = api_format_items_profiles($profile_row);
$this->assertEquals(
[
'profile_id' => 'profile_id',
'profile_name' => 'profile_name',
'is_default' => true,
'hide_friends' => true,
'profile_photo' => 'profile_photo',
'profile_thumb' => 'profile_thumb',
'publish' => true,
'net_publish' => true,
'description' => 'description',
'date_of_birth' => 'date_of_birth',
'address' => 'address',
'city' => 'city',
'region' => 'region',
'postal_code' => 'postal_code',
'country' => 'country',
'hometown' => 'hometown',
'gender' => 'gender',
'marital' => 'marital',
'marital_with' => 'marital_with',
'marital_since' => 'marital_since',
'sexual' => 'sexual',
'politic' => 'politic',
'religion' => 'religion',
'public_keywords' => 'public_keywords',
'private_keywords' => 'private_keywords',
'likes' => 'likes',
'dislikes' => 'dislikes',
'about' => 'about',
'music' => 'music',
'book' => 'book',
'tv' => 'tv',
'film' => 'film',
'interest' => 'interest',
'romance' => 'romance',
'work' => 'work',
'education' => 'education',
'social_networks' => 'social_networks',
'homepage' => 'homepage',
'users' => null
],
$result
);
}
/**
* Test the api_format_items() function.
*
@ -3994,58 +3898,6 @@ XML;
$this->markTestIncomplete();
}
/**
* Test the api_friendica_profile_show() function.
*
* @return void
*/
public function testApiFriendicaProfileShow()
{
$result = api_friendica_profile_show('json');
// We can't use assertSelfUser() here because the user object is missing some properties.
$this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
$this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
$this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
$this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
$this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
$this->assertTrue($result['$result']['friendica_owner']['verified']);
$this->assertFalse($result['$result']['multi_profiles']);
}
/**
* Test the api_friendica_profile_show() function with a profile ID.
*
* @return void
*/
public function testApiFriendicaProfileShowWithProfileId()
{
$this->markTestIncomplete('We need to add a dataset for this.');
}
/**
* Test the api_friendica_profile_show() function with a wrong profile ID.
*
* @return void
* @expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiFriendicaProfileShowWithWrongProfileId()
{
$_REQUEST['profile_id'] = 666;
api_friendica_profile_show('json');
}
/**
* Test the api_friendica_profile_show() function without an authenticated user.
*
* @return void
* @expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
{
$_SESSION['authenticated'] = false;
api_friendica_profile_show('json');
}
/**
* Test the api_saved_searches_list() function.
*