Merge remote-tracking branch 'upstream/develop' into app-user2

This commit is contained in:
Michael 2021-08-09 15:32:32 +00:00
commit 4495e83eca
36 changed files with 446 additions and 312 deletions

View file

@ -94,6 +94,7 @@ class VCard
'$url' => Contact::magicLinkByContact($contact, $contact['url']),
'$about' => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['about'] ?? ''),
'$xmpp' => DI::l10n()->t('XMPP:'),
'$matrix' => DI::l10n()->t('Matrix:'),
'$location' => DI::l10n()->t('Location:'),
'$network_link' => $network_link,
'$network_avatar' => $network_avatar,

View file

@ -676,7 +676,7 @@ class Contact
public static function updateSelfFromUserID($uid, $update_avatar = false)
{
$fields = ['id', 'name', 'nick', 'location', 'about', 'keywords', 'avatar', 'prvkey', 'pubkey',
'xmpp', 'contact-type', 'forum', 'prv', 'avatar-date', 'url', 'nurl', 'unsearchable',
'xmpp', 'matrix', 'contact-type', 'forum', 'prv', 'avatar-date', 'url', 'nurl', 'unsearchable',
'photo', 'thumb', 'micro', 'addr', 'request', 'notify', 'poll', 'confirm', 'poco', 'network'];
$self = DBA::selectFirst('contact', $fields, ['uid' => $uid, 'self' => true]);
if (!DBA::isResult($self)) {
@ -690,7 +690,7 @@ class Contact
}
$fields = ['name', 'photo', 'thumb', 'about', 'address', 'locality', 'region',
'country-name', 'pub_keywords', 'xmpp', 'net-publish'];
'country-name', 'pub_keywords', 'xmpp', 'matrix', 'net-publish'];
$profile = DBA::selectFirst('profile', $fields, ['uid' => $uid]);
if (!DBA::isResult($profile)) {
return false;
@ -702,7 +702,7 @@ class Contact
'avatar-date' => $self['avatar-date'], 'location' => Profile::formatLocation($profile),
'about' => $profile['about'], 'keywords' => $profile['pub_keywords'],
'contact-type' => $user['account-type'], 'prvkey' => $user['prvkey'],
'pubkey' => $user['pubkey'], 'xmpp' => $profile['xmpp'], 'network' => Protocol::DFRN];
'pubkey' => $user['pubkey'], 'xmpp' => $profile['xmpp'], 'matrix' => $profile['matrix'], 'network' => Protocol::DFRN];
// it seems as if ported accounts can have wrong values, so we make sure that now everything is fine.
$fields['url'] = DI::baseUrl() . '/profile/' . $user['nickname'];
@ -2064,11 +2064,11 @@ class Contact
*/
// These fields aren't updated by this routine:
// 'xmpp', 'sensitive'
// 'sensitive'
$fields = ['uid', 'uri-id', 'avatar', 'header', 'name', 'nick', 'location', 'keywords', 'about', 'subscribe',
'manually-approve', 'unsearchable', 'url', 'addr', 'batch', 'notify', 'poll', 'request', 'confirm', 'poco',
'network', 'alias', 'baseurl', 'gsid', 'forum', 'prv', 'contact-type', 'pubkey', 'last-item'];
'network', 'alias', 'baseurl', 'gsid', 'forum', 'prv', 'contact-type', 'pubkey', 'last-item', 'xmpp', 'matrix'];
$contact = DBA::selectFirst('contact', $fields, ['id' => $id]);
if (!DBA::isResult($contact)) {
return false;

View file

@ -706,7 +706,7 @@ class Item
return GRAVITY_UNKNOWN; // Should not happen
}
public static function insert($item, $notify = false, $dontcache = false)
public static function insert(array $item, bool $notify = false, bool $post_local = true)
{
$orig_item = $item;
@ -931,7 +931,7 @@ class Item
$item["private"] = self::PRIVATE;
}
if ($notify) {
if ($notify && $post_local) {
$item['edit'] = false;
$item['parent'] = $parent_id;
@ -953,7 +953,7 @@ class Item
unset($_SESSION['authenticated']);
unset($_SESSION['uid']);
}
} else {
} elseif (!$notify) {
Hook::callAll('post_remote', $item);
}
@ -1141,15 +1141,13 @@ class Item
return 0;
}
if (!$dontcache) {
if ($notify) {
if (!\Friendica\Content\Feature::isEnabled($posted_item['uid'], 'explicit_mentions') && ($posted_item['gravity'] == GRAVITY_COMMENT)) {
Tag::createImplicitMentions($posted_item['uri-id'], $posted_item['thr-parent-id']);
}
Hook::callAll('post_local_end', $posted_item);
} else {
Hook::callAll('post_remote_end', $posted_item);
if ($notify) {
if (!\Friendica\Content\Feature::isEnabled($posted_item['uid'], 'explicit_mentions') && ($posted_item['gravity'] == GRAVITY_COMMENT)) {
Tag::createImplicitMentions($posted_item['uri-id'], $posted_item['thr-parent-id']);
}
Hook::callAll('post_local_end', $posted_item);
} else {
Hook::callAll('post_remote_end', $posted_item);
}
if ($posted_item['gravity'] === GRAVITY_PARENT) {
@ -1465,7 +1463,7 @@ class Item
}
}
$distributed = self::insert($item, $notify, true);
$distributed = self::insert($item, $notify);
if (!$distributed) {
Logger::info("Distributed item wasn't stored", ['uri-id' => $item['uri-id'], 'user' => $uid]);
@ -1534,7 +1532,7 @@ class Item
$item['contact-id'] = $item['author-id'];
}
$public_shadow = self::insert($item, false, true);
$public_shadow = self::insert($item);
Logger::info('Stored public shadow', ['thread' => $itemid, 'id' => $public_shadow]);
}
@ -1593,7 +1591,7 @@ class Item
unset($item['post-reason']);
$item['contact-id'] = Contact::getIdForURL($item['author-link']);
$public_shadow = self::insert($item, false, true);
$public_shadow = self::insert($item);
Logger::info('Stored public shadow', ['uri-id' => $item['uri-id'], 'id' => $public_shadow]);

