### 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
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
---
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
*
$id = (!empty($_REQUEST['id']) ? intval($_REQUEST['id']) : 0);
try {
- $notification = DI::notify()->getByID($id);
- $notification->setSeen();
+ $notify = DI::notify()->getByID($id);
+ DI::notify()->setSeen(true, $notify);
- if ($notification->otype === Notify::OTYPE_ITEM) {
- $item = Item::selectFirstForUser(api_user(), [], ['id' => $notification->iid, 'uid' => api_user()]);
+ if ($notify->otype === Notify::OTYPE_ITEM) {
+ $item = Item::selectFirstForUser(api_user(), [], ['id' => $notify->iid, 'uid' => api_user()]);
if (DBA::isResult($item)) {
// we found the item, return it to the user
$ret = api_format_items([$item], $user_info, false, $type);
}
return api_format_data('result', $type, ['result' => "success"]);
} catch (NotFoundException $e) {
- throw new BadRequestException('Invalid argument');
+ throw new BadRequestException('Invalid argument', $e);
+ } catch (Exception $e) {
+ throw new InternalServerErrorException('Internal Server exception', $e);
}
}
/// @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.
*
--- /dev/null
+<?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);
+ }
+}
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
*/
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
$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);
}
}
--- /dev/null
+<?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);
+ }
+}
namespace Friendica\Model;
-use Exception;
use Friendica\BaseModel;
use Friendica\Content\Text\BBCode;
use Friendica\Database\Database;
$this->setMsgCache();
}
- /**
- * Set the notification as seen
- *
- * @param bool $seen true, if seen
- *
- * @return bool True, if the seen state could be saved
- */
- public function setSeen(bool $seen = true)
- {
- $this->seen = $seen;
- try {
- return $this->repo->update($this);
- } catch (Exception $e) {
- $this->logger->warning('Update failed.', ['$this' => $this, 'exception' => $e]);
- return false;
- }
- }
-
/**
* Sets the pre-formatted name (caching)
*/
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 = [])
{
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 = [])
{
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 = [])
{
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 = [])
{
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 = [])
{
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 = [])
{
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 = [])
{
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 = [])
{
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 = [])
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 = [])
{
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 = [])
{
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 = [])
{
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;
*
* @return string
*/
-class Queue extends BaseAdminModule
+class Queue extends BaseAdmin
{
public static function content(array $parameters = [])
{
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;
require_once __DIR__ . '/../../../boot.php';
-class Site extends BaseAdminModule
+class Site extends BaseAdmin
{
public static function post(array $parameters = [])
{
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 = [])
{
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 = [])
{
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 = [])
{
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 = [])
{
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 = [])
{
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 = [])
{
--- /dev/null
+<?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,
+ ];
+ }
+}
--- /dev/null
+<?php
+
+namespace Friendica\Module;
+
+use Friendica\BaseModule;
+use Friendica\Core\Addon;
+use Friendica\Core\Renderer;
+use Friendica\Core\Session;
+use Friendica\DI;
+use Friendica\Network\HTTPException\ForbiddenException;
+
+require_once 'boot.php';
+
+/**
+ * This abstract module is meant to be extended by all modules that are reserved to administrator users.
+ *
+ * It performs a blanket permission check in all the module methods as long as the relevant `parent::method()` is
+ * called in the inheriting module.
+ *
+ * Additionally, it puts together the administration page aside with all the administration links.
+ *
+ * @package Friendica\Module
+ */
+abstract class BaseAdmin extends BaseModule
+{
+ public static function post(array $parameters = [])
+ {
+ if (!is_site_admin()) {
+ return;
+ }
+
+ // do not allow a page manager to access the admin panel at all.
+ if (!empty($_SESSION['submanage'])) {
+ return;
+ }
+ }
+
+ public static function rawContent(array $parameters = [])
+ {
+ if (!is_site_admin()) {
+ return '';
+ }
+
+ if (!empty($_SESSION['submanage'])) {
+ return '';
+ }
+
+ return '';
+ }
+
+ public static function content(array $parameters = [])
+ {
+ if (!is_site_admin()) {
+ notice(DI::l10n()->t('Please login to continue.'));
+ Session::set('return_path', DI::args()->getQueryString());
+ DI::baseUrl()->redirect('login');
+ }
+
+ if (!empty($_SESSION['submanage'])) {
+ throw new ForbiddenException(DI::l10n()->t('Submanaged account can\'t access the administation pages. Please log back in as the master account.'));
+ }
+
+ // Header stuff
+ DI::page()['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('admin/settings_head.tpl'), []);
+
+ /*
+ * Side bar links
+ */
+
+ // array(url, name, extra css classes)
+ // not part of $aside to make the template more adjustable
+ $aside_sub = [
+ 'information' => [DI::l10n()->t('Information'), [
+ 'overview' => ['admin' , DI::l10n()->t('Overview') , 'overview'],
+ 'federation' => ['admin/federation' , DI::l10n()->t('Federation Statistics') , 'federation']
+ ]],
+ 'configuration' => [DI::l10n()->t('Configuration'), [
+ 'site' => ['admin/site' , DI::l10n()->t('Site') , 'site'],
+ 'users' => ['admin/users' , DI::l10n()->t('Users') , 'users'],
+ 'addons' => ['admin/addons' , DI::l10n()->t('Addons') , 'addons'],
+ 'themes' => ['admin/themes' , DI::l10n()->t('Themes') , 'themes'],
+ 'features' => ['admin/features' , DI::l10n()->t('Additional features') , 'features'],
+ 'tos' => ['admin/tos' , DI::l10n()->t('Terms of Service') , 'tos'],
+ ]],
+ 'database' => [DI::l10n()->t('Database'), [
+ 'dbsync' => ['admin/dbsync' , DI::l10n()->t('DB updates') , 'dbsync'],
+ 'deferred' => ['admin/queue/deferred', DI::l10n()->t('Inspect Deferred Workers'), 'deferred'],
+ 'workerqueue' => ['admin/queue' , DI::l10n()->t('Inspect worker Queue') , 'workerqueue'],
+ ]],
+ 'tools' => [DI::l10n()->t('Tools'), [
+ 'contactblock' => ['admin/blocklist/contact', DI::l10n()->t('Contact Blocklist') , 'contactblock'],
+ 'blocklist' => ['admin/blocklist/server' , DI::l10n()->t('Server Blocklist') , 'blocklist'],
+ 'deleteitem' => ['admin/item/delete' , DI::l10n()->t('Delete Item') , 'deleteitem'],
+ ]],
+ 'logs' => [DI::l10n()->t('Logs'), [
+ 'logsconfig' => ['admin/logs/', DI::l10n()->t('Logs') , 'logs'],
+ 'logsview' => ['admin/logs/view' , DI::l10n()->t('View Logs') , 'viewlogs'],
+ ]],
+ 'diagnostics' => [DI::l10n()->t('Diagnostics'), [
+ 'phpinfo' => ['admin/phpinfo' , DI::l10n()->t('PHP Info') , 'phpinfo'],
+ 'probe' => ['probe' , DI::l10n()->t('probe address') , 'probe'],
+ 'webfinger' => ['webfinger' , DI::l10n()->t('check webfinger') , 'webfinger'],
+ 'itemsource' => ['admin/item/source' , DI::l10n()->t('Item Source') , 'itemsource'],
+ 'babel' => ['babel' , DI::l10n()->t('Babel') , 'babel'],
+ ]],
+ ];
+
+ $t = Renderer::getMarkupTemplate('admin/aside.tpl');
+ DI::page()['aside'] .= Renderer::replaceMacros($t, [
+ '$admin' => ['addons_admin' => Addon::getAdminList()],
+ '$subpages' => $aside_sub,
+ '$admtxt' => DI::l10n()->t('Admin'),
+ '$plugadmtxt' => DI::l10n()->t('Addon Features'),
+ '$h_pending' => DI::l10n()->t('User registrations waiting for confirmation'),
+ '$admurl' => 'admin/'
+ ]);
+
+ return '';
+ }
+}
+++ /dev/null
-<?php
-
-namespace Friendica\Module;
-
-use Friendica\BaseModule;
-use Friendica\Core\Addon;
-use Friendica\Core\Renderer;
-use Friendica\Core\Session;
-use Friendica\DI;
-use Friendica\Network\HTTPException\ForbiddenException;
-
-require_once 'boot.php';
-
-/**
- * This abstract module is meant to be extended by all modules that are reserved to administrator users.
- *
- * It performs a blanket permission check in all the module methods as long as the relevant `parent::method()` is
- * called in the inheriting module.
- *
- * Additionally, it puts together the administration page aside with all the administration links.
- *
- * @package Friendica\Module
- */
-abstract class BaseAdminModule extends BaseModule
-{
- public static function post(array $parameters = [])
- {
- if (!is_site_admin()) {
- return;
- }
-
- // do not allow a page manager to access the admin panel at all.
- if (!empty($_SESSION['submanage'])) {
- return;
- }
- }
-
- public static function rawContent(array $parameters = [])
- {
- if (!is_site_admin()) {
- return '';
- }
-
- if (!empty($_SESSION['submanage'])) {
- return '';
- }
-
- return '';
- }
-
- public static function content(array $parameters = [])
- {
- if (!is_site_admin()) {
- notice(DI::l10n()->t('Please login to continue.'));
- Session::set('return_path', DI::args()->getQueryString());
- DI::baseUrl()->redirect('login');
- }
-
- if (!empty($_SESSION['submanage'])) {
- throw new ForbiddenException(DI::l10n()->t('Submanaged account can\'t access the administation pages. Please log back in as the master account.'));
- }
-
- // Header stuff
- DI::page()['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('admin/settings_head.tpl'), []);
-
- /*
- * Side bar links
- */
-
- // array(url, name, extra css classes)
- // not part of $aside to make the template more adjustable
- $aside_sub = [
- 'information' => [DI::l10n()->t('Information'), [
- 'overview' => ['admin' , DI::l10n()->t('Overview') , 'overview'],
- 'federation' => ['admin/federation' , DI::l10n()->t('Federation Statistics') , 'federation']
- ]],
- 'configuration' => [DI::l10n()->t('Configuration'), [
- 'site' => ['admin/site' , DI::l10n()->t('Site') , 'site'],
- 'users' => ['admin/users' , DI::l10n()->t('Users') , 'users'],
- 'addons' => ['admin/addons' , DI::l10n()->t('Addons') , 'addons'],
- 'themes' => ['admin/themes' , DI::l10n()->t('Themes') , 'themes'],
- 'features' => ['admin/features' , DI::l10n()->t('Additional features') , 'features'],
- 'tos' => ['admin/tos' , DI::l10n()->t('Terms of Service') , 'tos'],
- ]],
- 'database' => [DI::l10n()->t('Database'), [
- 'dbsync' => ['admin/dbsync' , DI::l10n()->t('DB updates') , 'dbsync'],
- 'deferred' => ['admin/queue/deferred', DI::l10n()->t('Inspect Deferred Workers'), 'deferred'],
- 'workerqueue' => ['admin/queue' , DI::l10n()->t('Inspect worker Queue') , 'workerqueue'],
- ]],
- 'tools' => [DI::l10n()->t('Tools'), [
- 'contactblock' => ['admin/blocklist/contact', DI::l10n()->t('Contact Blocklist') , 'contactblock'],
- 'blocklist' => ['admin/blocklist/server' , DI::l10n()->t('Server Blocklist') , 'blocklist'],
- 'deleteitem' => ['admin/item/delete' , DI::l10n()->t('Delete Item') , 'deleteitem'],
- ]],
- 'logs' => [DI::l10n()->t('Logs'), [
- 'logsconfig' => ['admin/logs/', DI::l10n()->t('Logs') , 'logs'],
- 'logsview' => ['admin/logs/view' , DI::l10n()->t('View Logs') , 'viewlogs'],
- ]],
- 'diagnostics' => [DI::l10n()->t('Diagnostics'), [
- 'phpinfo' => ['admin/phpinfo' , DI::l10n()->t('PHP Info') , 'phpinfo'],
- 'probe' => ['probe' , DI::l10n()->t('probe address') , 'probe'],
- 'webfinger' => ['webfinger' , DI::l10n()->t('check webfinger') , 'webfinger'],
- 'itemsource' => ['admin/item/source' , DI::l10n()->t('Item Source') , 'itemsource'],
- 'babel' => ['babel' , DI::l10n()->t('Babel') , 'babel'],
- ]],
- ];
-
- $t = Renderer::getMarkupTemplate('admin/aside.tpl');
- DI::page()['aside'] .= Renderer::replaceMacros($t, [
- '$admin' => ['addons_admin' => Addon::getAdminList()],
- '$subpages' => $aside_sub,
- '$admtxt' => DI::l10n()->t('Admin'),
- '$plugadmtxt' => DI::l10n()->t('Addon Features'),
- '$h_pending' => DI::l10n()->t('User registrations waiting for confirmation'),
- '$admurl' => 'admin/'
- ]);
-
- return '';
- }
-}
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 $return;
+ }
- return $ret;
+ /**
+ * 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);
}
}
--- /dev/null
+<?php
+
+namespace Friendica\Module;
+
+use Friendica\BaseModule;
+use Friendica\Content\ContactSelector;
+use Friendica\Content\Pager;
+use Friendica\Core\Renderer;
+use Friendica\Core\Search;
+use Friendica\DI;
+use Friendica\Model;
+use Friendica\Network\HTTPException;
+use Friendica\Object\Search\ContactResult;
+use Friendica\Object\Search\ResultList;
+use Friendica\Util\Proxy as ProxyUtils;
+
+/**
+ * Base class for search modules
+ */
+class BaseSearch extends BaseModule
+{
+ /**
+ * Performs a contact search with an optional prefix
+ *
+ * @param string $search Search query
+ * @param string $prefix A optional prefix (e.g. @ or !) for searching
+ *
+ * @return string
+ * @throws HTTPException\InternalServerErrorException
+ * @throws \ImagickException
+ */
+ public static function performContactSearch($search, $prefix = '')
+ {
+ $a = DI::app();
+ $config = DI::config();
+
+ $type = Search::TYPE_ALL;
+
+ $localSearch = $config->get('system', 'poco_local_search');
+
+ $search = $prefix . $search;
+
+ if (!$search) {
+ return '';
+ }
+
+ $header = '';
+
+ if (strpos($search, '@') === 0) {
+ $search = substr($search, 1);
+ $type = Search::TYPE_PEOPLE;
+ $header = DI::l10n()->t('People Search - %s', $search);
+
+ if (strrpos($search, '@') > 0) {
+ $results = Search::getContactsFromProbe($search);
+ }
+ }
+
+ if (strpos($search, '!') === 0) {
+ $search = substr($search, 1);
+ $type = Search::TYPE_FORUM;
+ $header = DI::l10n()->t('Forum Search - %s', $search);
+ }
+
+ $args = DI::args();
+ $pager = new Pager($args->getQueryString());
+
+ if ($localSearch && empty($results)) {
+ $pager->setItemsPerPage(80);
+ $results = Search::getContactsFromLocalDirectory($search, $type, $pager->getStart(), $pager->getItemsPerPage());
+ } elseif (strlen($config->get('system', 'directory')) && empty($results)) {
+ $results = Search::getContactsFromGlobalDirectory($search, $type, $pager->getPage());
+ $pager->setItemsPerPage($results->getItemsPage());
+ }
+
+ return self::printResult($results, $pager, $header);
+ }
+
+ /**
+ * Prints a human readable search result
+ *
+ * @param ResultList $results
+ * @param Pager $pager
+ * @param string $header
+ *
+ * @return string The result
+ * @throws HTTPException\InternalServerErrorException
+ * @throws \ImagickException
+ */
+ protected static function printResult(ResultList $results, Pager $pager, $header = '')
+ {
+ if ($results->getTotal() == 0) {
+ info(DI::l10n()->t('No matches'));
+ return '';
+ }
+
+ $id = 0;
+ $entries = [];
+ foreach ($results->getResults() as $result) {
+
+ // in case the result is a contact result, add a contact-specific entry
+ if ($result instanceof ContactResult) {
+
+ $alt_text = '';
+ $location = '';
+ $about = '';
+ $accountType = '';
+ $photo_menu = [];
+
+ // If We already know this contact then don't show the "connect" button
+ if ($result->getCid() > 0 || $result->getPCid() > 0) {
+ $connLink = "";
+ $connTxt = "";
+ $contact = Model\Contact::getById(
+ ($result->getCid() > 0) ? $result->getCid() : $result->getPCid()
+ );
+
+ if (!empty($contact)) {
+ $photo_menu = Model\Contact::photoMenu($contact);
+ $details = Contact::getContactTemplateVars($contact);
+ $alt_text = $details['alt_text'];
+ $location = $contact['location'];
+ $about = $contact['about'];
+ $accountType = Model\Contact::getAccountType($contact);
+ } else {
+ $photo_menu = [];
+ }
+ } else {
+ $connLink = DI::baseUrl()->get() . '/follow/?url=' . $result->getUrl();
+ $connTxt = DI::l10n()->t('Connect');
+
+ $photo_menu['profile'] = [DI::l10n()->t("View Profile"), Model\Contact::magicLink($result->getUrl())];
+ $photo_menu['follow'] = [DI::l10n()->t("Connect/Follow"), $connLink];
+ }
+
+ $photo = str_replace("http:///photo/", Search::getGlobalDirectory() . "/photo/", $result->getPhoto());
+
+ $entry = [
+ 'alt_text' => $alt_text,
+ 'url' => Model\Contact::magicLink($result->getUrl()),
+ 'itemurl' => $result->getItem(),
+ 'name' => $result->getName(),
+ 'thumb' => ProxyUtils::proxifyUrl($photo, false, ProxyUtils::SIZE_THUMB),
+ 'img_hover' => $result->getTags(),
+ 'conntxt' => $connTxt,
+ 'connlnk' => $connLink,
+ 'photo_menu' => $photo_menu,
+ 'details' => $location,
+ 'tags' => $result->getTags(),
+ 'about' => $about,
+ 'account_type' => $accountType,
+ 'network' => ContactSelector::networkToName($result->getNetwork(), $result->getUrl()),
+ 'id' => ++$id,
+ ];
+ $entries[] = $entry;
+ }
+ }
+
+ $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
+ return Renderer::replaceMacros($tpl, [
+ 'title' => $header,
+ '$contacts' => $entries,
+ '$paginate' => $pager->renderFull($results->getTotal()),
+ ]);
+ }
+}
+++ /dev/null
-<?php
-
-namespace Friendica\Module;
-
-use Friendica\BaseModule;
-use Friendica\Content\ContactSelector;
-use Friendica\Content\Pager;
-use Friendica\Core\Renderer;
-use Friendica\Core\Search;
-use Friendica\DI;
-use Friendica\Model;
-use Friendica\Network\HTTPException;
-use Friendica\Object\Search\ContactResult;
-use Friendica\Object\Search\ResultList;
-use Friendica\Util\Proxy as ProxyUtils;
-
-/**
- * Base class for search modules
- */
-class BaseSearchModule extends BaseModule
-{
- /**
- * Performs a contact search with an optional prefix
- *
- * @param string $search Search query
- * @param string $prefix A optional prefix (e.g. @ or !) for searching
- *
- * @return string
- * @throws HTTPException\InternalServerErrorException
- * @throws \ImagickException
- */
- public static function performContactSearch($search, $prefix = '')
- {
- $a = DI::app();
- $config = DI::config();
-
- $type = Search::TYPE_ALL;
-
- $localSearch = $config->get('system', 'poco_local_search');
-
- $search = $prefix . $search;
-
- if (!$search) {
- return '';
- }
-
- $header = '';
-
- if (strpos($search, '@') === 0) {
- $search = substr($search, 1);
- $type = Search::TYPE_PEOPLE;
- $header = DI::l10n()->t('People Search - %s', $search);
-
- if (strrpos($search, '@') > 0) {
- $results = Search::getContactsFromProbe($search);
- }
- }
-
- if (strpos($search, '!') === 0) {
- $search = substr($search, 1);
- $type = Search::TYPE_FORUM;
- $header = DI::l10n()->t('Forum Search - %s', $search);
- }
-
- $args = DI::args();
- $pager = new Pager($args->getQueryString());
-
- if ($localSearch && empty($results)) {
- $pager->setItemsPerPage(80);
- $results = Search::getContactsFromLocalDirectory($search, $type, $pager->getStart(), $pager->getItemsPerPage());
- } elseif (strlen($config->get('system', 'directory')) && empty($results)) {
- $results = Search::getContactsFromGlobalDirectory($search, $type, $pager->getPage());
- $pager->setItemsPerPage($results->getItemsPage());
- }
-
- return self::printResult($results, $pager, $header);
- }
-
- /**
- * Prints a human readable search result
- *
- * @param ResultList $results
- * @param Pager $pager
- * @param string $header
- *
- * @return string The result
- * @throws HTTPException\InternalServerErrorException
- * @throws \ImagickException
- */
- protected static function printResult(ResultList $results, Pager $pager, $header = '')
- {
- if ($results->getTotal() == 0) {
- info(DI::l10n()->t('No matches'));
- return '';
- }
-
- $id = 0;
- $entries = [];
- foreach ($results->getResults() as $result) {
-
- // in case the result is a contact result, add a contact-specific entry
- if ($result instanceof ContactResult) {
-
- $alt_text = '';
- $location = '';
- $about = '';
- $accountType = '';
- $photo_menu = [];
-
- // If We already know this contact then don't show the "connect" button
- if ($result->getCid() > 0 || $result->getPCid() > 0) {
- $connLink = "";
- $connTxt = "";
- $contact = Model\Contact::getById(
- ($result->getCid() > 0) ? $result->getCid() : $result->getPCid()
- );
-
- if (!empty($contact)) {
- $photo_menu = Model\Contact::photoMenu($contact);
- $details = Contact::getContactTemplateVars($contact);
- $alt_text = $details['alt_text'];
- $location = $contact['location'];
- $about = $contact['about'];
- $accountType = Model\Contact::getAccountType($contact);
- } else {
- $photo_menu = [];
- }
- } else {
- $connLink = DI::baseUrl()->get() . '/follow/?url=' . $result->getUrl();
- $connTxt = DI::l10n()->t('Connect');
-
- $photo_menu['profile'] = [DI::l10n()->t("View Profile"), Model\Contact::magicLink($result->getUrl())];
- $photo_menu['follow'] = [DI::l10n()->t("Connect/Follow"), $connLink];
- }
-
- $photo = str_replace("http:///photo/", Search::getGlobalDirectory() . "/photo/", $result->getPhoto());
-
- $entry = [
- 'alt_text' => $alt_text,
- 'url' => Model\Contact::magicLink($result->getUrl()),
- 'itemurl' => $result->getItem(),
- 'name' => $result->getName(),
- 'thumb' => ProxyUtils::proxifyUrl($photo, false, ProxyUtils::SIZE_THUMB),
- 'img_hover' => $result->getTags(),
- 'conntxt' => $connTxt,
- 'connlnk' => $connLink,
- 'photo_menu' => $photo_menu,
- 'details' => $location,
- 'tags' => $result->getTags(),
- 'about' => $about,
- 'account_type' => $accountType,
- 'network' => ContactSelector::networkToName($result->getNetwork(), $result->getUrl()),
- 'id' => ++$id,
- ];
- $entries[] = $entry;
- }
- }
-
- $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
- return Renderer::replaceMacros($tpl, [
- 'title' => $header,
- '$contacts' => $entries,
- '$paginate' => $pager->renderFull($results->getTotal()),
- ]);
- }
-}
--- /dev/null
+<?php
+
+namespace Friendica\Module;
+
+use Friendica\BaseModule;
+use Friendica\Content\Feature;
+use Friendica\Core\Renderer;
+use Friendica\DI;
+
+class BaseSettings extends BaseModule
+{
+ public static function content(array $parameters = [])
+ {
+ $a = DI::app();
+
+ $tpl = Renderer::getMarkupTemplate('settings/head.tpl');
+ DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl, [
+ '$ispublic' => DI::l10n()->t('everybody')
+ ]);
+
+ $tabs = [];
+
+ $tabs[] = [
+ 'label' => DI::l10n()->t('Account'),
+ 'url' => 'settings',
+ 'selected' => (($a->argc == 1) && ($a->argv[0] === 'settings') ? 'active' : ''),
+ 'accesskey' => 'o',
+ ];
+
+ $tabs[] = [
+ 'label' => DI::l10n()->t('Two-factor authentication'),
+ 'url' => 'settings/2fa',
+ 'selected' => (($a->argc > 1) && ($a->argv[1] === '2fa') ? 'active' : ''),
+ 'accesskey' => 'o',
+ ];
+
+ $tabs[] = [
+ 'label' => DI::l10n()->t('Profile'),
+ 'url' => 'settings/profile',
+ 'selected' => (($a->argc > 1) && ($a->argv[1] === 'profile') ? 'active' : ''),
+ 'accesskey' => 'p',
+ ];
+
+ if (Feature::get()) {
+ $tabs[] = [
+ 'label' => DI::l10n()->t('Additional features'),
+ 'url' => 'settings/features',
+ 'selected' => (($a->argc > 1) && ($a->argv[1] === 'features') ? 'active' : ''),
+ 'accesskey' => 't',
+ ];
+ }
+
+ $tabs[] = [
+ 'label' => DI::l10n()->t('Display'),
+ 'url' => 'settings/display',
+ 'selected' => (($a->argc > 1) && ($a->argv[1] === 'display') ? 'active' : ''),
+ 'accesskey' => 'i',
+ ];
+
+ $tabs[] = [
+ 'label' => DI::l10n()->t('Social Networks'),
+ 'url' => 'settings/connectors',
+ 'selected' => (($a->argc > 1) && ($a->argv[1] === 'connectors') ? 'active' : ''),
+ 'accesskey' => 'w',
+ ];
+
+ $tabs[] = [
+ 'label' => DI::l10n()->t('Addons'),
+ 'url' => 'settings/addon',
+ 'selected' => (($a->argc > 1) && ($a->argv[1] === 'addon') ? 'active' : ''),
+ 'accesskey' => 'l',
+ ];
+
+ $tabs[] = [
+ 'label' => DI::l10n()->t('Delegations'),
+ 'url' => 'settings/delegation',
+ 'selected' => (($a->argc > 1) && ($a->argv[1] === 'delegation') ? 'active' : ''),
+ 'accesskey' => 'd',
+ ];
+
+ $tabs[] = [
+ 'label' => DI::l10n()->t('Connected apps'),
+ 'url' => 'settings/oauth',
+ 'selected' => (($a->argc > 1) && ($a->argv[1] === 'oauth') ? 'active' : ''),
+ 'accesskey' => 'b',
+ ];
+
+ $tabs[] = [
+ 'label' => DI::l10n()->t('Export personal data'),
+ 'url' => 'settings/userexport',
+ 'selected' => (($a->argc > 1) && ($a->argv[1] === 'userexport') ? 'active' : ''),
+ 'accesskey' => 'e',
+ ];
+
+ $tabs[] = [
+ 'label' => DI::l10n()->t('Remove account'),
+ 'url' => 'removeme',
+ 'selected' => (($a->argc == 1) && ($a->argv[0] === 'removeme') ? 'active' : ''),
+ 'accesskey' => 'r',
+ ];
+
+
+ $tabtpl = Renderer::getMarkupTemplate("generic_links_widget.tpl");
+ DI::page()['aside'] = Renderer::replaceMacros($tabtpl, [
+ '$title' => DI::l10n()->t('Settings'),
+ '$class' => 'settings-widget',
+ '$items' => $tabs,
+ ]);
+ }
+}
+++ /dev/null
-<?php
-
-namespace Friendica\Module;
-
-use Friendica\BaseModule;
-use Friendica\Content\Feature;
-use Friendica\Core\Renderer;
-use Friendica\DI;
-
-class BaseSettingsModule extends BaseModule
-{
- public static function content(array $parameters = [])
- {
- $a = DI::app();
-
- $tpl = Renderer::getMarkupTemplate('settings/head.tpl');
- DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl, [
- '$ispublic' => DI::l10n()->t('everybody')
- ]);
-
- $tabs = [];
-
- $tabs[] = [
- 'label' => DI::l10n()->t('Account'),
- 'url' => 'settings',
- 'selected' => (($a->argc == 1) && ($a->argv[0] === 'settings') ? 'active' : ''),
- 'accesskey' => 'o',
- ];
-
- $tabs[] = [
- 'label' => DI::l10n()->t('Two-factor authentication'),
- 'url' => 'settings/2fa',
- 'selected' => (($a->argc > 1) && ($a->argv[1] === '2fa') ? 'active' : ''),
- 'accesskey' => 'o',
- ];
-
- $tabs[] = [
- 'label' => DI::l10n()->t('Profile'),
- 'url' => 'settings/profile',
- 'selected' => (($a->argc > 1) && ($a->argv[1] === 'profile') ? 'active' : ''),
- 'accesskey' => 'p',
- ];
-
- if (Feature::get()) {
- $tabs[] = [
- 'label' => DI::l10n()->t('Additional features'),
- 'url' => 'settings/features',
- 'selected' => (($a->argc > 1) && ($a->argv[1] === 'features') ? 'active' : ''),
- 'accesskey' => 't',
- ];
- }
-
- $tabs[] = [
- 'label' => DI::l10n()->t('Display'),
- 'url' => 'settings/display',
- 'selected' => (($a->argc > 1) && ($a->argv[1] === 'display') ? 'active' : ''),
- 'accesskey' => 'i',
- ];
-
- $tabs[] = [
- 'label' => DI::l10n()->t('Social Networks'),
- 'url' => 'settings/connectors',
- 'selected' => (($a->argc > 1) && ($a->argv[1] === 'connectors') ? 'active' : ''),
- 'accesskey' => 'w',
- ];
-
- $tabs[] = [
- 'label' => DI::l10n()->t('Addons'),
- 'url' => 'settings/addon',
- 'selected' => (($a->argc > 1) && ($a->argv[1] === 'addon') ? 'active' : ''),
- 'accesskey' => 'l',
- ];
-
- $tabs[] = [
- 'label' => DI::l10n()->t('Delegations'),
- 'url' => 'settings/delegation',
- 'selected' => (($a->argc > 1) && ($a->argv[1] === 'delegation') ? 'active' : ''),
- 'accesskey' => 'd',
- ];
-
- $tabs[] = [
- 'label' => DI::l10n()->t('Connected apps'),
- 'url' => 'settings/oauth',
- 'selected' => (($a->argc > 1) && ($a->argv[1] === 'oauth') ? 'active' : ''),
- 'accesskey' => 'b',
- ];
-
- $tabs[] = [
- 'label' => DI::l10n()->t('Export personal data'),
- 'url' => 'settings/userexport',
- 'selected' => (($a->argc > 1) && ($a->argv[1] === 'userexport') ? 'active' : ''),
- 'accesskey' => 'e',
- ];
-
- $tabs[] = [
- 'label' => DI::l10n()->t('Remove account'),
- 'url' => 'removeme',
- 'selected' => (($a->argc == 1) && ($a->argv[0] === 'removeme') ? 'active' : ''),
- 'accesskey' => 'r',
- ];
-
-
- $tabtpl = Renderer::getMarkupTemplate("generic_links_widget.tpl");
- DI::page()['aside'] = Renderer::replaceMacros($tabtpl, [
- '$title' => DI::l10n()->t('Settings'),
- '$class' => 'settings-widget',
- '$items' => $tabs,
- ]);
- }
-}
// @TODO: Replace with parameter from router
if (DI::args()->get(1) === 'mark' && DI::args()->get(2) === 'all') {
try {
- $success = DI::notify()->setAllSeen();
- }catch (\Exception $e) {
+ $success = DI::notify()->setSeen();
+ } catch (\Exception $e) {
DI::logger()->warning('set all seen failed.', ['exception' => $e]);
$success = false;
}
if ($request_id) {
try {
- $notification = DI::notify()->getByID($request_id);
- $notification->setSeen();
+ $notify = DI::notify()->getByID($request_id);
+ DI::notify()->setSeen(true, $notify);
- if (!empty($notification->link)) {
- System::externalRedirect($notification->link);
+ if (!empty($notify->link)) {
+ System::externalRedirect($notify->link);
}
} catch (HTTPException\NotFoundException $e) {
DI::baseUrl()->redirect('notifications/system');
}
}
-
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 = [])
{
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 = [])
{
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 = [])
{
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 = [])
{
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 = [])
{
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 = [])
{
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;
/**
*
* @package Friendica\Module\TwoFactor
*/
-class AppSpecific extends BaseSettingsModule
+class AppSpecific extends BaseSettings
{
private static $appSpecificPassword = null;
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 = [])
{
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;
/**
*
* @package Friendica\Module\TwoFactor
*/
-class Recovery extends BaseSettingsModule
+class Recovery extends BaseSettings
{
public static function init(array $parameters = [])
{
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;
*
* @package Friendica\Module\TwoFactor\Settings
*/
-class Verify extends BaseSettingsModule
+class Verify extends BaseSettings
{
public static function init(array $parameters = [])
{
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.
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;
* @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'];
// 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'];
/**
* Class Field
*
- * @see https://docs.joinmastodon.org/api/entities/#field
+ * @see https://docs.joinmastodon.org/entities/field/
*/
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;
+ }
}
namespace Friendica\Object\Api\Mastodon;
use Friendica\App\BaseURL;
+use Friendica\Collection\Api\Mastodon\Fields;
/**
* Virtual entity to separate Accounts from Follow Requests.
*/
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;
}
use Friendica\Core\Hook;
use Friendica\Model;
use Friendica\Collection;
+use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Network\HTTPException\NotFoundException;
use Friendica\Util\DateTimeFormat;
}
/**
- * {@inheritDoc}
+ * Set seen state of notifications of the local_user()
+ *
+ * @param bool $seen optional true or false. default true
+ * @param Model\Notify $notify optional a notify, which should be set seen (including his parents)
*
* @return bool true on success, false on error
+ *
* @throws Exception
*/
- public function setAllSeen(bool $seen = true)
+ public function setSeen(bool $seen = true, Model\Notify $notify = null)
{
- return $this->dba->update('notify', ['seen' => $seen], ['uid' => local_user()]);
+ if (empty($notify)) {
+ $conditions = ['uid' => local_user()];
+ } else {
+ $conditions = ['(`link` = ? OR (`parent` != 0 AND `parent` = ? AND `otype` = ?)) AND `uid` = ?',
+ $notify->link,
+ $notify->parent,
+ $notify->otype,
+ local_user()];
+ }
+
+ return $this->dba->update('notify', ['seen' => $seen], $conditions);
}
/**
*
* @return Model\Notify|false
*
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ * @throws InternalServerErrorException
* @throws Exception
*/
public function insert(array $fields)
{
- $fields['date'] = DateTimeFormat::utcNow();
+ $fields['date'] = DateTimeFormat::utcNow();
Hook::callAll('enotify_store', $fields);
'/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' => [
use Friendica\Model\Contact;
use Friendica\Network\HTTPException;
use Friendica\Test\Util\Database\StaticDatabase;
+use Friendica\Util\Temporal;
use Monolog\Handler\TestHandler;
require_once __DIR__ . '/../../include/api.php';
$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.
*
$this->app->argv = ['api', 'friendica', 'notification'];
$this->app->argc = count($this->app->argv);
$result = api_friendica_notification('xml');
+ $dateRel = Temporal::getRelativeDate('2020-01-01 12:12:02');
$assertXml=<<<XML
<?xml version="1.0"?>
<notes>
- <note id="1" hash="" type="8" name="Reply to" url="http://localhost/display/1" photo="http://localhost/" date="2020-01-01 12:12:02" msg="A test reply from an item" uid="42" link="http://localhost/notification/1" iid="4" parent="0" seen="0" verb="" otype="item" name_cache="" msg_cache="A test reply from an item" timestamp="1577880722" date_rel="4 weeks ago" msg_html="A test reply from an item" msg_plain="A test reply from an item"/>
+ <note id="1" hash="" type="8" name="Reply to" url="http://localhost/display/1" photo="http://localhost/" date="2020-01-01 12:12:02" msg="A test reply from an item" uid="42" link="http://localhost/notification/1" iid="4" parent="0" seen="0" verb="" otype="item" name_cache="" msg_cache="A test reply from an item" timestamp="1577880722" date_rel="{$dateRel}" msg_html="A test reply from an item" msg_plain="A test reply from an item"/>
</notes>
XML;
$this->assertXmlStringEqualsXmlString($assertXml, $result);
$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.
*