View file

@ -33,19 +33,36 @@ use Friendica\Util\DateTimeFormat;
class Delayed
{
/**
* The content of the post is posted as is. Connector settings are using the default settings.
* This is used for automated scheduled posts via feeds or from the API.
*/
const PREPARED = 0;
/**
* The content is posted like a manual post. Means some processing of body will be done.
* Also it is posted with default permissions and default connector settings.
* This is used for mirrored connector posts.
*/
const UNPREPARED = 1;
/**
* Like PREPARED, but additionally the connector settings can differ.
* This is used when manually publishing scheduled posts.
*/
const PREPARED_NO_HOOK = 2;
/**
* Insert a new delayed post
*
* @param string $uri
* @param array $item
* @param integer $notify
* @param bool $unprepared
* @param string $delayed
* @param array $taglist
* @param array $attachments
* @return int ID of the created delayed post entry
* @param string $uri
* @param array $item
* @param int $notify
* @param int $preparation_mode
* @param string $delayed
* @param array $taglist
* @param array $attachments
* @return int ID of the created delayed post entry
*/
public static function add(string $uri, array $item, int $notify = 0, bool $unprepared = false, string $delayed = '', array $taglist = [], array $attachments = [])
public static function add(string $uri, array $item, int $notify = 0, int $preparation_mode = self::PREPARED, string $delayed = '', array $taglist = [], array $attachments = [])
{
if (empty($item['uid']) || self::exists($uri, $item['uid'])) {
Logger::notice('No uid or already found');
@ -63,7 +80,7 @@ class Delayed
Logger::notice('Adding post for delayed publishing', ['uid' => $item['uid'], 'delayed' => $delayed, 'uri' => $uri]);
$wid = Worker::add(['priority' => PRIORITY_HIGH, 'delayed' => $delayed], 'DelayedPublish', $item, $notify, $taglist, $attachments, $unprepared, $uri);
$wid = Worker::add(['priority' => PRIORITY_HIGH, 'delayed' => $delayed], 'DelayedPublish', $item, $notify, $taglist, $attachments, $preparation_mode, $uri);
if (!$wid) {
return 0;
}
@ -168,21 +185,21 @@ class Delayed
/**
* Publish a delayed post
*
* @param array $item
* @param integer $notify
* @param array $taglist
* @param array $attachments
* @param bool $unprepared
* @param array $item
* @param int $notify
* @param array $taglist
* @param array $attachments
* @param int $preparation_mode
* @param string $uri
* @return bool
*/
public static function publish(array $item, int $notify = 0, array $taglist = [], array $attachments = [], bool $unprepared = false, string $uri = '')
public static function publish(array $item, int $notify = 0, array $taglist = [], array $attachments = [], int $preparation_mode = self::PREPARED, string $uri = '')
{
if (!empty($attachments)) {
$item['attachments'] = $attachments;
}
if ($unprepared) {
if ($preparation_mode == self::UNPREPARED) {
$_SESSION['authenticated'] = true;
$_SESSION['uid'] = $item['uid'];
@ -209,7 +226,8 @@ class Delayed
return $id;
}
$id = Item::insert($item, $notify);
$id = Item::insert($item, $notify, $preparation_mode == self::PREPARED);
Logger::notice('Post stored', ['id' => $id, 'uid' => $item['uid'], 'cid' => $item['contact-id']]);

View file

@ -361,6 +361,7 @@ class Profile
$homepage = !empty($profile['homepage']) ? DI::l10n()->t('Homepage:') : false;
$about = !empty($profile['about']) ? DI::l10n()->t('About:') : false;
$xmpp = !empty($profile['xmpp']) ? DI::l10n()->t('XMPP:') : false;
$matrix = !empty($profile['matrix']) ? DI::l10n()->t('Matrix:') : false;
if ((!empty($profile['hidewall']) || $block) && !Session::isAuthenticated()) {
$location = $homepage = $about = false;
@ -439,6 +440,7 @@ class Profile
$o .= Renderer::replaceMacros($tpl, [
'$profile' => $p,
'$xmpp' => $xmpp,
'$matrix' => $matrix,
'$follow' => DI::l10n()->t('Follow'),
'$follow_link' => $follow_link,
'$unfollow' => DI::l10n()->t('Unfollow'),

View file

@ -186,7 +186,7 @@ class Statuses extends BaseApi
if (!empty($request['scheduled_at'])) {
$item['guid'] = Item::guid($item, true);
$item['uri'] = Item::newURI($item['uid'], $item['guid']);
$id = Post\Delayed::add($item['uri'], $item, PRIORITY_HIGH, false, $request['scheduled_at']);
$id = Post\Delayed::add($item['uri'], $item, PRIORITY_HIGH, Post\Delayed::PREPARED, $request['scheduled_at']);
if (empty($id)) {
DI::mstdnError()->InternalError();
}

View file

@ -607,6 +607,8 @@ class Contact extends BaseModule
'$location_label' => DI::l10n()->t('Location:'),
'$xmpp' => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['xmpp']),
'$xmpp_label' => DI::l10n()->t('XMPP:'),
'$matrix' => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['matrix']),
'$matrix_label' => DI::l10n()->t('Matrix:'),
'$about' => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['about'], BBCode::EXTERNAL),
'$about_label' => DI::l10n()->t('About:'),
'$keywords' => $contact['keywords'],

View file

@ -120,7 +120,7 @@ class NoScrape extends BaseModule
$json_info['last-activity'] = date('o-W', $last_active);
//These are optional fields.
$profile_fields = ['about', 'locality', 'region', 'postal-code', 'country-name'];
$profile_fields = ['about', 'locality', 'region', 'postal-code', 'country-name', 'xmpp', 'matrix'];
foreach ($profile_fields as $field) {
if (!empty($profile[$field])) {
$json_info["$field"] = $profile[$field];

View file

@ -176,6 +176,10 @@ class Profile extends BaseProfile
$basic_fields += self::buildField('xmpp', DI::l10n()->t('XMPP:'), $profile['xmpp']);
}
if ($profile['matrix']) {
$basic_fields += self::buildField('matrix', DI::l10n()->t('Matrix:'), $profile['matrix']);
}
if ($profile['homepage']) {
$basic_fields += self::buildField('homepage', DI::l10n()->t('Homepage:'), HTML::toLink($profile['homepage']));
}

View file

@ -92,6 +92,7 @@ class Index extends BaseSettings
$pub_keywords = self::cleanKeywords(Strings::escapeTags(trim($_POST['pub_keywords'])));
$prv_keywords = self::cleanKeywords(Strings::escapeTags(trim($_POST['prv_keywords'])));
$xmpp = Strings::escapeTags(trim($_POST['xmpp']));
$matrix = Strings::escapeTags(trim($_POST['matrix']));
$homepage = Strings::escapeTags(trim($_POST['homepage']));
if ((strpos($homepage, 'http') !== 0) && (strlen($homepage))) {
// neither http nor https in URL, add them
@ -120,6 +121,7 @@ class Index extends BaseSettings
'postal-code' => $postal_code,
'country-name' => $country_name,
'xmpp' => $xmpp,
'matrix' => $matrix,
'homepage' => $homepage,
'pub_keywords' => $pub_keywords,
'prv_keywords' => $prv_keywords,
@ -240,6 +242,7 @@ class Index extends BaseSettings
'$country_name' => ['country_name', DI::l10n()->t('Country:'), $profile['country-name']],
'$age' => ((intval($profile['dob'])) ? '(' . DI::l10n()->t('Age: ') . DI::l10n()->tt('%d year old', '%d years old', Temporal::getAgeByTimezone($profile['dob'], $profile['timezone'])) . ')' : ''),
'$xmpp' => ['xmpp', DI::l10n()->t('XMPP (Jabber) address:'), $profile['xmpp'], DI::l10n()->t('The XMPP address will be propagated to your contacts so that they can follow you.')],
'$matrix' => ['matrix', DI::l10n()->t('Matrix (Element) address:'), $profile['matrix'], DI::l10n()->t('The Matrix address will be published so that people can follow you there.')],
'$homepage' => ['homepage', DI::l10n()->t('Homepage URL:'), $profile['homepage']],
'$pub_keywords' => ['pub_keywords', DI::l10n()->t('Public Keywords:'), $profile['pub_keywords'], DI::l10n()->t('(Used for suggesting potential friends, can be seen by others)')],
'$prv_keywords' => ['prv_keywords', DI::l10n()->t('Private Keywords:'), $profile['prv_keywords'], DI::l10n()->t('(Used for searching profiles, never shown to others)')],

View file

@ -47,7 +47,7 @@ class Xrd extends BaseModule
}
$uri = urldecode(Strings::escapeTags(trim($_GET['uri'])));
if (($_SERVER['HTTP_ACCEPT'] ?? '') == 'application/jrd+json') {
if (strpos($_SERVER['HTTP_ACCEPT'] ?? '', 'application/jrd+json') !== false) {
$mode = 'json';
} else {
$mode = 'xml';
@ -58,7 +58,7 @@ class Xrd extends BaseModule
}
$uri = urldecode(Strings::escapeTags(trim($_GET['resource'])));
if (($_SERVER['HTTP_ACCEPT'] ?? '') == 'application/xrd+xml') {
if (strpos($_SERVER['HTTP_ACCEPT'] ?? '', 'application/xrd+xml') !== false) {
$mode = 'xml';
} else {
$mode = 'json';
@ -159,9 +159,6 @@ class Xrd extends BaseModule
{
$salmon_key = Salmon::salmonKey($owner['spubkey']);
header('Access-Control-Allow-Origin: *');
header('Content-type: application/json; charset=utf-8');
$json = [
'subject' => 'acct:' . $owner['addr'],
'aliases' => [
@ -235,8 +232,8 @@ class Xrd extends BaseModule
],
];
echo json_encode($json);
exit();
header('Access-Control-Allow-Origin: *');
System::jsonExit($json, 'application/jrd+json; charset=utf-8');
}
private static function printXML($alias, $baseURL, $user, $owner, $avatar)

View file

@ -89,8 +89,8 @@ class Probe
private static function rearrangeData($data)
{
$fields = ["name", "nick", "guid", "url", "addr", "alias", "photo", "header",
"account-type", "community", "keywords", "location", "about", "hide",
"batch", "notify", "poll", "request", "confirm", "subscribe", "poco",
"account-type", "community", "keywords", "location", "about", "xmpp", "matrix",
"hide", "batch", "notify", "poll", "request", "confirm", "subscribe", "poco",
"following", "followers", "inbox", "outbox", "sharedinbox",
"priority", "network", "pubkey", "manually-approve", "baseurl", "gsid"];
@ -1067,6 +1067,14 @@ class Probe
$data["about"] = $json["about"];
}
if (!empty($json["xmpp"])) {
$data["xmpp"] = $json["xmpp"];
}
if (!empty($json["matrix"])) {
$data["matrix"] = $json["matrix"];
}
if (!empty($json["key"])) {
$data["pubkey"] = $json["key"];
}
@ -2230,6 +2238,7 @@ class Probe
'header' => $profile['header'] ? Contact::getHeaderUrlForId($profile['id'], $profile['updated']) : '',
'account-type' => $profile['contact-type'], 'community' => ($profile['contact-type'] == User::ACCOUNT_TYPE_COMMUNITY),
'keywords' => $profile['keywords'], 'location' => $profile['location'], 'about' => $profile['about'],
'xmpp' => $profile['xmpp'], 'matrix' => $profile['matrix'],
'hide' => !$profile['net-publish'], 'batch' => '', 'notify' => $profile['notify'],
'poll' => $profile['poll'], 'request' => $profile['request'], 'confirm' => $profile['confirm'],
'subscribe' => $approfile['generator']['url'] . '/follow?url={uri}', 'poco' => $profile['poco'],

View file

@ -354,7 +354,7 @@ class Transmitter
$data['url'] = $owner['url'];
$data['manuallyApprovesFollowers'] = in_array($owner['page-flags'], [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_PRVGROUP]);
$data['discoverable'] = $owner['net-publish'];
$data['discoverable'] = (bool)$owner['net-publish'];
$data['publicKey'] = ['id' => $owner['url'] . '#main-key',
'owner' => $owner['url'],
'publicKeyPem' => $owner['pubkey']];

View file

@ -601,7 +601,7 @@ class Feed
}
$publish_at = date(DateTimeFormat::MYSQL, $publish_time);
if (Post\Delayed::add($posting['item']['uri'], $posting['item'], $posting['notify'], false, $publish_at, $posting['taglist'], $posting['attachments'])) {
if (Post\Delayed::add($posting['item']['uri'], $posting['item'], $posting['notify'], Post\Delayed::PREPARED, $publish_at, $posting['taglist'], $posting['attachments'])) {
DI::pConfig()->set($item['uid'], 'system', 'last_publish', $publish_time);
}
}

View file

@ -29,17 +29,17 @@ class DelayedPublish
/**
* Publish a post, used for delayed postings
*
* @param array $item
* @param integer $notify
* @param array $taglist
* @param array $attachments
* @param bool $unprepared
* @param array $item
* @param int $notify
* @param array $taglist
* @param array $attachments
* @param int $preparation_mode
* @param string $uri
* @return void
*/
public static function execute(array $item, int $notify = 0, array $taglist = [], array $attachments = [], bool $unprepared = false, string $uri = '')
public static function execute(array $item, int $notify = 0, array $taglist = [], array $attachments = [], int $preparation_mode = Post\Delayed::PREPARED, string $uri = '')
{
$id = Post\Delayed::publish($item, $notify, $taglist, $attachments, $unprepared, $uri);
Logger::notice('Post published', ['id' => $id, 'uid' => $item['uid'], 'notify' => $notify, 'unprepared' => $unprepared]);
$id = Post\Delayed::publish($item, $notify, $taglist, $attachments, $preparation_mode, $uri);
Logger::notice('Post published', ['id' => $id, 'uid' => $item['uid'], 'notify' => $notify, 'unprepared' => $preparation_mode]);
}
}