mirror of
https://github.com/friendica/friendica
synced 2025-04-27 06:30:12 +00:00
Fix code style
This commit is contained in:
parent
d4697a17a3
commit
0e59dba914
102 changed files with 3038 additions and 2764 deletions
|
@ -13,7 +13,6 @@ use Friendica\Core\Protocol;
|
|||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Network\Probe;
|
||||
use Friendica\Protocol\ActivityNamespace;
|
||||
|
@ -153,7 +152,7 @@ class APContact
|
|||
// Detect multiple fast repeating request to the same address
|
||||
// See https://github.com/friendica/friendica/issues/9303
|
||||
$cachekey = 'apcontact:' . ItemURI::getIdByURI($url);
|
||||
$result = DI::cache()->get($cachekey);
|
||||
$result = DI::cache()->get($cachekey);
|
||||
if (!is_null($result)) {
|
||||
DI::logger()->info('Multiple requests for the address', ['url' => $url, 'update' => $update, 'result' => $result]);
|
||||
if (!empty($fetched_contact)) {
|
||||
|
@ -165,7 +164,7 @@ class APContact
|
|||
|
||||
if (DI::baseUrl()->isLocalUrl($url) && ($local_uid = User::getIdForURL($url))) {
|
||||
try {
|
||||
$data = Transmitter::getProfile($local_uid);
|
||||
$data = Transmitter::getProfile($local_uid);
|
||||
$local_owner = User::getOwnerDataById($local_uid);
|
||||
} catch(HTTPException\NotFoundException $e) {
|
||||
$data = null;
|
||||
|
@ -177,11 +176,11 @@ class APContact
|
|||
|
||||
try {
|
||||
$curlResult = HTTPSignature::fetchRaw($url);
|
||||
$failed = empty($curlResult->getBodyString()) ||
|
||||
$failed = empty($curlResult->getBodyString()) ||
|
||||
(!$curlResult->isSuccess() && ($curlResult->getReturnCode() != 410));
|
||||
|
||||
if (!$failed) {
|
||||
$data = json_decode($curlResult->getBodyString(), true);
|
||||
if (!$failed) {
|
||||
$data = json_decode($curlResult->getBodyString(), true);
|
||||
$failed = empty($data) || !is_array($data);
|
||||
}
|
||||
|
||||
|
@ -206,13 +205,13 @@ class APContact
|
|||
return $fetched_contact;
|
||||
}
|
||||
|
||||
$apcontact['url'] = $compacted['@id'];
|
||||
$apcontact['uuid'] = JsonLD::fetchElement($compacted, 'diaspora:guid', '@value');
|
||||
$apcontact['type'] = str_replace('as:', '', JsonLD::fetchElement($compacted, '@type'));
|
||||
$apcontact['url'] = $compacted['@id'];
|
||||
$apcontact['uuid'] = JsonLD::fetchElement($compacted, 'diaspora:guid', '@value');
|
||||
$apcontact['type'] = str_replace('as:', '', JsonLD::fetchElement($compacted, '@type'));
|
||||
$apcontact['following'] = JsonLD::fetchElement($compacted, 'as:following', '@id');
|
||||
$apcontact['followers'] = JsonLD::fetchElement($compacted, 'as:followers', '@id');
|
||||
$apcontact['inbox'] = (JsonLD::fetchElement($compacted, 'ldp:inbox', '@id') ?? '');
|
||||
$apcontact['outbox'] = JsonLD::fetchElement($compacted, 'as:outbox', '@id');
|
||||
$apcontact['inbox'] = (JsonLD::fetchElement($compacted, 'ldp:inbox', '@id') ?? '');
|
||||
$apcontact['outbox'] = JsonLD::fetchElement($compacted, 'as:outbox', '@id');
|
||||
|
||||
$apcontact['sharedinbox'] = '';
|
||||
if (!empty($compacted['as:endpoints'])) {
|
||||
|
@ -303,12 +302,12 @@ class APContact
|
|||
}
|
||||
}
|
||||
|
||||
$apcontact['manually-approve'] = (int)JsonLD::fetchElement($compacted, 'as:manuallyApprovesFollowers');
|
||||
$apcontact['manually-approve'] = (int)JsonLD::fetchElement($compacted, 'as:manuallyApprovesFollowers');
|
||||
$apcontact['posting-restricted'] = (int)JsonLD::fetchElement($compacted, 'lemmy:postingRestrictedToMods');
|
||||
$apcontact['suspended'] = (int)JsonLD::fetchElement($compacted, 'toot:suspended');
|
||||
$apcontact['suspended'] = (int)JsonLD::fetchElement($compacted, 'toot:suspended');
|
||||
|
||||
if (!empty($compacted['as:generator'])) {
|
||||
$apcontact['baseurl'] = JsonLD::fetchElement($compacted['as:generator'], 'as:url', '@id');
|
||||
$apcontact['baseurl'] = JsonLD::fetchElement($compacted['as:generator'], 'as:url', '@id');
|
||||
$apcontact['generator'] = JsonLD::fetchElement($compacted['as:generator'], 'as:name', '@value');
|
||||
}
|
||||
|
||||
|
@ -348,7 +347,7 @@ class APContact
|
|||
if (!empty($local_owner)) {
|
||||
$statuses_count = self::getStatusesCount($local_owner);
|
||||
} else {
|
||||
$outbox = HTTPSignature::fetch($apcontact['outbox']);
|
||||
$outbox = HTTPSignature::fetch($apcontact['outbox']);
|
||||
$statuses_count = $outbox['totalItems'] ?? 0;
|
||||
}
|
||||
if (!empty($statuses_count)) {
|
||||
|
|
|
@ -23,7 +23,7 @@ use Friendica\Protocol\ActivityPub;
|
|||
class Circle
|
||||
{
|
||||
const FOLLOWERS = '~';
|
||||
const MUTUALS = '&';
|
||||
const MUTUALS = '&';
|
||||
|
||||
/**
|
||||
* Fetches circle record by user id and maybe includes deleted circles as well
|
||||
|
@ -163,7 +163,8 @@ class Circle
|
|||
*/
|
||||
public static function countUnseen(int $uid)
|
||||
{
|
||||
$stmt = DBA::p("SELECT `circle`.`id`, `circle`.`name`,
|
||||
$stmt = DBA::p(
|
||||
"SELECT `circle`.`id`, `circle`.`name`,
|
||||
(SELECT COUNT(*) FROM `post-user`
|
||||
WHERE `uid` = ?
|
||||
AND `unseen`
|
||||
|
@ -230,15 +231,15 @@ class Circle
|
|||
|
||||
if ($user['def_gid'] == $gid) {
|
||||
$user['def_gid'] = 0;
|
||||
$change = true;
|
||||
$change = true;
|
||||
}
|
||||
if (strpos($user['allow_gid'], '<' . $gid . '>') !== false) {
|
||||
$user['allow_gid'] = str_replace('<' . $gid . '>', '', $user['allow_gid']);
|
||||
$change = true;
|
||||
$change = true;
|
||||
}
|
||||
if (strpos($user['deny_gid'], '<' . $gid . '>') !== false) {
|
||||
$user['deny_gid'] = str_replace('<' . $gid . '>', '', $user['deny_gid']);
|
||||
$change = true;
|
||||
$change = true;
|
||||
}
|
||||
|
||||
if ($change) {
|
||||
|
@ -410,13 +411,13 @@ class Circle
|
|||
if ($key !== false) {
|
||||
if ($expand_followers) {
|
||||
$followers = Contact::selectToArray(['id'], [
|
||||
'uid' => $uid,
|
||||
'rel' => [Contact::FOLLOWER, Contact::FRIEND],
|
||||
'network' => $networks,
|
||||
'uid' => $uid,
|
||||
'rel' => [Contact::FOLLOWER, Contact::FRIEND],
|
||||
'network' => $networks,
|
||||
'contact-type' => [Contact::TYPE_UNKNOWN, Contact::TYPE_PERSON, Contact::TYPE_NEWS, Contact::TYPE_ORGANISATION],
|
||||
'archive' => false,
|
||||
'pending' => false,
|
||||
'blocked' => false,
|
||||
'archive' => false,
|
||||
'pending' => false,
|
||||
'blocked' => false,
|
||||
]);
|
||||
|
||||
foreach ($followers as $follower) {
|
||||
|
@ -431,13 +432,13 @@ class Circle
|
|||
$key = array_search(self::MUTUALS, $circle_ids);
|
||||
if ($key !== false) {
|
||||
$mutuals = Contact::selectToArray(['id'], [
|
||||
'uid' => $uid,
|
||||
'rel' => [Contact::FRIEND],
|
||||
'network' => $networks,
|
||||
'uid' => $uid,
|
||||
'rel' => [Contact::FRIEND],
|
||||
'network' => $networks,
|
||||
'contact-type' => [Contact::TYPE_UNKNOWN, Contact::TYPE_PERSON],
|
||||
'archive' => false,
|
||||
'pending' => false,
|
||||
'blocked' => false,
|
||||
'archive' => false,
|
||||
'pending' => false,
|
||||
'blocked' => false,
|
||||
]);
|
||||
|
||||
foreach ($mutuals as $mutual) {
|
||||
|
@ -478,8 +479,8 @@ class Circle
|
|||
{
|
||||
$display_circles = [
|
||||
[
|
||||
'name' => '',
|
||||
'id' => '0',
|
||||
'name' => '',
|
||||
'id' => '0',
|
||||
'selected' => ''
|
||||
]
|
||||
];
|
||||
|
@ -487,8 +488,8 @@ class Circle
|
|||
$stmt = DBA::select('group', [], ['deleted' => false, 'uid' => $uid, 'cid' => null], ['order' => ['name']]);
|
||||
while ($circle = DBA::fetch($stmt)) {
|
||||
$display_circles[] = [
|
||||
'name' => $circle['name'],
|
||||
'id' => $circle['id'],
|
||||
'name' => $circle['name'],
|
||||
'id' => $circle['id'],
|
||||
'selected' => $gid == $circle['id'] ? 'true' : ''
|
||||
];
|
||||
}
|
||||
|
@ -497,8 +498,8 @@ class Circle
|
|||
DI::logger()->info('Got circles', $display_circles);
|
||||
|
||||
$o = Renderer::replaceMacros(Renderer::getMarkupTemplate('circle_selection.tpl'), [
|
||||
'$id' => $id,
|
||||
'$label' => $label,
|
||||
'$id' => $id,
|
||||
'$label' => $label,
|
||||
'$circles' => $display_circles
|
||||
]);
|
||||
return $o;
|
||||
|
@ -526,10 +527,10 @@ class Circle
|
|||
|
||||
$display_circles = [
|
||||
[
|
||||
'text' => DI::l10n()->t('Everybody'),
|
||||
'id' => 0,
|
||||
'text' => DI::l10n()->t('Everybody'),
|
||||
'id' => 0,
|
||||
'selected' => (($circle_id === 'everyone') ? 'circle-selected' : ''),
|
||||
'href' => $every,
|
||||
'href' => $every,
|
||||
]
|
||||
];
|
||||
|
||||
|
@ -544,7 +545,7 @@ class Circle
|
|||
|
||||
if ($editmode == 'full') {
|
||||
$circleedit = [
|
||||
'href' => 'circle/' . $circle['id'],
|
||||
'href' => 'circle/' . $circle['id'],
|
||||
'title' => DI::l10n()->t('edit'),
|
||||
];
|
||||
} else {
|
||||
|
@ -552,23 +553,23 @@ class Circle
|
|||
}
|
||||
|
||||
if ($each == 'circle') {
|
||||
$networks = Widget::unavailableNetworks();
|
||||
$networks = Widget::unavailableNetworks();
|
||||
$sql_values = array_merge([$circle['id']], $networks);
|
||||
$condition = ["`circle-id` = ? AND NOT `contact-network` IN (" . substr(str_repeat("?, ", count($networks)), 0, -2) . ")"];
|
||||
$condition = array_merge($condition, $sql_values);
|
||||
$condition = ["`circle-id` = ? AND NOT `contact-network` IN (" . substr(str_repeat("?, ", count($networks)), 0, -2) . ")"];
|
||||
$condition = array_merge($condition, $sql_values);
|
||||
|
||||
$count = DBA::count('circle-member-view', $condition);
|
||||
$count = DBA::count('circle-member-view', $condition);
|
||||
$circle_name = sprintf('%s (%d)', $circle['name'], $count);
|
||||
} else {
|
||||
$circle_name = $circle['name'];
|
||||
}
|
||||
|
||||
$display_circles[] = [
|
||||
'id' => $circle['id'],
|
||||
'cid' => $cid,
|
||||
'text' => $circle_name,
|
||||
'href' => $each . '/' . $circle['id'],
|
||||
'edit' => $circleedit,
|
||||
'id' => $circle['id'],
|
||||
'cid' => $cid,
|
||||
'text' => $circle_name,
|
||||
'href' => $each . '/' . $circle['id'],
|
||||
'edit' => $circleedit,
|
||||
'selected' => $selected,
|
||||
'ismember' => in_array($circle['id'], $member_of),
|
||||
];
|
||||
|
@ -581,18 +582,18 @@ class Circle
|
|||
}
|
||||
|
||||
$tpl = Renderer::getMarkupTemplate('circle_side.tpl');
|
||||
$o = Renderer::replaceMacros($tpl, [
|
||||
'$add' => DI::l10n()->t('add'),
|
||||
'$title' => DI::l10n()->t('Circles'),
|
||||
'$circles' => $display_circles,
|
||||
'$new_circle' => $editmode == 'extended' || $editmode == 'full' ? 1 : '',
|
||||
'$circle_page' => 'circle/',
|
||||
'$edittext' => DI::l10n()->t('Edit circle'),
|
||||
'$uncircled' => $every === 'contact' ? DI::l10n()->t('Contacts not in any circle') : '',
|
||||
'$uncircled_selected' => (($circle_id === 'none') ? 'circle-selected' : ''),
|
||||
'$createtext' => DI::l10n()->t('Create a new circle'),
|
||||
'$create_circle' => DI::l10n()->t('Circle Name: '),
|
||||
'$edit_circles_text' => DI::l10n()->t('Edit circles'),
|
||||
$o = Renderer::replaceMacros($tpl, [
|
||||
'$add' => DI::l10n()->t('add'),
|
||||
'$title' => DI::l10n()->t('Circles'),
|
||||
'$circles' => $display_circles,
|
||||
'$new_circle' => $editmode == 'extended' || $editmode == 'full' ? 1 : '',
|
||||
'$circle_page' => 'circle/',
|
||||
'$edittext' => DI::l10n()->t('Edit circle'),
|
||||
'$uncircled' => $every === 'contact' ? DI::l10n()->t('Contacts not in any circle') : '',
|
||||
'$uncircled_selected' => (($circle_id === 'none') ? 'circle-selected' : ''),
|
||||
'$createtext' => DI::l10n()->t('Create a new circle'),
|
||||
'$create_circle' => DI::l10n()->t('Circle Name: '),
|
||||
'$edit_circles_text' => DI::l10n()->t('Edit circles'),
|
||||
'$form_security_token' => BaseModule::getFormSecurityToken('circle_edit'),
|
||||
]);
|
||||
|
||||
|
|
|
@ -74,12 +74,12 @@ class Contact
|
|||
* This will only be assigned to contacts, not to user accounts
|
||||
* @{
|
||||
*/
|
||||
const TYPE_UNKNOWN = -1;
|
||||
const TYPE_PERSON = User::ACCOUNT_TYPE_PERSON;
|
||||
const TYPE_UNKNOWN = -1;
|
||||
const TYPE_PERSON = User::ACCOUNT_TYPE_PERSON;
|
||||
const TYPE_ORGANISATION = User::ACCOUNT_TYPE_ORGANISATION;
|
||||
const TYPE_NEWS = User::ACCOUNT_TYPE_NEWS;
|
||||
const TYPE_COMMUNITY = User::ACCOUNT_TYPE_COMMUNITY;
|
||||
const TYPE_RELAY = User::ACCOUNT_TYPE_RELAY;
|
||||
const TYPE_NEWS = User::ACCOUNT_TYPE_NEWS;
|
||||
const TYPE_COMMUNITY = User::ACCOUNT_TYPE_COMMUNITY;
|
||||
const TYPE_RELAY = User::ACCOUNT_TYPE_RELAY;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
@ -335,7 +335,7 @@ class Contact
|
|||
if (!empty($fields)) {
|
||||
foreach (['id', 'next-update', 'network', 'local-data'] as $internal) {
|
||||
if (!in_array($internal, $fields)) {
|
||||
$fields[] = $internal;
|
||||
$fields[] = $internal;
|
||||
$removal[] = $internal;
|
||||
}
|
||||
}
|
||||
|
@ -353,9 +353,9 @@ class Contact
|
|||
// Then the alias (which could be anything)
|
||||
if (!DBA::isResult($contact)) {
|
||||
// The link could be provided as http although we stored it as https
|
||||
$ssl_url = str_replace('http://', 'https://', $url);
|
||||
$ssl_url = str_replace('http://', 'https://', $url);
|
||||
$condition = ['`alias` IN (?, ?, ?) AND `uid` = ? AND NOT `deleted`', $url, Strings::normaliseLink($url), $ssl_url, $uid];
|
||||
$contact = DBA::selectFirst('contact', $fields, $condition, $options);
|
||||
$contact = DBA::selectFirst('contact', $fields, $condition, $options);
|
||||
}
|
||||
|
||||
if (!DBA::isResult($contact)) {
|
||||
|
@ -837,7 +837,7 @@ class Contact
|
|||
}
|
||||
|
||||
$fields = ['uid', 'username', 'nickname', 'page-flags', 'account-type', 'prvkey', 'pubkey'];
|
||||
$user = DBA::selectFirst('user', $fields, ['uid' => $uid, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]);
|
||||
$user = DBA::selectFirst('user', $fields, ['uid' => $uid, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]);
|
||||
if (!DBA::isResult($user)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -868,11 +868,11 @@ class Contact
|
|||
'network' => Protocol::DFRN,
|
||||
'url' => $url,
|
||||
// it seems as if ported accounts can have wrong values, so we make sure that now everything is fine.
|
||||
'nurl' => Strings::normaliseLink($url),
|
||||
'uri-id' => ItemURI::getIdByURI($url),
|
||||
'addr' => $user['nickname'] . '@' . substr(DI::baseUrl(), strpos(DI::baseUrl(), '://') + 3),
|
||||
'notify' => DI::baseUrl() . '/dfrn_notify/' . $user['nickname'],
|
||||
'poll' => DI::baseUrl() . '/feed/' . $user['nickname'],
|
||||
'nurl' => Strings::normaliseLink($url),
|
||||
'uri-id' => ItemURI::getIdByURI($url),
|
||||
'addr' => $user['nickname'] . '@' . substr(DI::baseUrl(), strpos(DI::baseUrl(), '://') + 3),
|
||||
'notify' => DI::baseUrl() . '/dfrn_notify/' . $user['nickname'],
|
||||
'poll' => DI::baseUrl() . '/feed/' . $user['nickname'],
|
||||
];
|
||||
|
||||
$avatar = Photo::selectFirst(['resource-id', 'type'], ['uid' => $uid, 'profile' => true]);
|
||||
|
@ -897,14 +897,14 @@ class Contact
|
|||
$fields['micro'] = self::getDefaultAvatar($fields, Proxy::SIZE_MICRO);
|
||||
}
|
||||
|
||||
$fields['avatar'] = User::getAvatarUrl($user);
|
||||
$fields['header'] = User::getBannerUrl($user);
|
||||
$fields['forum'] = in_array($user['page-flags'], [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_COMM_MAN]);
|
||||
$fields['prv'] = $user['page-flags'] == User::PAGE_FLAGS_PRVGROUP;
|
||||
$fields['unsearchable'] = !$profile['net-publish'];
|
||||
$fields['avatar'] = User::getAvatarUrl($user);
|
||||
$fields['header'] = User::getBannerUrl($user);
|
||||
$fields['forum'] = in_array($user['page-flags'], [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_COMM_MAN]);
|
||||
$fields['prv'] = $user['page-flags'] == User::PAGE_FLAGS_PRVGROUP;
|
||||
$fields['unsearchable'] = !$profile['net-publish'];
|
||||
$fields['manually-approve'] = in_array($user['page-flags'], [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_PRVGROUP, User::PAGE_FLAGS_COMM_MAN]);
|
||||
$fields['baseurl'] = DI::baseUrl();
|
||||
$fields['gsid'] = GServer::getID($fields['baseurl'], true);
|
||||
$fields['baseurl'] = DI::baseUrl();
|
||||
$fields['gsid'] = GServer::getID($fields['baseurl'], true);
|
||||
|
||||
$update = false;
|
||||
|
||||
|
@ -1083,7 +1083,7 @@ class Contact
|
|||
public static function markForArchival(array $contact)
|
||||
{
|
||||
if ((!isset($contact['uri-id']) || !isset($contact['url']) || !isset($contact['archive']) || !isset($contact['self']) || !isset($contact['term-date'])) && !empty($contact['id'])) {
|
||||
$fields = ['id', 'uri-id', 'url', 'archive', 'self', 'term-date'];
|
||||
$fields = ['id', 'uri-id', 'url', 'archive', 'self', 'term-date'];
|
||||
$contact = DBA::selectFirst('contact', $fields, ['id' => $contact['id']]);
|
||||
if (!DBA::isResult($contact)) {
|
||||
return;
|
||||
|
@ -1135,7 +1135,7 @@ class Contact
|
|||
{
|
||||
// Always unarchive the relay contact entry
|
||||
if (!empty($contact['batch']) && !empty($contact['term-date']) && ($contact['term-date'] > DBA::NULL_DATETIME)) {
|
||||
$fields = ['failed' => false, 'term-date' => DBA::NULL_DATETIME, 'archive' => false, 'unsearchable' => true];
|
||||
$fields = ['failed' => false, 'term-date' => DBA::NULL_DATETIME, 'archive' => false, 'unsearchable' => true];
|
||||
$condition = ['uid' => 0, 'network' => Protocol::FEDERATED, 'batch' => $contact['batch'], 'contact-type' => self::TYPE_RELAY];
|
||||
if (!DBA::exists('contact', array_merge($condition, $fields))) {
|
||||
self::update($fields, $condition);
|
||||
|
@ -1149,7 +1149,7 @@ class Contact
|
|||
}
|
||||
|
||||
if ((!isset($contact['url']) || !isset($contact['uri-id'])) && !empty($contact['id'])) {
|
||||
$fields = ['id', 'uri-id', 'url', 'batch', 'term-date'];
|
||||
$fields = ['id', 'uri-id', 'url', 'batch', 'term-date'];
|
||||
$contact = DBA::selectFirst('contact', $fields, ['id' => $contact['id']]);
|
||||
if (!DBA::isResult($contact)) {
|
||||
return;
|
||||
|
@ -1205,11 +1205,11 @@ class Contact
|
|||
|
||||
if ($contact['contact-type'] == Contact::TYPE_COMMUNITY) {
|
||||
$mention_label = DI::l10n()->t('Post to group');
|
||||
$mention_url = 'compose/0?body=!' . $contact['addr'];
|
||||
$mention_url = 'compose/0?body=!' . $contact['addr'];
|
||||
$network_label = DI::l10n()->t('View group');
|
||||
} else {
|
||||
$mention_label = DI::l10n()->t('Mention');
|
||||
$mention_url = 'compose/0?body=@' . $contact['addr'];
|
||||
$mention_url = 'compose/0?body=@' . $contact['addr'];
|
||||
$network_label = DI::l10n()->t('Network Posts');
|
||||
}
|
||||
$network_url = 'contact/' . $contact['id'] . '/conversations';
|
||||
|
@ -1369,10 +1369,10 @@ class Contact
|
|||
|
||||
if (DBA::isResult($personal_contact) && !Probe::isProbable($personal_contact['network'])) {
|
||||
DI::logger()->info('Take contact data from personal contact', ['url' => $url, 'update' => $update, 'contact' => $personal_contact]);
|
||||
$data = $personal_contact;
|
||||
$data['photo'] = $personal_contact['avatar'];
|
||||
$data = $personal_contact;
|
||||
$data['photo'] = $personal_contact['avatar'];
|
||||
$data['account-type'] = $personal_contact['contact-type'];
|
||||
$data['hide'] = $personal_contact['unsearchable'];
|
||||
$data['hide'] = $personal_contact['unsearchable'];
|
||||
unset($data['avatar']);
|
||||
unset($data['contact-type']);
|
||||
unset($data['unsearchable']);
|
||||
|
@ -1404,17 +1404,17 @@ class Contact
|
|||
if (!$contact_id) {
|
||||
// We only insert the basic data. The rest will be done in "updateFromProbeArray"
|
||||
$fields = [
|
||||
'uid' => $uid,
|
||||
'url' => $data['url'],
|
||||
'baseurl' => $data['baseurl'] ?? '',
|
||||
'nurl' => Strings::normaliseLink($data['url']),
|
||||
'network' => $data['network'],
|
||||
'created' => DateTimeFormat::utcNow(),
|
||||
'rel' => self::SHARING,
|
||||
'writable' => 1,
|
||||
'blocked' => 0,
|
||||
'readonly' => 0,
|
||||
'pending' => 0,
|
||||
'uid' => $uid,
|
||||
'url' => $data['url'],
|
||||
'baseurl' => $data['baseurl'] ?? '',
|
||||
'nurl' => Strings::normaliseLink($data['url']),
|
||||
'network' => $data['network'],
|
||||
'created' => DateTimeFormat::utcNow(),
|
||||
'rel' => self::SHARING,
|
||||
'writable' => 1,
|
||||
'blocked' => 0,
|
||||
'readonly' => 0,
|
||||
'pending' => 0,
|
||||
];
|
||||
|
||||
$condition = ['nurl' => Strings::normaliseLink($data['url']), 'uid' => $uid, 'deleted' => false];
|
||||
|
@ -1627,13 +1627,13 @@ class Contact
|
|||
|
||||
if (DI::pConfig()->get($uid, 'system', 'infinite_scroll')) {
|
||||
$tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
|
||||
$o = Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
|
||||
$o = Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
|
||||
} else {
|
||||
$o = '';
|
||||
}
|
||||
|
||||
$fields = array_merge(Item::DISPLAY_FIELDLIST, ['featured']);
|
||||
$items = Post::toArray(Post::selectForUser($uid, $fields, $condition, $params));
|
||||
$items = Post::toArray(Post::selectForUser($uid, $fields, $condition, $params));
|
||||
|
||||
$o .= DI::conversation()->render($items, ConversationContent::MODE_CONTACT_POSTS);
|
||||
|
||||
|
@ -1690,7 +1690,7 @@ class Contact
|
|||
|
||||
if (DI::pConfig()->get($uid, 'system', 'infinite_scroll')) {
|
||||
$tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
|
||||
$o = Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
|
||||
$o = Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
|
||||
} else {
|
||||
$o = '';
|
||||
}
|
||||
|
@ -1706,7 +1706,7 @@ class Contact
|
|||
$sql2 = "SELECT `thr-parent-id` AS `uri-id`, `created` FROM `post-user-view` WHERE " . array_shift($condition2);
|
||||
|
||||
$union = array_merge($condition1, $condition2);
|
||||
$sql = $sql1 . " UNION " . $sql2;
|
||||
$sql = $sql1 . " UNION " . $sql2;
|
||||
|
||||
$sql .= " ORDER BY `created` DESC LIMIT ?, ?";
|
||||
$union = array_merge($union, [$pager->getStart(), $pager->getItemsPerPage()]);
|
||||
|
@ -1715,7 +1715,7 @@ class Contact
|
|||
if (empty($last_created) && ($pager->getStart() == 0)) {
|
||||
$fields = ['uri-id', 'thr-parent-id', 'gravity', 'author-id', 'created'];
|
||||
$pinned = Post\Collection::selectToArrayForContact($cid, Post\Collection::FEATURED, $fields);
|
||||
$items = array_merge($items, $pinned);
|
||||
$items = array_merge($items, $pinned);
|
||||
}
|
||||
|
||||
$o .= DI::conversation()->render($items, ConversationContent::MODE_CONTACTS, $update, false, 'pinned_created', $uid);
|
||||
|
@ -1906,9 +1906,9 @@ class Contact
|
|||
*/
|
||||
private static function checkAvatarCacheByArray(array $contact, bool $no_update = false): array
|
||||
{
|
||||
$update = false;
|
||||
$update = false;
|
||||
$contact_fields = [];
|
||||
$fields = ['photo', 'thumb', 'micro'];
|
||||
$fields = ['photo', 'thumb', 'micro'];
|
||||
foreach ($fields as $field) {
|
||||
if (isset($contact[$field])) {
|
||||
$contact_fields[] = $field;
|
||||
|
@ -1964,7 +1964,7 @@ class Contact
|
|||
|
||||
if (!empty($contact['gsid'])) {
|
||||
// Use default banners for certain platforms
|
||||
$gserver = DBA::selectFirst('gserver', ['platform'], ['id' => $contact['gsid']]);
|
||||
$gserver = DBA::selectFirst('gserver', ['platform'], ['id' => $contact['gsid']]);
|
||||
$platform = strtolower($gserver['platform'] ?? '');
|
||||
} else {
|
||||
$platform = '';
|
||||
|
@ -2009,18 +2009,18 @@ class Contact
|
|||
switch ($size) {
|
||||
case Proxy::SIZE_MICRO:
|
||||
$avatar['size'] = 48;
|
||||
$default = self::DEFAULT_AVATAR_MICRO;
|
||||
$default = self::DEFAULT_AVATAR_MICRO;
|
||||
break;
|
||||
|
||||
case Proxy::SIZE_THUMB:
|
||||
$avatar['size'] = 80;
|
||||
$default = self::DEFAULT_AVATAR_THUMB;
|
||||
$default = self::DEFAULT_AVATAR_THUMB;
|
||||
break;
|
||||
|
||||
case Proxy::SIZE_SMALL:
|
||||
default:
|
||||
$avatar['size'] = 300;
|
||||
$default = self::DEFAULT_AVATAR_PHOTO;
|
||||
$default = self::DEFAULT_AVATAR_PHOTO;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2029,14 +2029,14 @@ class Contact
|
|||
$type = Contact::TYPE_PERSON;
|
||||
|
||||
if (!empty($contact['id'])) {
|
||||
$account = DBA::selectFirst('account-user-view', ['platform', 'contact-type'], ['id' => $contact['id']]);
|
||||
$platform = $account['platform'] ?? '';
|
||||
$account = DBA::selectFirst('account-user-view', ['platform', 'contact-type'], ['id' => $contact['id']]);
|
||||
$platform = $account['platform'] ?? '';
|
||||
$type = $account['contact-type'] ?? Contact::TYPE_PERSON;
|
||||
}
|
||||
|
||||
if (empty($platform) && !empty($contact['uri-id'])) {
|
||||
$account = DBA::selectFirst('account-user-view', ['platform', 'contact-type'], ['uri-id' => $contact['uri-id']]);
|
||||
$platform = $account['platform'] ?? '';
|
||||
$account = DBA::selectFirst('account-user-view', ['platform', 'contact-type'], ['uri-id' => $contact['uri-id']]);
|
||||
$platform = $account['platform'] ?? '';
|
||||
$type = $account['contact-type'] ?? Contact::TYPE_PERSON;
|
||||
}
|
||||
|
||||
|
@ -2146,7 +2146,7 @@ class Contact
|
|||
return DI::baseUrl() . $default;
|
||||
}
|
||||
|
||||
$avatar['url'] = '';
|
||||
$avatar['url'] = '';
|
||||
$avatar['success'] = false;
|
||||
|
||||
Hook::callAll('avatar_lookup', $avatar);
|
||||
|
@ -2174,7 +2174,7 @@ class Contact
|
|||
if (empty($updated)) {
|
||||
$account = DBA::selectFirst('account-user-view', ['updated', 'guid'], ['id' => $cid]);
|
||||
$updated = $account['updated'] ?? '';
|
||||
$guid = $account['guid'] ?? '';
|
||||
$guid = $account['guid'] ?? '';
|
||||
}
|
||||
|
||||
$guid = urlencode($guid);
|
||||
|
@ -2242,7 +2242,7 @@ class Contact
|
|||
if (empty($updated) || empty($guid)) {
|
||||
$account = DBA::selectFirst('account-user-view', ['updated', 'guid'], ['id' => $cid]);
|
||||
$updated = $account['updated'] ?? '';
|
||||
$guid = $account['guid'] ?? '';
|
||||
$guid = $account['guid'] ?? '';
|
||||
}
|
||||
|
||||
$guid = urlencode($guid);
|
||||
|
@ -2373,11 +2373,11 @@ class Contact
|
|||
|
||||
if ($default_avatar && Proxy::isLocalImage($avatar)) {
|
||||
$fields = [
|
||||
'avatar' => $avatar,
|
||||
'avatar' => $avatar,
|
||||
'avatar-date' => DateTimeFormat::utcNow(),
|
||||
'photo' => $avatar,
|
||||
'thumb' => self::getDefaultAvatar($contact, Proxy::SIZE_THUMB),
|
||||
'micro' => self::getDefaultAvatar($contact, Proxy::SIZE_MICRO)
|
||||
'photo' => $avatar,
|
||||
'thumb' => self::getDefaultAvatar($contact, Proxy::SIZE_THUMB),
|
||||
'micro' => self::getDefaultAvatar($contact, Proxy::SIZE_MICRO)
|
||||
];
|
||||
DI::logger()->debug('Use default avatar', ['id' => $cid, 'uid' => $uid]);
|
||||
}
|
||||
|
@ -2416,11 +2416,11 @@ class Contact
|
|||
$photos = Photo::importProfilePhoto($avatar, $uid, $cid, true);
|
||||
if ($photos) {
|
||||
$fields = [
|
||||
'avatar' => $avatar,
|
||||
'photo' => $photos[0],
|
||||
'thumb' => $photos[1],
|
||||
'micro' => $photos[2],
|
||||
'blurhash' => $photos[3],
|
||||
'avatar' => $avatar,
|
||||
'photo' => $photos[0],
|
||||
'thumb' => $photos[1],
|
||||
'micro' => $photos[2],
|
||||
'blurhash' => $photos[3],
|
||||
'avatar-date' => DateTimeFormat::utcNow(),
|
||||
];
|
||||
$update = true;
|
||||
|
@ -2473,7 +2473,7 @@ class Contact
|
|||
{
|
||||
// Update contact data for all users
|
||||
$condition = ['self' => false, 'nurl' => Strings::normaliseLink($url)];
|
||||
$contacts = DBA::select('contact', ['id', 'uid'], $condition);
|
||||
$contacts = DBA::select('contact', ['id', 'uid'], $condition);
|
||||
while ($contact = DBA::fetch($contacts)) {
|
||||
DI::logger()->info('Deleting contact', ['id' => $contact['id'], 'uid' => $contact['uid'], 'url' => $url]);
|
||||
self::remove($contact['id']);
|
||||
|
@ -2600,7 +2600,7 @@ class Contact
|
|||
public static function removeDuplicates(string $nurl, int $uid)
|
||||
{
|
||||
$condition = ['nurl' => $nurl, 'uid' => $uid, 'self' => false, 'deleted' => false, 'network' => Protocol::FEDERATED];
|
||||
$count = DBA::count('contact', $condition);
|
||||
$count = DBA::count('contact', $condition);
|
||||
if ($count <= 1) {
|
||||
return false;
|
||||
}
|
||||
|
@ -2615,7 +2615,7 @@ class Contact
|
|||
DI::logger()->info('Found duplicates', ['count' => $count, 'first' => $first, 'uid' => $uid, 'nurl' => $nurl]);
|
||||
|
||||
// Find all duplicates
|
||||
$condition = ["`nurl` = ? AND `uid` = ? AND `id` != ? AND NOT `self` AND NOT `deleted`", $nurl, $uid, $first];
|
||||
$condition = ["`nurl` = ? AND `uid` = ? AND `id` != ? AND NOT `self` AND NOT `deleted`", $nurl, $uid, $first];
|
||||
$duplicates = DBA::select('contact', ['id', 'network'], $condition);
|
||||
while ($duplicate = DBA::fetch($duplicates)) {
|
||||
if (!in_array($duplicate['network'], Protocol::FEDERATED)) {
|
||||
|
@ -2686,7 +2686,7 @@ class Contact
|
|||
$data = Probe::uri($contact['url'], $network, $contact['uid']);
|
||||
|
||||
if (in_array($data['network'], Protocol::FEDERATED) && (parse_url($data['url'], PHP_URL_SCHEME) == 'http')) {
|
||||
$ssl_url = str_replace('http://', 'https://', $contact['url']);
|
||||
$ssl_url = str_replace('http://', 'https://', $contact['url']);
|
||||
$ssl_data = Probe::uri($ssl_url, $network, $contact['uid']);
|
||||
if (($ssl_data['network'] == $data['network']) && (parse_url($ssl_data['url'], PHP_URL_SCHEME) != 'http')) {
|
||||
$data = $ssl_data;
|
||||
|
@ -2883,12 +2883,12 @@ class Contact
|
|||
}
|
||||
|
||||
if (isset($ret['account-type']) && is_int($ret['account-type'])) {
|
||||
$ret['forum'] = false;
|
||||
$ret['prv'] = false;
|
||||
$ret['forum'] = false;
|
||||
$ret['prv'] = false;
|
||||
$ret['contact-type'] = $ret['account-type'];
|
||||
if (($ret['contact-type'] == User::ACCOUNT_TYPE_COMMUNITY) && isset($ret['manually-approve'])) {
|
||||
$ret['forum'] = (bool)!$ret['manually-approve'];
|
||||
$ret['prv'] = (bool)!$ret['forum'];
|
||||
$ret['prv'] = (bool)!$ret['forum'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2907,7 +2907,7 @@ class Contact
|
|||
}
|
||||
|
||||
$update = false;
|
||||
$guid = ($ret['guid'] ?? '') ?: Item::guidFromUri($ret['url'], $ret['baseurl'] ?? $ret['alias'] ?? '');
|
||||
$guid = ($ret['guid'] ?? '') ?: Item::guidFromUri($ret['url'], $ret['baseurl'] ?? $ret['alias'] ?? '');
|
||||
|
||||
// make sure to not overwrite existing values with blank entries except some technical fields
|
||||
$keep = ['batch', 'notify', 'poll', 'request', 'confirm', 'poco', 'baseurl'];
|
||||
|
@ -2974,7 +2974,7 @@ class Contact
|
|||
}
|
||||
|
||||
if (($uid == 0) || in_array($ret['network'], [Protocol::DFRN, Protocol::DIASPORA, Protocol::ACTIVITYPUB])) {
|
||||
$ret['last-update'] = $updated;
|
||||
$ret['last-update'] = $updated;
|
||||
$ret['success_update'] = $updated;
|
||||
}
|
||||
|
||||
|
@ -3106,10 +3106,10 @@ class Contact
|
|||
|
||||
if (!empty($arr['contact']['name'])) {
|
||||
$probed = false;
|
||||
$ret = $arr['contact'];
|
||||
$ret = $arr['contact'];
|
||||
} else {
|
||||
$probed = true;
|
||||
$ret = Probe::uri($url, $network, $uid);
|
||||
$ret = Probe::uri($url, $network, $uid);
|
||||
|
||||
// Ensure that the public contact exists
|
||||
if ($ret['network'] != Protocol::PHANTOM) {
|
||||
|
@ -3124,7 +3124,7 @@ class Contact
|
|||
|
||||
// check if we already have a contact
|
||||
$condition = ['uid' => $uid, 'nurl' => Strings::normaliseLink($ret['url']), 'deleted' => false];
|
||||
$contact = DBA::selectFirst('contact', ['id', 'rel', 'url', 'pending', 'hub-verify'], $condition);
|
||||
$contact = DBA::selectFirst('contact', ['id', 'rel', 'url', 'pending', 'hub-verify'], $condition);
|
||||
|
||||
$protocol = self::getProtocol($ret['url'], $ret['network']);
|
||||
|
||||
|
@ -3203,7 +3203,7 @@ class Contact
|
|||
'nick' => $ret['nick'],
|
||||
'network' => $ret['network'],
|
||||
'baseurl' => $ret['baseurl'],
|
||||
'gsid' => $ret['gsid'] ?? null,
|
||||
'gsid' => $ret['gsid'] ?? null,
|
||||
'contact-type' => $ret['account-type'] ?? self::TYPE_PERSON,
|
||||
'protocol' => $protocol,
|
||||
'pubkey' => $ret['pubkey'],
|
||||
|
@ -3223,7 +3223,7 @@ class Contact
|
|||
return $result;
|
||||
}
|
||||
|
||||
$contact_id = $contact['id'];
|
||||
$contact_id = $contact['id'];
|
||||
$result['cid'] = $contact_id;
|
||||
|
||||
if ($contact['contact-type'] == self::TYPE_COMMUNITY) {
|
||||
|
@ -3268,7 +3268,7 @@ class Contact
|
|||
return false;
|
||||
}
|
||||
|
||||
$fields = ['id', 'url', 'name', 'nick', 'avatar', 'photo', 'network', 'blocked', 'baseurl'];
|
||||
$fields = ['id', 'url', 'name', 'nick', 'avatar', 'photo', 'network', 'blocked', 'baseurl'];
|
||||
$pub_contact = DBA::selectFirst('contact', $fields, ['id' => $datarray['author-id']]);
|
||||
if (!DBA::isResult($pub_contact)) {
|
||||
// Should never happen
|
||||
|
@ -3280,10 +3280,10 @@ class Contact
|
|||
return false;
|
||||
}
|
||||
|
||||
$url = ($datarray['author-link'] ?? '') ?: $pub_contact['url'];
|
||||
$name = $pub_contact['name'];
|
||||
$photo = ($pub_contact['avatar'] ?? '') ?: $pub_contact["photo"];
|
||||
$nick = $pub_contact['nick'];
|
||||
$url = ($datarray['author-link'] ?? '') ?: $pub_contact['url'];
|
||||
$name = $pub_contact['name'];
|
||||
$photo = ($pub_contact['avatar'] ?? '') ?: $pub_contact["photo"];
|
||||
$nick = $pub_contact['nick'];
|
||||
$network = $pub_contact['network'];
|
||||
|
||||
// Ensure that we don't create a new contact when there already is one
|
||||
|
@ -3361,7 +3361,7 @@ class Contact
|
|||
|
||||
/// @TODO Encapsulate this into a function/method
|
||||
$fields = ['uid', 'username', 'email', 'page-flags', 'notify-flags', 'language'];
|
||||
$user = DBA::selectFirst('user', $fields, ['uid' => $importer['uid']]);
|
||||
$user = DBA::selectFirst('user', $fields, ['uid' => $importer['uid']]);
|
||||
if (DBA::isResult($user) && !in_array($user['page-flags'], [User::PAGE_FLAGS_SOAPBOX, User::PAGE_FLAGS_FREELOVE, User::PAGE_FLAGS_COMMUNITY])) {
|
||||
// create notification
|
||||
if (is_array($contact_record)) {
|
||||
|
@ -3395,7 +3395,7 @@ class Contact
|
|||
}
|
||||
|
||||
$condition = ['uid' => $importer['uid'], 'url' => $url, 'pending' => true];
|
||||
$fields = ['pending' => false];
|
||||
$fields = ['pending' => false];
|
||||
if ($user['page-flags'] == User::PAGE_FLAGS_FREELOVE) {
|
||||
$fields['rel'] = self::FRIEND;
|
||||
}
|
||||
|
@ -3500,7 +3500,7 @@ class Contact
|
|||
DBA::update(
|
||||
'contact',
|
||||
['bdyear' => substr($nextbd, 0, 4), 'bd' => $nextbd],
|
||||
['id' => $contact['id']]
|
||||
['id' => $contact['id']]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -3655,9 +3655,9 @@ class Contact
|
|||
*/
|
||||
public static function isGroup(int $contactid): bool
|
||||
{
|
||||
$fields = ['contact-type'];
|
||||
$fields = ['contact-type'];
|
||||
$condition = ['id' => $contactid];
|
||||
$contact = DBA::selectFirst('contact', $fields, $condition);
|
||||
$contact = DBA::selectFirst('contact', $fields, $condition);
|
||||
if (!DBA::isResult($contact)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -3675,7 +3675,7 @@ class Contact
|
|||
public static function canReceivePrivateMessages(array $contact): bool
|
||||
{
|
||||
$protocol = $contact['network'] ?? $contact['protocol'] ?? Protocol::PHANTOM;
|
||||
$self = $contact['self'] ?? false;
|
||||
$self = $contact['self'] ?? false;
|
||||
|
||||
return in_array($protocol, [Protocol::DFRN, Protocol::DIASPORA, Protocol::ACTIVITYPUB]) && !$self;
|
||||
}
|
||||
|
@ -3706,12 +3706,12 @@ class Contact
|
|||
}
|
||||
|
||||
$condition = [
|
||||
'network' => $networks,
|
||||
'server-failed' => false,
|
||||
'failed' => false,
|
||||
'deleted' => false,
|
||||
'unsearchable' => false,
|
||||
'uid' => $uid
|
||||
'network' => $networks,
|
||||
'server-failed' => false,
|
||||
'failed' => false,
|
||||
'deleted' => false,
|
||||
'unsearchable' => false,
|
||||
'uid' => $uid
|
||||
];
|
||||
|
||||
if (!$show_blocked) {
|
||||
|
@ -3755,10 +3755,10 @@ class Contact
|
|||
*/
|
||||
public static function addByUrls(array $urls): array
|
||||
{
|
||||
$added = 0;
|
||||
$updated = 0;
|
||||
$added = 0;
|
||||
$updated = 0;
|
||||
$unchanged = 0;
|
||||
$count = 0;
|
||||
$count = 0;
|
||||
|
||||
foreach ($urls as $url) {
|
||||
if (empty($url) || !is_string($url)) {
|
||||
|
|
|
@ -98,7 +98,7 @@ class Relation
|
|||
$uid = User::getIdForURL($url);
|
||||
if (!empty($uid)) {
|
||||
DI::logger()->info('Fetch the followers/followings locally', ['url' => $url]);
|
||||
$followers = self::getContacts($uid, [Contact::FOLLOWER, Contact::FRIEND]);
|
||||
$followers = self::getContacts($uid, [Contact::FOLLOWER, Contact::FRIEND]);
|
||||
$followings = self::getContacts($uid, [Contact::SHARING, Contact::FRIEND]);
|
||||
} elseif (!Contact::isLocal($url)) {
|
||||
DI::logger()->info('Fetch the followers/followings by polling the endpoints', ['url' => $url]);
|
||||
|
@ -117,7 +117,7 @@ class Relation
|
|||
}
|
||||
} else {
|
||||
DI::logger()->warning('Contact seems to be local but could not be found here', ['url' => $url]);
|
||||
$followers = [];
|
||||
$followers = [];
|
||||
$followings = [];
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ class Relation
|
|||
}
|
||||
$contacts = array_unique($contacts);
|
||||
|
||||
$follower_counter = 0;
|
||||
$follower_counter = 0;
|
||||
$following_counter = 0;
|
||||
|
||||
DI::logger()->info('Discover contacts', ['id' => $target, 'url' => $url, 'contacts' => count($contacts)]);
|
||||
|
@ -199,7 +199,7 @@ class Relation
|
|||
*/
|
||||
private static function getContacts(int $uid, array $rel, bool $only_ap = true): array
|
||||
{
|
||||
$list = [];
|
||||
$list = [];
|
||||
$profile = Profile::getByUID($uid);
|
||||
if (!empty($profile['hide-friends'])) {
|
||||
return $list;
|
||||
|
@ -300,7 +300,7 @@ class Relation
|
|||
* @param integer $uid
|
||||
* @return boolean
|
||||
*/
|
||||
static public function areSuggestionsOutdated(int $uid): bool
|
||||
public static function areSuggestionsOutdated(int $uid): bool
|
||||
{
|
||||
return DI::pConfig()->get($uid, 'suggestion', 'last_update') + 3600 < time();
|
||||
}
|
||||
|
@ -311,7 +311,7 @@ class Relation
|
|||
* @param integer $uid
|
||||
* @return void
|
||||
*/
|
||||
static public function updateCachedSuggestions(int $uid)
|
||||
public static function updateCachedSuggestions(int $uid)
|
||||
{
|
||||
if (!self::areSuggestionsOutdated($uid)) {
|
||||
return;
|
||||
|
@ -334,11 +334,11 @@ class Relation
|
|||
* @param int $limit optional, default 80
|
||||
* @return array
|
||||
*/
|
||||
static public function getCachedSuggestions(int $uid, int $start = 0, int $limit = 80): array
|
||||
public static function getCachedSuggestions(int $uid, int $start = 0, int $limit = 80): array
|
||||
{
|
||||
$condition = ["`uid` = ? AND `uri-id` IN (SELECT `uri-id` FROM `account-suggestion` WHERE NOT `ignore` AND `uid` = ?)", 0, $uid];
|
||||
$params = ['limit' => [$start, $limit]];
|
||||
$cached = DBA::selectToArray('contact', [], $condition, $params);
|
||||
$params = ['limit' => [$start, $limit]];
|
||||
$cached = DBA::selectToArray('contact', [], $condition, $params);
|
||||
|
||||
if (!empty($cached)) {
|
||||
return $cached;
|
||||
|
@ -355,15 +355,15 @@ class Relation
|
|||
* @param int $limit optional, default 80
|
||||
* @return array
|
||||
*/
|
||||
static public function getSuggestions(int $uid, int $start = 0, int $limit = 80): array
|
||||
public static function getSuggestions(int $uid, int $start = 0, int $limit = 80): array
|
||||
{
|
||||
if ($uid == 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$cid = Contact::getPublicIdByUserId($uid);
|
||||
$cid = Contact::getPublicIdByUserId($uid);
|
||||
$totallimit = $start + $limit;
|
||||
$contacts = [];
|
||||
$contacts = [];
|
||||
|
||||
DI::logger()->info('Collecting suggestions', ['uid' => $uid, 'cid' => $cid, 'start' => $start, 'limit' => $limit]);
|
||||
|
||||
|
@ -371,17 +371,21 @@ class Relation
|
|||
|
||||
// The query returns contacts where contacts interacted with whom the given user follows.
|
||||
// Contacts who already are in the user's contact table are ignored.
|
||||
$results = DBA::select('contact', [], ["`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` IN
|
||||
$results = DBA::select(
|
||||
'contact',
|
||||
[],
|
||||
["`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` IN
|
||||
(SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ?)
|
||||
AND NOT `cid` IN (SELECT `id` FROM `contact` WHERE `uid` = ? AND `nurl` IN
|
||||
(SELECT `nurl` FROM `contact` WHERE `uid` = ? AND `rel` IN (?, ?))) AND `id` = `cid`)
|
||||
AND NOT `hidden` AND `network` IN (?, ?, ?)
|
||||
AND NOT `uri-id` IN (SELECT `uri-id` FROM `account-suggestion` WHERE `uri-id` = `contact`.`uri-id` AND `uid` = ?)",
|
||||
$cid,
|
||||
0,
|
||||
$uid, Contact::FRIEND, Contact::SHARING,
|
||||
Protocol::ACTIVITYPUB, Protocol::DFRN, $diaspora, $uid
|
||||
], [
|
||||
$cid,
|
||||
0,
|
||||
$uid, Contact::FRIEND, Contact::SHARING,
|
||||
Protocol::ACTIVITYPUB, Protocol::DFRN, $diaspora, $uid
|
||||
],
|
||||
[
|
||||
'order' => ['last-item' => true],
|
||||
'limit' => $totallimit,
|
||||
]
|
||||
|
@ -401,15 +405,17 @@ class Relation
|
|||
|
||||
// The query returns contacts where contacts interacted with whom also interacted with the given user.
|
||||
// Contacts who already are in the user's contact table are ignored.
|
||||
$results = DBA::select('contact', [],
|
||||
$results = DBA::select(
|
||||
'contact',
|
||||
[],
|
||||
["`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` IN
|
||||
(SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ?)
|
||||
AND NOT `cid` IN (SELECT `id` FROM `contact` WHERE `uid` = ? AND `nurl` IN
|
||||
(SELECT `nurl` FROM `contact` WHERE `uid` = ? AND `rel` IN (?, ?))) AND `id` = `cid`)
|
||||
AND NOT `hidden` AND `network` IN (?, ?, ?)
|
||||
AND NOT `uri-id` IN (SELECT `uri-id` FROM `account-suggestion` WHERE `uri-id` = `contact`.`uri-id` AND `uid` = ?)",
|
||||
$cid, 0, $uid, Contact::FRIEND, Contact::SHARING,
|
||||
Protocol::ACTIVITYPUB, Protocol::DFRN, $diaspora, $uid],
|
||||
$cid, 0, $uid, Contact::FRIEND, Contact::SHARING,
|
||||
Protocol::ACTIVITYPUB, Protocol::DFRN, $diaspora, $uid],
|
||||
['order' => ['last-item' => true], 'limit' => $totallimit]
|
||||
);
|
||||
|
||||
|
@ -425,12 +431,14 @@ class Relation
|
|||
}
|
||||
|
||||
// The query returns contacts that follow the given user but aren't followed by that user.
|
||||
$results = DBA::select('contact', [],
|
||||
$results = DBA::select(
|
||||
'contact',
|
||||
[],
|
||||
["`nurl` IN (SELECT `nurl` FROM `contact` WHERE `uid` = ? AND `rel` = ?)
|
||||
AND NOT `hidden` AND `uid` = ? AND `network` IN (?, ?, ?)
|
||||
AND NOT `uri-id` IN (SELECT `uri-id` FROM `account-suggestion` WHERE `uri-id` = `contact`.`uri-id` AND `uid` = ?)",
|
||||
$uid, Contact::FOLLOWER, 0,
|
||||
Protocol::ACTIVITYPUB, Protocol::DFRN, $diaspora, $uid],
|
||||
$uid, Contact::FOLLOWER, 0,
|
||||
Protocol::ACTIVITYPUB, Protocol::DFRN, $diaspora, $uid],
|
||||
['order' => ['last-item' => true], 'limit' => $totallimit]
|
||||
);
|
||||
|
||||
|
@ -446,12 +454,14 @@ class Relation
|
|||
}
|
||||
|
||||
// The query returns any contact that isn't followed by that user.
|
||||
$results = DBA::select('contact', [],
|
||||
$results = DBA::select(
|
||||
'contact',
|
||||
[],
|
||||
["NOT `nurl` IN (SELECT `nurl` FROM `contact` WHERE `uid` = ? AND `rel` IN (?, ?) AND `nurl` = `nurl`)
|
||||
AND NOT `hidden` AND `uid` = ? AND `network` IN (?, ?, ?)
|
||||
AND NOT `uri-id` IN (SELECT `uri-id` FROM `account-suggestion` WHERE `uri-id` = `contact`.`uri-id` AND `uid` = ?)",
|
||||
$uid, Contact::FRIEND, Contact::SHARING, 0,
|
||||
Protocol::ACTIVITYPUB, Protocol::DFRN, $diaspora, $uid],
|
||||
$uid, Contact::FRIEND, Contact::SHARING, 0,
|
||||
Protocol::ACTIVITYPUB, Protocol::DFRN, $diaspora, $uid],
|
||||
['order' => ['last-item' => true], 'limit' => $totallimit]
|
||||
);
|
||||
|
||||
|
@ -476,7 +486,7 @@ class Relation
|
|||
public static function countFollows(int $cid, array $condition = []): int
|
||||
{
|
||||
$condition = DBA::mergeConditions($condition, ["`cid` = ? and `follows`", $cid]);
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `relation-cid` WHERE " . array_shift($condition);
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `relation-cid` WHERE " . array_shift($condition);
|
||||
|
||||
$result = DBA::fetchFirst($sql, $condition);
|
||||
return $result['total'] ?? 0;
|
||||
|
@ -495,7 +505,7 @@ class Relation
|
|||
public static function listFollows(int $cid, array $condition = [], int $count = 30, int $offset = 0)
|
||||
{
|
||||
$condition = DBA::mergeConditions($condition, ["`cid` = ? and `follows`", $cid]);
|
||||
$sql = "SELECT `contact`.* FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `relation-cid` WHERE " . array_shift($condition);
|
||||
$sql = "SELECT `contact`.* FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `relation-cid` WHERE " . array_shift($condition);
|
||||
if ($count > 0) {
|
||||
$sql .= " LIMIT ?, ?";
|
||||
$condition = array_merge($condition, [$offset, $count]);
|
||||
|
@ -514,7 +524,7 @@ class Relation
|
|||
public static function countFollowers(int $cid, array $condition = [])
|
||||
{
|
||||
$condition = DBA::mergeConditions($condition, ["`relation-cid` = ? and `follows`", $cid]);
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " . array_shift($condition);
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " . array_shift($condition);
|
||||
|
||||
$result = DBA::fetchFirst($sql, $condition);
|
||||
return $result['total'] ?? 0;
|
||||
|
@ -533,7 +543,7 @@ class Relation
|
|||
public static function listFollowers(int $cid, array $condition = [], int $count = 30, int $offset = 0)
|
||||
{
|
||||
$condition = DBA::mergeConditions($condition, ["`relation-cid` = ? and `follows`", $cid]);
|
||||
$sql = "SELECT `contact`.* FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " . array_shift($condition);
|
||||
$sql = "SELECT `contact`.* FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " . array_shift($condition);
|
||||
if ($count > 0) {
|
||||
$sql .= " LIMIT ?, ?";
|
||||
$condition = array_merge($condition, [$offset, $count]);
|
||||
|
@ -553,13 +563,13 @@ class Relation
|
|||
{
|
||||
$condition1 = DBA::mergeConditions($condition, ["`cid` = ? and `follows`", $cid]);
|
||||
$condition2 = DBA::mergeConditions($condition, ["`relation-cid` = ? and `follows`", $cid]);
|
||||
$sql1 = "SELECT `contact`.`id` FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `relation-cid` WHERE " . array_shift($condition1);
|
||||
$sql2 = "SELECT `contact`.`id` FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " . array_shift($condition2);
|
||||
$union = array_merge($condition1, $condition2);
|
||||
$sql = $sql1 . " INTERSECT " . $sql2;
|
||||
$sql1 = "SELECT `contact`.`id` FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `relation-cid` WHERE " . array_shift($condition1);
|
||||
$sql2 = "SELECT `contact`.`id` FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " . array_shift($condition2);
|
||||
$union = array_merge($condition1, $condition2);
|
||||
$sql = $sql1 . " INTERSECT " . $sql2;
|
||||
|
||||
$contacts = 0;
|
||||
$query = DBA::p($sql, $union);
|
||||
$query = DBA::p($sql, $union);
|
||||
while (DBA::fetch($query)) {
|
||||
$contacts++;
|
||||
}
|
||||
|
@ -582,10 +592,10 @@ class Relation
|
|||
{
|
||||
$condition1 = DBA::mergeConditions($condition, ["`cid` = ? and `follows`", $cid]);
|
||||
$condition2 = DBA::mergeConditions($condition, ["`relation-cid` = ? and `follows`", $cid]);
|
||||
$sql1 = "SELECT `contact`.* FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `relation-cid` WHERE " . array_shift($condition1);
|
||||
$sql2 = "SELECT `contact`.* FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " . array_shift($condition2);
|
||||
$union = array_merge($condition1, $condition2);
|
||||
$sql = $sql1 . " INTERSECT " . $sql2;
|
||||
$sql1 = "SELECT `contact`.* FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `relation-cid` WHERE " . array_shift($condition1);
|
||||
$sql2 = "SELECT `contact`.* FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " . array_shift($condition2);
|
||||
$union = array_merge($condition1, $condition2);
|
||||
$sql = $sql1 . " INTERSECT " . $sql2;
|
||||
if ($count > 0) {
|
||||
$sql .= " LIMIT ?, ?";
|
||||
$union = array_merge($union, [$offset, $count]);
|
||||
|
@ -605,13 +615,13 @@ class Relation
|
|||
{
|
||||
$condition1 = DBA::mergeConditions($condition, ["`cid` = ? and `follows`", $cid]);
|
||||
$condition2 = DBA::mergeConditions($condition, ["`relation-cid` = ? and `follows`", $cid]);
|
||||
$sql1 = "SELECT `contact`.`id` FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `relation-cid` WHERE " . array_shift($condition1);
|
||||
$sql2 = "SELECT `contact`.`id` FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " .array_shift($condition2);
|
||||
$union = array_merge($condition1, $condition2);
|
||||
$sql = $sql1 . " UNION " . $sql2;
|
||||
$sql1 = "SELECT `contact`.`id` FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `relation-cid` WHERE " . array_shift($condition1);
|
||||
$sql2 = "SELECT `contact`.`id` FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " .array_shift($condition2);
|
||||
$union = array_merge($condition1, $condition2);
|
||||
$sql = $sql1 . " UNION " . $sql2;
|
||||
|
||||
$contacts = 0;
|
||||
$query = DBA::p($sql, $union);
|
||||
$query = DBA::p($sql, $union);
|
||||
while (DBA::fetch($query)) {
|
||||
$contacts++;
|
||||
}
|
||||
|
@ -634,10 +644,10 @@ class Relation
|
|||
{
|
||||
$condition1 = DBA::mergeConditions($condition, ["`cid` = ? and `follows`", $cid]);
|
||||
$condition2 = DBA::mergeConditions($condition, ["`relation-cid` = ? and `follows`", $cid]);
|
||||
$sql1 = "SELECT `contact`.* FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `relation-cid` WHERE " . array_shift($condition1);
|
||||
$sql2 = "SELECT `contact`.* FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " .array_shift($condition2);
|
||||
$union = array_merge($condition1, $condition2);
|
||||
$sql = $sql1 . " UNION " . $sql2;
|
||||
$sql1 = "SELECT `contact`.* FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `relation-cid` WHERE " . array_shift($condition1);
|
||||
$sql2 = "SELECT `contact`.* FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " .array_shift($condition2);
|
||||
$union = array_merge($condition1, $condition2);
|
||||
$sql = $sql1 . " UNION " . $sql2;
|
||||
if ($count > 0) {
|
||||
$sql .= " LIMIT ?, ?";
|
||||
$union = array_merge($union, [$offset, $count]);
|
||||
|
@ -659,13 +669,13 @@ class Relation
|
|||
{
|
||||
$condition1 = DBA::mergeConditions($condition, ["`relation-cid` = ?", $sourceId]);
|
||||
$condition2 = DBA::mergeConditions($condition, ["`relation-cid` = ?", $targetId]);
|
||||
$sql1 = "SELECT `contact`.`id` FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " . array_shift($condition1);
|
||||
$sql2 = "SELECT `contact`.`id` FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " .array_shift($condition2);
|
||||
$union = array_merge($condition1, $condition2);
|
||||
$sql = $sql1 . " INTERSECT " . $sql2;
|
||||
$sql1 = "SELECT `contact`.`id` FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " . array_shift($condition1);
|
||||
$sql2 = "SELECT `contact`.`id` FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " .array_shift($condition2);
|
||||
$union = array_merge($condition1, $condition2);
|
||||
$sql = $sql1 . " INTERSECT " . $sql2;
|
||||
|
||||
$contacts = 0;
|
||||
$query = DBA::p($sql, $union);
|
||||
$query = DBA::p($sql, $union);
|
||||
while (DBA::fetch($query)) {
|
||||
$contacts++;
|
||||
}
|
||||
|
@ -690,10 +700,10 @@ class Relation
|
|||
{
|
||||
$condition1 = DBA::mergeConditions($condition, ["`relation-cid` = ?", $sourceId]);
|
||||
$condition2 = DBA::mergeConditions($condition, ["`relation-cid` = ?", $targetId]);
|
||||
$sql1 = "SELECT `contact`.* FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " . array_shift($condition1);
|
||||
$sql2 = "SELECT `contact`.* FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " .array_shift($condition2);
|
||||
$union = array_merge($condition1, $condition2);
|
||||
$sql = $sql1 . " INTERSECT " . $sql2;
|
||||
$sql1 = "SELECT `contact`.* FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " . array_shift($condition1);
|
||||
$sql2 = "SELECT `contact`.* FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " .array_shift($condition2);
|
||||
$union = array_merge($condition1, $condition2);
|
||||
$sql = $sql1 . " INTERSECT " . $sql2;
|
||||
if ($count > 0) {
|
||||
$sql .= " LIMIT ?, ?";
|
||||
$union = array_merge($union, [$offset, $count]);
|
||||
|
@ -712,10 +722,11 @@ class Relation
|
|||
*/
|
||||
public static function countCommonFollows(int $sourceId, int $targetId, array $condition = []): int
|
||||
{
|
||||
$condition = DBA::mergeConditions($condition,
|
||||
$condition = DBA::mergeConditions(
|
||||
$condition,
|
||||
['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)
|
||||
AND `id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)',
|
||||
$sourceId, $targetId]
|
||||
$sourceId, $targetId]
|
||||
);
|
||||
|
||||
return DI::dba()->count('contact', $condition);
|
||||
|
@ -735,13 +746,17 @@ class Relation
|
|||
*/
|
||||
public static function listCommonFollows(int $sourceId, int $targetId, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
|
||||
{
|
||||
$condition = DBA::mergeConditions($condition,
|
||||
$condition = DBA::mergeConditions(
|
||||
$condition,
|
||||
["`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)
|
||||
AND `id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)",
|
||||
$sourceId, $targetId]
|
||||
$sourceId, $targetId]
|
||||
);
|
||||
|
||||
return DI::dba()->selectToArray('contact', [], $condition,
|
||||
return DI::dba()->selectToArray(
|
||||
'contact',
|
||||
[],
|
||||
$condition,
|
||||
['limit' => [$offset, $count], 'order' => [$shuffle ? 'RAND()' : 'name']]
|
||||
);
|
||||
}
|
||||
|
@ -757,10 +772,11 @@ class Relation
|
|||
*/
|
||||
public static function countCommonFollowers(int $sourceId, int $targetId, array $condition = []): int
|
||||
{
|
||||
$condition = DBA::mergeConditions($condition,
|
||||
$condition = DBA::mergeConditions(
|
||||
$condition,
|
||||
["`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)
|
||||
AND `id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)",
|
||||
$sourceId, $targetId]
|
||||
$sourceId, $targetId]
|
||||
);
|
||||
|
||||
return DI::dba()->count('contact', $condition);
|
||||
|
@ -780,13 +796,17 @@ class Relation
|
|||
*/
|
||||
public static function listCommonFollowers(int $sourceId, int $targetId, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
|
||||
{
|
||||
$condition = DBA::mergeConditions($condition,
|
||||
$condition = DBA::mergeConditions(
|
||||
$condition,
|
||||
["`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)
|
||||
AND `id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)",
|
||||
$sourceId, $targetId]
|
||||
$sourceId, $targetId]
|
||||
);
|
||||
|
||||
return DI::dba()->selectToArray('contact', [], $condition,
|
||||
return DI::dba()->selectToArray(
|
||||
'contact',
|
||||
[],
|
||||
$condition,
|
||||
['limit' => [$offset, $count], 'order' => [$shuffle ? 'RAND()' : 'name']]
|
||||
);
|
||||
}
|
||||
|
@ -799,78 +819,156 @@ class Relation
|
|||
*/
|
||||
public static function calculateInteractionScore(int $uid)
|
||||
{
|
||||
$days = DI::config()->get('channel', 'interaction_score_days');
|
||||
$days = DI::config()->get('channel', 'interaction_score_days');
|
||||
$contact_id = Contact::getPublicIdByUserId($uid);
|
||||
|
||||
DI::logger()->debug('Calculation - start', ['uid' => $uid, 'cid' => $contact_id, 'days' => $days]);
|
||||
|
||||
$follow = Verb::getID(Activity::FOLLOW);
|
||||
$view = Verb::getID(Activity::VIEW);
|
||||
$read = Verb::getID(Activity::READ);
|
||||
$view = Verb::getID(Activity::VIEW);
|
||||
$read = Verb::getID(Activity::READ);
|
||||
|
||||
DBA::update('contact-relation', ['score' => 0, 'relation-score' => 0, 'thread-score' => 0, 'relation-thread-score' => 0], ['relation-cid' => $contact_id]);
|
||||
|
||||
$total = DBA::fetchFirst("SELECT count(*) AS `activity` FROM `post-user` INNER JOIN `post` ON `post`.`uri-id` = `post-user`.`thr-parent-id` WHERE `post-user`.`author-id` = ? AND `post-user`.`received` >= ? AND `post-user`.`uid` = ? AND `post`.`author-id` != ? AND NOT `post`.`vid` IN (?, ?, ?)",
|
||||
$contact_id, DateTimeFormat::utc('now - ' . $days . ' day'), $uid, $contact_id, $follow, $view, $read);
|
||||
$total = DBA::fetchFirst(
|
||||
"SELECT count(*) AS `activity` FROM `post-user` INNER JOIN `post` ON `post`.`uri-id` = `post-user`.`thr-parent-id` WHERE `post-user`.`author-id` = ? AND `post-user`.`received` >= ? AND `post-user`.`uid` = ? AND `post`.`author-id` != ? AND NOT `post`.`vid` IN (?, ?, ?)",
|
||||
$contact_id,
|
||||
DateTimeFormat::utc('now - ' . $days . ' day'),
|
||||
$uid,
|
||||
$contact_id,
|
||||
$follow,
|
||||
$view,
|
||||
$read
|
||||
);
|
||||
|
||||
DI::logger()->debug('Calculate relation-score', ['uid' => $uid, 'total' => $total['activity']]);
|
||||
|
||||
$interactions = DBA::p("SELECT `post`.`author-id`, count(*) AS `activity`, EXISTS(SELECT `pid` FROM `account-user-view` WHERE `pid` = `post`.`author-id` AND `uid` = ? AND `rel` IN (?, ?)) AS `follows`
|
||||
$interactions = DBA::p(
|
||||
"SELECT `post`.`author-id`, count(*) AS `activity`, EXISTS(SELECT `pid` FROM `account-user-view` WHERE `pid` = `post`.`author-id` AND `uid` = ? AND `rel` IN (?, ?)) AS `follows`
|
||||
FROM `post-user` INNER JOIN `post` ON `post`.`uri-id` = `post-user`.`thr-parent-id` WHERE `post-user`.`author-id` = ? AND `post-user`.`received` >= ? AND `post-user`.`uid` = ? AND `post`.`author-id` != ? AND NOT `post`.`vid` IN (?, ?, ?) GROUP BY `post`.`author-id`",
|
||||
$uid, Contact::SHARING, Contact::FRIEND, $contact_id, DateTimeFormat::utc('now - ' . $days . ' day'), $uid, $contact_id, $follow, $view, $read);
|
||||
$uid,
|
||||
Contact::SHARING,
|
||||
Contact::FRIEND,
|
||||
$contact_id,
|
||||
DateTimeFormat::utc('now - ' . $days . ' day'),
|
||||
$uid,
|
||||
$contact_id,
|
||||
$follow,
|
||||
$view,
|
||||
$read
|
||||
);
|
||||
while ($interaction = DBA::fetch($interactions)) {
|
||||
$score = min((int)(($interaction['activity'] / $total['activity']) * 65535), 65535);
|
||||
DBA::update('contact-relation', ['relation-score' => $score, 'follows' => $interaction['follows']], ['relation-cid' => $contact_id, 'cid' => $interaction['author-id']]);
|
||||
}
|
||||
DBA::close($interactions);
|
||||
|
||||
$total = DBA::fetchFirst("SELECT count(*) AS `activity` FROM `post-user` INNER JOIN `post` ON `post`.`uri-id` = `post-user`.`parent-uri-id` WHERE `post-user`.`author-id` = ? AND `post-user`.`received` >= ? AND `post-user`.`uid` = ? AND `post`.`author-id` != ? AND NOT `post`.`vid` IN (?, ?, ?)",
|
||||
$contact_id, DateTimeFormat::utc('now - ' . $days . ' day'), $uid, $contact_id, $follow, $view, $read);
|
||||
$total = DBA::fetchFirst(
|
||||
"SELECT count(*) AS `activity` FROM `post-user` INNER JOIN `post` ON `post`.`uri-id` = `post-user`.`parent-uri-id` WHERE `post-user`.`author-id` = ? AND `post-user`.`received` >= ? AND `post-user`.`uid` = ? AND `post`.`author-id` != ? AND NOT `post`.`vid` IN (?, ?, ?)",
|
||||
$contact_id,
|
||||
DateTimeFormat::utc('now - ' . $days . ' day'),
|
||||
$uid,
|
||||
$contact_id,
|
||||
$follow,
|
||||
$view,
|
||||
$read
|
||||
);
|
||||
|
||||
DI::logger()->debug('Calculate relation-thread-score', ['uid' => $uid, 'total' => $total['activity']]);
|
||||
|
||||
$interactions = DBA::p("SELECT `post`.`author-id`, count(*) AS `activity`, EXISTS(SELECT `pid` FROM `account-user-view` WHERE `pid` = `post`.`author-id` AND `uid` = ? AND `rel` IN (?, ?)) AS `follows`
|
||||
$interactions = DBA::p(
|
||||
"SELECT `post`.`author-id`, count(*) AS `activity`, EXISTS(SELECT `pid` FROM `account-user-view` WHERE `pid` = `post`.`author-id` AND `uid` = ? AND `rel` IN (?, ?)) AS `follows`
|
||||
FROM `post-user` INNER JOIN `post` ON `post`.`uri-id` = `post-user`.`parent-uri-id` WHERE `post-user`.`author-id` = ? AND `post-user`.`received` >= ? AND `post-user`.`uid` = ? AND `post`.`author-id` != ? AND NOT `post`.`vid` IN (?, ?, ?) GROUP BY `post`.`author-id`",
|
||||
$uid, Contact::SHARING, Contact::FRIEND, $contact_id, DateTimeFormat::utc('now - ' . $days . ' day'), $uid, $contact_id, $follow, $view, $read);
|
||||
$uid,
|
||||
Contact::SHARING,
|
||||
Contact::FRIEND,
|
||||
$contact_id,
|
||||
DateTimeFormat::utc('now - ' . $days . ' day'),
|
||||
$uid,
|
||||
$contact_id,
|
||||
$follow,
|
||||
$view,
|
||||
$read
|
||||
);
|
||||
while ($interaction = DBA::fetch($interactions)) {
|
||||
$score = min((int)(($interaction['activity'] / $total['activity']) * 65535), 65535);
|
||||
DBA::update('contact-relation', ['relation-thread-score' => $score, 'follows' => !empty($interaction['follows'])], ['relation-cid' => $contact_id, 'cid' => $interaction['author-id']]);
|
||||
}
|
||||
DBA::close($interactions);
|
||||
|
||||
$total = DBA::fetchFirst("SELECT count(*) AS `activity` FROM `post-user` INNER JOIN `post` ON `post-user`.`uri-id` = `post`.`thr-parent-id` WHERE `post-user`.`author-id` = ? AND `post-user`.`received` >= ? AND `post-user`.`uid` = ? AND `post`.`author-id` != ? AND NOT `post`.`vid` IN (?, ?, ?)",
|
||||
$contact_id, DateTimeFormat::utc('now - ' . $days . ' day'), $uid, $contact_id, $follow, $view, $read);
|
||||
$total = DBA::fetchFirst(
|
||||
"SELECT count(*) AS `activity` FROM `post-user` INNER JOIN `post` ON `post-user`.`uri-id` = `post`.`thr-parent-id` WHERE `post-user`.`author-id` = ? AND `post-user`.`received` >= ? AND `post-user`.`uid` = ? AND `post`.`author-id` != ? AND NOT `post`.`vid` IN (?, ?, ?)",
|
||||
$contact_id,
|
||||
DateTimeFormat::utc('now - ' . $days . ' day'),
|
||||
$uid,
|
||||
$contact_id,
|
||||
$follow,
|
||||
$view,
|
||||
$read
|
||||
);
|
||||
|
||||
DI::logger()->debug('Calculate score', ['uid' => $uid, 'total' => $total['activity']]);
|
||||
|
||||
$interactions = DBA::p("SELECT `post`.`author-id`, count(*) AS `activity` FROM `post-user` INNER JOIN `post` ON `post-user`.`uri-id` = `post`.`thr-parent-id` WHERE `post-user`.`author-id` = ? AND `post-user`.`received` >= ? AND `post-user`.`uid` = ? AND `post`.`author-id` != ? AND NOT `post`.`vid` IN (?, ?, ?) GROUP BY `post`.`author-id`",
|
||||
$contact_id, DateTimeFormat::utc('now - ' . $days . ' day'), $uid, $contact_id, $follow, $view, $read);
|
||||
$interactions = DBA::p(
|
||||
"SELECT `post`.`author-id`, count(*) AS `activity` FROM `post-user` INNER JOIN `post` ON `post-user`.`uri-id` = `post`.`thr-parent-id` WHERE `post-user`.`author-id` = ? AND `post-user`.`received` >= ? AND `post-user`.`uid` = ? AND `post`.`author-id` != ? AND NOT `post`.`vid` IN (?, ?, ?) GROUP BY `post`.`author-id`",
|
||||
$contact_id,
|
||||
DateTimeFormat::utc('now - ' . $days . ' day'),
|
||||
$uid,
|
||||
$contact_id,
|
||||
$follow,
|
||||
$view,
|
||||
$read
|
||||
);
|
||||
while ($interaction = DBA::fetch($interactions)) {
|
||||
$score = min((int)(($interaction['activity'] / $total['activity']) * 65535), 65535);
|
||||
DBA::update('contact-relation', ['score' => $score], ['relation-cid' => $contact_id, 'cid' => $interaction['author-id']]);
|
||||
}
|
||||
DBA::close($interactions);
|
||||
|
||||
$total = DBA::fetchFirst("SELECT count(*) AS `activity` FROM `post-user` INNER JOIN `post` ON `post-user`.`uri-id` = `post`.`parent-uri-id` WHERE `post-user`.`author-id` = ? AND `post-user`.`received` >= ? AND `post-user`.`uid` = ? AND `post`.`author-id` != ? AND NOT `post`.`vid` IN (?, ?, ?)",
|
||||
$contact_id, DateTimeFormat::utc('now - ' . $days . ' day'), $uid, $contact_id, $follow, $view, $read);
|
||||
$total = DBA::fetchFirst(
|
||||
"SELECT count(*) AS `activity` FROM `post-user` INNER JOIN `post` ON `post-user`.`uri-id` = `post`.`parent-uri-id` WHERE `post-user`.`author-id` = ? AND `post-user`.`received` >= ? AND `post-user`.`uid` = ? AND `post`.`author-id` != ? AND NOT `post`.`vid` IN (?, ?, ?)",
|
||||
$contact_id,
|
||||
DateTimeFormat::utc('now - ' . $days . ' day'),
|
||||
$uid,
|
||||
$contact_id,
|
||||
$follow,
|
||||
$view,
|
||||
$read
|
||||
);
|
||||
|
||||
DI::logger()->debug('Calculate thread-score', ['uid' => $uid, 'total' => $total['activity']]);
|
||||
|
||||
$interactions = DBA::p("SELECT `post`.`author-id`, count(*) AS `activity` FROM `post-user` INNER JOIN `post` ON `post-user`.`uri-id` = `post`.`parent-uri-id` WHERE `post-user`.`author-id` = ? AND `post-user`.`received` >= ? AND `post-user`.`uid` = ? AND `post`.`author-id` != ? AND NOT `post`.`vid` IN (?, ?, ?) GROUP BY `post`.`author-id`",
|
||||
$contact_id, DateTimeFormat::utc('now - ' . $days . ' day'), $uid, $contact_id, $follow, $view, $read);
|
||||
$interactions = DBA::p(
|
||||
"SELECT `post`.`author-id`, count(*) AS `activity` FROM `post-user` INNER JOIN `post` ON `post-user`.`uri-id` = `post`.`parent-uri-id` WHERE `post-user`.`author-id` = ? AND `post-user`.`received` >= ? AND `post-user`.`uid` = ? AND `post`.`author-id` != ? AND NOT `post`.`vid` IN (?, ?, ?) GROUP BY `post`.`author-id`",
|
||||
$contact_id,
|
||||
DateTimeFormat::utc('now - ' . $days . ' day'),
|
||||
$uid,
|
||||
$contact_id,
|
||||
$follow,
|
||||
$view,
|
||||
$read
|
||||
);
|
||||
while ($interaction = DBA::fetch($interactions)) {
|
||||
$score = min((int)(($interaction['activity'] / $total['activity']) * 65535), 65535);
|
||||
DBA::update('contact-relation', ['thread-score' => $score], ['relation-cid' => $contact_id, 'cid' => $interaction['author-id']]);
|
||||
}
|
||||
DBA::close($interactions);
|
||||
|
||||
$total = DBA::fetchFirst("SELECT count(*) AS `posts` FROM `post-thread-user` WHERE EXISTS(SELECT `cid` FROM `contact-relation` WHERE `cid` = `post-thread-user`.`author-id` AND `relation-cid` = ? AND `follows`) AND `uid` = ? AND `created` > ?",
|
||||
$contact_id, $uid, DateTimeFormat::utc('now - ' . $days . ' day'));
|
||||
$total = DBA::fetchFirst(
|
||||
"SELECT count(*) AS `posts` FROM `post-thread-user` WHERE EXISTS(SELECT `cid` FROM `contact-relation` WHERE `cid` = `post-thread-user`.`author-id` AND `relation-cid` = ? AND `follows`) AND `uid` = ? AND `created` > ?",
|
||||
$contact_id,
|
||||
$uid,
|
||||
DateTimeFormat::utc('now - ' . $days . ' day')
|
||||
);
|
||||
|
||||
DI::logger()->debug('Calculate post-score', ['uid' => $uid, 'total' => $total['posts']]);
|
||||
|
||||
$posts = DBA::p("SELECT `author-id`, count(*) AS `posts` FROM `post-thread-user` WHERE EXISTS(SELECT `cid` FROM `contact-relation` WHERE `cid` = `post-thread-user`.`author-id` AND `relation-cid` = ? AND `follows`) AND `uid` = ? AND `created` > ? GROUP BY `author-id`",
|
||||
$contact_id, $uid, DateTimeFormat::utc('now - ' . $days . ' day'));
|
||||
$posts = DBA::p(
|
||||
"SELECT `author-id`, count(*) AS `posts` FROM `post-thread-user` WHERE EXISTS(SELECT `cid` FROM `contact-relation` WHERE `cid` = `post-thread-user`.`author-id` AND `relation-cid` = ? AND `follows`) AND `uid` = ? AND `created` > ? GROUP BY `author-id`",
|
||||
$contact_id,
|
||||
$uid,
|
||||
DateTimeFormat::utc('now - ' . $days . ' day')
|
||||
);
|
||||
while ($post = DBA::fetch($posts)) {
|
||||
$score = min((int)(($post['posts'] / $total['posts']) * 65535), 65535);
|
||||
DBA::update('contact-relation', ['post-score' => $score], ['relation-cid' => $contact_id, 'cid' => $post['author-id']]);
|
||||
|
|
|
@ -56,9 +56,9 @@ class User
|
|||
return false;
|
||||
}
|
||||
|
||||
$fields = self::preparedFields($contact);
|
||||
$fields['cid'] = $pcid;
|
||||
$fields['uid'] = $contact['uid'];
|
||||
$fields = self::preparedFields($contact);
|
||||
$fields['cid'] = $pcid;
|
||||
$fields['uid'] = $contact['uid'];
|
||||
$fields['uri-id'] = $contact['uri-id'];
|
||||
|
||||
$ret = DBA::insert('user-contact', $fields, Database::INSERT_UPDATE);
|
||||
|
@ -89,7 +89,7 @@ class User
|
|||
continue;
|
||||
}
|
||||
$update_fields['cid'] = $contact['pid'];
|
||||
$ret = DBA::update('user-contact', $update_fields, ['uri-id' => $contact['uri-id'], 'uid' => $contact['uid']], true);
|
||||
$ret = DBA::update('user-contact', $update_fields, ['uri-id' => $contact['uri-id'], 'uid' => $contact['uid']], true);
|
||||
DI::logger()->info('Updated user contact', ['uid' => $contact['uid'], 'id' => $contact['pid'], 'uri-id' => $contact['uri-id'], 'ret' => $ret]);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@ use Friendica\Util\XML;
|
|||
*/
|
||||
class Event
|
||||
{
|
||||
|
||||
public static function getHTML(array $event, bool $simple = false, int $uriid = 0): string
|
||||
{
|
||||
if (empty($event)) {
|
||||
|
@ -232,28 +231,28 @@ class Event
|
|||
*/
|
||||
public static function store(array $arr): int
|
||||
{
|
||||
$guid = $arr['guid'] ?? '' ?: System::createUUID();
|
||||
$uri = $arr['uri'] ?? '' ?: Item::newURI($guid);
|
||||
$guid = $arr['guid'] ?? '' ?: System::createUUID();
|
||||
$uri = $arr['uri'] ?? '' ?: Item::newURI($guid);
|
||||
$event = [
|
||||
'id' => intval($arr['id'] ?? 0),
|
||||
'uid' => intval($arr['uid'] ?? 0),
|
||||
'cid' => intval($arr['cid'] ?? 0),
|
||||
'id' => intval($arr['id'] ?? 0),
|
||||
'uid' => intval($arr['uid'] ?? 0),
|
||||
'cid' => intval($arr['cid'] ?? 0),
|
||||
'guid' => $guid,
|
||||
'uri' => $uri,
|
||||
'uri-id' => ItemURI::insert(['uri' => $uri, 'guid' => $guid]),
|
||||
'type' => ($arr['type'] ?? '') ?: 'event',
|
||||
'summary' => $arr['summary'] ?? '',
|
||||
'desc' => $arr['desc'] ?? '',
|
||||
'location' => $arr['location'] ?? '',
|
||||
'allow_cid' => $arr['allow_cid'] ?? '',
|
||||
'allow_gid' => $arr['allow_gid'] ?? '',
|
||||
'deny_cid' => $arr['deny_cid'] ?? '',
|
||||
'deny_gid' => $arr['deny_gid'] ?? '',
|
||||
'type' => ($arr['type'] ?? '') ?: 'event',
|
||||
'summary' => $arr['summary'] ?? '',
|
||||
'desc' => $arr['desc'] ?? '',
|
||||
'location' => $arr['location'] ?? '',
|
||||
'allow_cid' => $arr['allow_cid'] ?? '',
|
||||
'allow_gid' => $arr['allow_gid'] ?? '',
|
||||
'deny_cid' => $arr['deny_cid'] ?? '',
|
||||
'deny_gid' => $arr['deny_gid'] ?? '',
|
||||
'nofinish' => intval($arr['nofinish'] ?? (!empty($arr['start']) && empty($arr['finish']))),
|
||||
'created' => DateTimeFormat::utc(($arr['created'] ?? '') ?: 'now'),
|
||||
'edited' => DateTimeFormat::utc(($arr['edited'] ?? '') ?: 'now'),
|
||||
'start' => DateTimeFormat::utc(($arr['start'] ?? '') ?: DBA::NULL_DATETIME),
|
||||
'finish' => DateTimeFormat::utc(($arr['finish'] ?? '') ?: DBA::NULL_DATETIME),
|
||||
'edited' => DateTimeFormat::utc(($arr['edited'] ?? '') ?: 'now'),
|
||||
'start' => DateTimeFormat::utc(($arr['start'] ?? '') ?: DBA::NULL_DATETIME),
|
||||
'finish' => DateTimeFormat::utc(($arr['finish'] ?? '') ?: DBA::NULL_DATETIME),
|
||||
];
|
||||
|
||||
|
||||
|
@ -357,7 +356,7 @@ class Event
|
|||
$item['body'] = self::getBBCode($event);
|
||||
$item['event-id'] = $event['id'];
|
||||
|
||||
$item['object'] = '<object><type>' . XML::escape(Activity\ObjectType::EVENT) . '</type><title></title><id>' . XML::escape($event['uri']) . '</id>';
|
||||
$item['object'] = '<object><type>' . XML::escape(Activity\ObjectType::EVENT) . '</type><title></title><id>' . XML::escape($event['uri']) . '</id>';
|
||||
$item['object'] .= '<content>' . XML::escape(self::getBBCode($event)) . '</content>';
|
||||
$item['object'] .= '</object>' . "\n";
|
||||
|
||||
|
@ -375,13 +374,13 @@ class Event
|
|||
return $item;
|
||||
}
|
||||
|
||||
$item['post-type'] = Item::PT_EVENT;
|
||||
$item['title'] = '';
|
||||
$item['object-type'] = Activity\ObjectType::EVENT;
|
||||
$item['body'] = self::getBBCode($event);
|
||||
$item['event-id'] = $event_id;
|
||||
$item['post-type'] = Item::PT_EVENT;
|
||||
$item['title'] = '';
|
||||
$item['object-type'] = Activity\ObjectType::EVENT;
|
||||
$item['body'] = self::getBBCode($event);
|
||||
$item['event-id'] = $event_id;
|
||||
|
||||
$item['object'] = '<object><type>' . XML::escape(Activity\ObjectType::EVENT) . '</type><title></title><id>' . XML::escape($event['uri']) . '</id>';
|
||||
$item['object'] = '<object><type>' . XML::escape(Activity\ObjectType::EVENT) . '</type><title></title><id>' . XML::escape($event['uri']) . '</id>';
|
||||
$item['object'] .= '<content>' . XML::escape(self::getBBCode($event)) . '</content>';
|
||||
$item['object'] .= '</object>' . "\n";
|
||||
|
||||
|
@ -398,7 +397,7 @@ class Event
|
|||
{
|
||||
// First day of the week (0 = Sunday).
|
||||
$firstDay = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'calendar', 'first_day_of_week') ?? 0;
|
||||
$defaultView = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'calendar', 'defaultView') ?? 'month';
|
||||
$defaultView = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'calendar', 'defaultView') ?? 'month';
|
||||
|
||||
return [
|
||||
'firstDay' => $firstDay,
|
||||
|
@ -649,12 +648,12 @@ class Event
|
|||
if (DI::userSession()->getLocalUserId() && DI::userSession()->getLocalUserId() == $event['uid'] && $event['type'] == 'event') {
|
||||
$edit = !$event['cid'] ? ['calendar/event/edit/' . $event['id'], DI::l10n()->t('Edit event'), '', ''] : null;
|
||||
$copy = !$event['cid'] ? ['calendar/event/copy/' . $event['id'], DI::l10n()->t('Duplicate event'), '', ''] : null;
|
||||
$drop = ['calendar/api/delete/' . $event['id'], DI::l10n()->t('Delete event'), '', ''];
|
||||
$drop = ['calendar/api/delete/' . $event['id'], DI::l10n()->t('Delete event'), '', ''];
|
||||
}
|
||||
|
||||
$title = strip_tags(BBCode::convertForUriId($event['uri-id'], $event['summary']));
|
||||
if (!$title) {
|
||||
[$title, $_trash] = explode("<br", BBCode::convertForUriId($event['uri-id'], Strings::escapeHtml($event['desc'])), BBCode::TWITTER_API);
|
||||
list($title, $_trash) = explode("<br", BBCode::convertForUriId($event['uri-id'], Strings::escapeHtml($event['desc'])), BBCode::TWITTER_API);
|
||||
}
|
||||
|
||||
$event['author-link'] = Contact::magicLink($event['author-link']);
|
||||
|
@ -694,7 +693,7 @@ class Event
|
|||
}
|
||||
|
||||
switch ($format) {
|
||||
// Format the exported data as a CSV file.
|
||||
// Format the exported data as a CSV file.
|
||||
case "csv":
|
||||
$o .= '"Subject", "Start Date", "Start Time", "Description", "End Date", "End Time", "Location"' . PHP_EOL;
|
||||
|
||||
|
@ -744,21 +743,21 @@ class Event
|
|||
$tmp = $event['summary'];
|
||||
$tmp = str_replace(PHP_EOL, PHP_EOL . ' ', $tmp);
|
||||
$tmp = addcslashes($tmp, ',;');
|
||||
$o .= 'SUMMARY:' . $tmp . PHP_EOL;
|
||||
$o .= 'SUMMARY:' . $tmp . PHP_EOL;
|
||||
}
|
||||
|
||||
if ($event['desc']) {
|
||||
$tmp = $event['desc'];
|
||||
$tmp = str_replace(PHP_EOL, PHP_EOL . ' ', $tmp);
|
||||
$tmp = addcslashes($tmp, ',;');
|
||||
$o .= 'DESCRIPTION:' . $tmp . PHP_EOL;
|
||||
$o .= 'DESCRIPTION:' . $tmp . PHP_EOL;
|
||||
}
|
||||
|
||||
if ($event['location']) {
|
||||
$tmp = $event['location'];
|
||||
$tmp = str_replace(PHP_EOL, PHP_EOL . ' ', $tmp);
|
||||
$tmp = addcslashes($tmp, ',;');
|
||||
$o .= 'LOCATION:' . $tmp . PHP_EOL;
|
||||
$o .= 'LOCATION:' . $tmp . PHP_EOL;
|
||||
}
|
||||
|
||||
$o .= 'END:VEVENT' . PHP_EOL;
|
||||
|
@ -912,7 +911,7 @@ class Event
|
|||
}
|
||||
|
||||
// Construct the profile link (magic-auth).
|
||||
$author = [
|
||||
$author = [
|
||||
'uid' => 0,
|
||||
'id' => $item['author-id'],
|
||||
'network' => $item['author-network'],
|
||||
|
|
|
@ -39,44 +39,44 @@ use Psr\Http\Message\UriInterface;
|
|||
class GServer
|
||||
{
|
||||
// Directory types
|
||||
const DT_NONE = 0;
|
||||
const DT_POCO = 1;
|
||||
const DT_NONE = 0;
|
||||
const DT_POCO = 1;
|
||||
const DT_MASTODON = 2;
|
||||
|
||||
// Methods to detect server types
|
||||
|
||||
// Non endpoint specific methods
|
||||
const DETECT_MANUAL = 0;
|
||||
const DETECT_HEADER = 1;
|
||||
const DETECT_BODY = 2;
|
||||
const DETECT_HOST_META = 3;
|
||||
const DETECT_CONTACTS = 4;
|
||||
const DETECT_AP_ACTOR = 5;
|
||||
const DETECT_MANUAL = 0;
|
||||
const DETECT_HEADER = 1;
|
||||
const DETECT_BODY = 2;
|
||||
const DETECT_HOST_META = 3;
|
||||
const DETECT_CONTACTS = 4;
|
||||
const DETECT_AP_ACTOR = 5;
|
||||
const DETECT_AP_COLLECTION = 6;
|
||||
|
||||
const DETECT_UNSPECIFIC = [self::DETECT_MANUAL, self::DETECT_HEADER, self::DETECT_BODY, self::DETECT_HOST_META, self::DETECT_CONTACTS, self::DETECT_AP_ACTOR];
|
||||
|
||||
// Implementation specific endpoints
|
||||
// @todo Possibly add Lemmy detection via the endpoint /api/v3/site
|
||||
const DETECT_FRIENDIKA = 10;
|
||||
const DETECT_FRIENDICA = 11;
|
||||
const DETECT_STATUSNET = 12;
|
||||
const DETECT_GNUSOCIAL = 13;
|
||||
const DETECT_CONFIG_JSON = 14; // Statusnet, GNU Social, Older Hubzilla/Redmatrix
|
||||
const DETECT_FRIENDIKA = 10;
|
||||
const DETECT_FRIENDICA = 11;
|
||||
const DETECT_STATUSNET = 12;
|
||||
const DETECT_GNUSOCIAL = 13;
|
||||
const DETECT_CONFIG_JSON = 14; // Statusnet, GNU Social, Older Hubzilla/Redmatrix
|
||||
const DETECT_SITEINFO_JSON = 15; // Newer Hubzilla
|
||||
const DETECT_MASTODON_API = 16;
|
||||
const DETECT_STATUS_PHP = 17; // Nextcloud
|
||||
const DETECT_V1_CONFIG = 18;
|
||||
const DETECT_SYSTEM_ACTOR = 20; // Mistpark, Osada, Roadhouse, Zap
|
||||
const DETECT_THREADS = 21;
|
||||
const DETECT_MASTODON_API = 16;
|
||||
const DETECT_STATUS_PHP = 17; // Nextcloud
|
||||
const DETECT_V1_CONFIG = 18;
|
||||
const DETECT_SYSTEM_ACTOR = 20; // Mistpark, Osada, Roadhouse, Zap
|
||||
const DETECT_THREADS = 21;
|
||||
|
||||
// Standardized endpoints
|
||||
const DETECT_STATISTICS_JSON = 100;
|
||||
const DETECT_NODEINFO_10 = 101; // Nodeinfo Version 1.0
|
||||
const DETECT_NODEINFO_20 = 102; // Nodeinfo Version 2.0
|
||||
const DETECT_NODEINFO2_10 = 103; // Nodeinfo2 Version 1.0
|
||||
const DETECT_NODEINFO_21 = 104; // Nodeinfo Version 2.1
|
||||
const DETECT_NODEINFO_22 = 105; // Nodeinfo Version 2.2
|
||||
const DETECT_NODEINFO_10 = 101; // Nodeinfo Version 1.0
|
||||
const DETECT_NODEINFO_20 = 102; // Nodeinfo Version 2.0
|
||||
const DETECT_NODEINFO2_10 = 103; // Nodeinfo2 Version 1.0
|
||||
const DETECT_NODEINFO_21 = 104; // Nodeinfo Version 2.1
|
||||
const DETECT_NODEINFO_22 = 105; // Nodeinfo Version 2.2
|
||||
|
||||
/**
|
||||
* Check for the existence of a server and adds it in the background if not existant
|
||||
|
@ -343,7 +343,7 @@ class GServer
|
|||
$gserver = DBA::selectFirst('gserver', [], ['nurl' => Strings::normaliseLink($server_url)]);
|
||||
if (DBA::isResult($gserver)) {
|
||||
if ($gserver['created'] <= DBA::NULL_DATETIME) {
|
||||
$fields = ['created' => DateTimeFormat::utcNow()];
|
||||
$fields = ['created' => DateTimeFormat::utcNow()];
|
||||
$condition = ['nurl' => Strings::normaliseLink($server_url)];
|
||||
self::update($fields, $condition);
|
||||
}
|
||||
|
@ -450,9 +450,11 @@ class GServer
|
|||
$gserver = DBA::selectFirst('gserver', [], ['nurl' => $nurl]);
|
||||
if (DBA::isResult($gserver)) {
|
||||
$next_update = self::getNextUpdateDate(false, $gserver['created'], $gserver['last_contact']);
|
||||
self::update(['url' => $url, 'failed' => true, 'blocked' => Network::isUrlBlocked($url), 'last_failure' => DateTimeFormat::utcNow(),
|
||||
'next_contact' => $next_update, 'network' => Protocol::PHANTOM, 'detection-method' => null],
|
||||
['nurl' => $nurl]);
|
||||
self::update(
|
||||
['url' => $url, 'failed' => true, 'blocked' => Network::isUrlBlocked($url), 'last_failure' => DateTimeFormat::utcNow(),
|
||||
'next_contact' => $next_update, 'network' => Protocol::PHANTOM, 'detection-method' => null],
|
||||
['nurl' => $nurl]
|
||||
);
|
||||
DI::logger()->info('Set failed status for existing server', ['url' => $url]);
|
||||
if (self::isDefunct($gserver)) {
|
||||
self::archiveContacts($gserver['id']);
|
||||
|
@ -461,8 +463,8 @@ class GServer
|
|||
}
|
||||
|
||||
self::insert(['url' => $url, 'nurl' => $nurl,
|
||||
'network' => Protocol::PHANTOM, 'created' => DateTimeFormat::utcNow(),
|
||||
'failed' => true, 'last_failure' => DateTimeFormat::utcNow()]);
|
||||
'network' => Protocol::PHANTOM, 'created' => DateTimeFormat::utcNow(),
|
||||
'failed' => true, 'last_failure' => DateTimeFormat::utcNow()]);
|
||||
DI::logger()->info('Set failed status for new server', ['url' => $url]);
|
||||
}
|
||||
|
||||
|
@ -592,7 +594,7 @@ class GServer
|
|||
if ((parse_url($url, PHP_URL_HOST) == parse_url($valid_url, PHP_URL_HOST)) &&
|
||||
(parse_url($url, PHP_URL_PATH) == parse_url($valid_url, PHP_URL_PATH)) &&
|
||||
(parse_url($url, PHP_URL_SCHEME) != parse_url($valid_url, PHP_URL_SCHEME))) {
|
||||
$url = $valid_url;
|
||||
$url = $valid_url;
|
||||
}
|
||||
|
||||
$in_webroot = empty(parse_url($url, PHP_URL_PATH));
|
||||
|
@ -627,10 +629,10 @@ class GServer
|
|||
if ($serverdata['network'] == Protocol::PHANTOM) {
|
||||
if ($in_webroot) {
|
||||
// Fetch the landing page, possibly it reveals some data
|
||||
$accept = 'application/activity+json,application/ld+json,application/json,*/*;q=0.9';
|
||||
$accept = 'application/activity+json,application/ld+json,application/json,*/*;q=0.9';
|
||||
$curlResult = DI::httpClient()->get($url, $accept, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]);
|
||||
if (!$curlResult->isSuccess() && $curlResult->getReturnCode() == '406') {
|
||||
$curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]);
|
||||
$curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]);
|
||||
$html_fetched = true;
|
||||
} else {
|
||||
$html_fetched = false;
|
||||
|
@ -639,8 +641,8 @@ class GServer
|
|||
if ($curlResult->isSuccess()) {
|
||||
$json = json_decode($curlResult->getBodyString(), true);
|
||||
if (!empty($json) && is_array($json)) {
|
||||
$data = self::fetchDataFromSystemActor($json, $serverdata);
|
||||
$serverdata = $data['server'];
|
||||
$data = self::fetchDataFromSystemActor($json, $serverdata);
|
||||
$serverdata = $data['server'];
|
||||
$systemactor = $data['actor'];
|
||||
if (!$html_fetched && !in_array($serverdata['detection-method'], [self::DETECT_SYSTEM_ACTOR, self::DETECT_AP_COLLECTION])) {
|
||||
$curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]);
|
||||
|
@ -739,7 +741,7 @@ class GServer
|
|||
return false;
|
||||
}
|
||||
|
||||
$serverdata['url'] = $url;
|
||||
$serverdata['url'] = $url;
|
||||
$serverdata['nurl'] = Strings::normaliseLink($url);
|
||||
|
||||
// We have to prevent an endless loop here.
|
||||
|
@ -803,10 +805,10 @@ class GServer
|
|||
$gserver = DBA::selectFirst('gserver', ['network'], ['nurl' => Strings::normaliseLink($url)]);
|
||||
if (!DBA::isResult($gserver)) {
|
||||
$serverdata['created'] = DateTimeFormat::utcNow();
|
||||
$ret = self::insert($serverdata);
|
||||
$id = DBA::lastInsertId();
|
||||
$ret = self::insert($serverdata);
|
||||
$id = DBA::lastInsertId();
|
||||
} else {
|
||||
$ret = self::update($serverdata, ['nurl' => $serverdata['nurl']]);
|
||||
$ret = self::update($serverdata, ['nurl' => $serverdata['nurl']]);
|
||||
$gserver = DBA::selectFirst('gserver', ['id'], ['nurl' => $serverdata['nurl']]);
|
||||
if (DBA::isResult($gserver)) {
|
||||
$id = $gserver['id'];
|
||||
|
@ -816,8 +818,8 @@ class GServer
|
|||
// Count the number of known contacts from this server
|
||||
if (!empty($id) && !in_array($serverdata['network'], [Protocol::PHANTOM, Protocol::FEED])) {
|
||||
$apcontacts = DBA::count('apcontact', ['gsid' => $id]);
|
||||
$contacts = DBA::count('contact', ['uid' => 0, 'gsid' => $id, 'failed' => false]);
|
||||
$max_users = max($apcontacts, $contacts);
|
||||
$contacts = DBA::count('contact', ['uid' => 0, 'gsid' => $id, 'failed' => false]);
|
||||
$max_users = max($apcontacts, $contacts);
|
||||
if ($max_users > $serverdata['registered-users']) {
|
||||
DI::logger()->info('Update registered users', ['id' => $id, 'url' => $serverdata['nurl'], 'registered-users' => $max_users]);
|
||||
self::update(['registered-users' => $max_users], ['id' => $id]);
|
||||
|
@ -846,7 +848,7 @@ class GServer
|
|||
|
||||
if (!empty($systemactor)) {
|
||||
$contact = Contact::getByURL($systemactor, true, ['gsid', 'baseurl', 'id', 'network', 'url', 'name']);
|
||||
DI::logger()->debug('Fetched system actor', ['url' => $url, 'gsid' => $id, 'contact' => $contact]);
|
||||
DI::logger()->debug('Fetched system actor', ['url' => $url, 'gsid' => $id, 'contact' => $contact]);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
|
@ -879,9 +881,9 @@ class GServer
|
|||
$data['subscribe'] = (bool)($data['subscribe'] ?? false);
|
||||
|
||||
if (!$data['subscribe'] || empty($data['scope']) || !in_array(strtolower($data['scope']), ['all', 'tags'])) {
|
||||
$data['scope'] = '';
|
||||
$data['scope'] = '';
|
||||
$data['subscribe'] = false;
|
||||
$data['tags'] = [];
|
||||
$data['tags'] = [];
|
||||
}
|
||||
|
||||
$gserver = DBA::selectFirst('gserver', ['id', 'url', 'network', 'relay-subscribe', 'relay-scope'], ['nurl' => Strings::normaliseLink($server_url)]);
|
||||
|
@ -975,13 +977,13 @@ class GServer
|
|||
return $serverdata;
|
||||
}
|
||||
|
||||
$valid = false;
|
||||
$valid = false;
|
||||
$old_serverdata = $serverdata;
|
||||
|
||||
$serverdata['detection-method'] = self::DETECT_STATISTICS_JSON;
|
||||
|
||||
if (!empty($data['version'])) {
|
||||
$valid = true;
|
||||
$valid = true;
|
||||
$serverdata['version'] = $data['version'];
|
||||
// Version numbers on statistics.json are presented with additional info, e.g.:
|
||||
// 0.6.3.0-p1702cc1c, 0.6.99.0-p1b9ab160 or 3.4.3-2-1191.
|
||||
|
@ -989,12 +991,12 @@ class GServer
|
|||
}
|
||||
|
||||
if (!empty($data['name'])) {
|
||||
$valid = true;
|
||||
$valid = true;
|
||||
$serverdata['site_name'] = $data['name'];
|
||||
}
|
||||
|
||||
if (!empty($data['network'])) {
|
||||
$valid = true;
|
||||
$valid = true;
|
||||
$serverdata['platform'] = strtolower($data['network']);
|
||||
|
||||
if ($serverdata['platform'] == 'diaspora') {
|
||||
|
@ -1009,22 +1011,22 @@ class GServer
|
|||
}
|
||||
|
||||
if (!empty($data['total_users'])) {
|
||||
$valid = true;
|
||||
$valid = true;
|
||||
$serverdata['registered-users'] = max($data['total_users'], 1);
|
||||
}
|
||||
|
||||
if (!empty($data['active_users_monthly'])) {
|
||||
$valid = true;
|
||||
$valid = true;
|
||||
$serverdata['active-month-users'] = max($data['active_users_monthly'], 0);
|
||||
}
|
||||
|
||||
if (!empty($data['active_users_halfyear'])) {
|
||||
$valid = true;
|
||||
$valid = true;
|
||||
$serverdata['active-halfyear-users'] = max($data['active_users_halfyear'], 0);
|
||||
}
|
||||
|
||||
if (!empty($data['local_posts'])) {
|
||||
$valid = true;
|
||||
$valid = true;
|
||||
$serverdata['local-posts'] = max($data['local_posts'], 0);
|
||||
}
|
||||
|
||||
|
@ -1065,8 +1067,8 @@ class GServer
|
|||
return [];
|
||||
}
|
||||
|
||||
$nodeinfo1_url = '';
|
||||
$nodeinfo2_url = '';
|
||||
$nodeinfo1_url = '';
|
||||
$nodeinfo2_url = '';
|
||||
$detection_method = self::DETECT_MANUAL;
|
||||
|
||||
foreach ($nodeinfo['links'] as $link) {
|
||||
|
@ -1078,13 +1080,13 @@ class GServer
|
|||
if ($link['rel'] == 'http://nodeinfo.diaspora.software/ns/schema/1.0') {
|
||||
$nodeinfo1_url = Network::addBasePath($link['href'], $httpResult->getUrl());
|
||||
} elseif (($detection_method < self::DETECT_NODEINFO_20) && ($link['rel'] == 'http://nodeinfo.diaspora.software/ns/schema/2.0')) {
|
||||
$nodeinfo2_url = Network::addBasePath($link['href'], $httpResult->getUrl());
|
||||
$nodeinfo2_url = Network::addBasePath($link['href'], $httpResult->getUrl());
|
||||
$detection_method = self::DETECT_NODEINFO_20;
|
||||
} elseif (($detection_method < self::DETECT_NODEINFO_21) && ($link['rel'] == 'http://nodeinfo.diaspora.software/ns/schema/2.1')) {
|
||||
$nodeinfo2_url = Network::addBasePath($link['href'], $httpResult->getUrl());
|
||||
$nodeinfo2_url = Network::addBasePath($link['href'], $httpResult->getUrl());
|
||||
$detection_method = self::DETECT_NODEINFO_21;
|
||||
} elseif (($detection_method < self::DETECT_NODEINFO_22) && ($link['rel'] == 'http://nodeinfo.diaspora.software/ns/schema/2.2')) {
|
||||
$nodeinfo2_url = Network::addBasePath($link['href'], $httpResult->getUrl());
|
||||
$nodeinfo2_url = Network::addBasePath($link['href'], $httpResult->getUrl());
|
||||
$detection_method = self::DETECT_NODEINFO_22;
|
||||
}
|
||||
}
|
||||
|
@ -1132,7 +1134,7 @@ class GServer
|
|||
|
||||
$server = [
|
||||
'detection-method' => self::DETECT_NODEINFO_10,
|
||||
'register_policy' => Register::CLOSED
|
||||
'register_policy' => Register::CLOSED
|
||||
];
|
||||
|
||||
if (!empty($nodeinfo['openRegistrations'])) {
|
||||
|
@ -1232,8 +1234,8 @@ class GServer
|
|||
|
||||
$server = [
|
||||
'detection-method' => $detection_method,
|
||||
'register_policy' => Register::CLOSED,
|
||||
'platform' => 'unknown',
|
||||
'register_policy' => Register::CLOSED,
|
||||
'platform' => 'unknown',
|
||||
];
|
||||
|
||||
if (!empty($nodeinfo['openRegistrations'])) {
|
||||
|
@ -1363,7 +1365,7 @@ class GServer
|
|||
|
||||
$server = [
|
||||
'detection-method' => self::DETECT_NODEINFO2_10,
|
||||
'register_policy' => Register::CLOSED
|
||||
'register_policy' => Register::CLOSED
|
||||
];
|
||||
|
||||
if (!empty($nodeinfo['openRegistrations'])) {
|
||||
|
@ -1471,7 +1473,7 @@ class GServer
|
|||
|
||||
if (!empty($data['platform'])) {
|
||||
$serverdata['platform'] = strtolower($data['platform']);
|
||||
$serverdata['version'] = $data['version'] ?? 'N/A';
|
||||
$serverdata['version'] = $data['version'] ?? 'N/A';
|
||||
}
|
||||
|
||||
if (!empty($data['plugins'])) {
|
||||
|
@ -1547,17 +1549,17 @@ class GServer
|
|||
|
||||
$actor = JsonLD::compact($data, false);
|
||||
if (in_array(JsonLD::fetchElement($actor, '@type'), ActivityPub\Receiver::ACCOUNT_TYPES)) {
|
||||
$serverdata['network'] = Protocol::ACTIVITYPUB;
|
||||
$serverdata['network'] = Protocol::ACTIVITYPUB;
|
||||
$serverdata['site_name'] = JsonLD::fetchElement($actor, 'as:name', '@value');
|
||||
$serverdata['info'] = JsonLD::fetchElement($actor, 'as:summary', '@value');
|
||||
$serverdata['info'] = JsonLD::fetchElement($actor, 'as:summary', '@value');
|
||||
if (self::isNomad($actor)) {
|
||||
$serverdata['platform'] = self::getNomadName($actor['@id']);
|
||||
$serverdata['version'] = self::getNomadVersion($actor['@id']);
|
||||
$serverdata['platform'] = self::getNomadName($actor['@id']);
|
||||
$serverdata['version'] = self::getNomadVersion($actor['@id']);
|
||||
$serverdata['detection-method'] = self::DETECT_SYSTEM_ACTOR;
|
||||
} elseif (!empty($actor['as:generator'])) {
|
||||
$generator = explode(' ', JsonLD::fetchElement($actor['as:generator'], 'as:name', '@value'));
|
||||
$serverdata['platform'] = strtolower(array_shift($generator));
|
||||
$serverdata['version'] = self::getNomadVersion($actor['@id']);
|
||||
$generator = explode(' ', JsonLD::fetchElement($actor['as:generator'], 'as:name', '@value'));
|
||||
$serverdata['platform'] = strtolower(array_shift($generator));
|
||||
$serverdata['version'] = self::getNomadVersion($actor['@id']);
|
||||
$serverdata['detection-method'] = self::DETECT_SYSTEM_ACTOR;
|
||||
} else {
|
||||
$serverdata['detection-method'] = self::DETECT_AP_ACTOR;
|
||||
|
@ -1565,8 +1567,8 @@ class GServer
|
|||
return ['server' => $serverdata, 'actor' => $actor['@id']];
|
||||
} elseif ((JsonLD::fetchElement($actor, '@type') == 'as:Collection')) {
|
||||
// By now only Ktistec seems to provide collections this way
|
||||
$serverdata['platform'] = 'ktistec';
|
||||
$serverdata['network'] = Protocol::ACTIVITYPUB;
|
||||
$serverdata['platform'] = 'ktistec';
|
||||
$serverdata['network'] = Protocol::ACTIVITYPUB;
|
||||
$serverdata['detection-method'] = self::DETECT_AP_COLLECTION;
|
||||
|
||||
$actors = JsonLD::fetchElementArray($actor, 'as:items');
|
||||
|
@ -1610,7 +1612,7 @@ class GServer
|
|||
*/
|
||||
private static function getNomadName(string $url): string
|
||||
{
|
||||
$name = 'nomad';
|
||||
$name = 'nomad';
|
||||
$curlResult = DI::httpClient()->get($url . '/manifest', 'application/manifest+json', [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]);
|
||||
if (!$curlResult->isSuccess() || ($curlResult->getBodyString() == '')) {
|
||||
if ($curlResult->getReturnCode() == 418) {
|
||||
|
@ -1729,7 +1731,7 @@ class GServer
|
|||
private static function validHostMeta(string $url): bool
|
||||
{
|
||||
$xrd_timeout = DI::config()->get('system', 'xrd_timeout');
|
||||
$curlResult = DI::httpClient()->get($url . Probe::HOST_META, HttpClientAccept::XRD_XML, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]);
|
||||
$curlResult = DI::httpClient()->get($url . Probe::HOST_META, HttpClientAccept::XRD_XML, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]);
|
||||
if (!$curlResult->isSuccess()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1828,10 +1830,10 @@ class GServer
|
|||
}
|
||||
|
||||
if (!empty($data['totalResults'])) {
|
||||
$registeredUsers = $serverdata['registered-users'] ?? 0;
|
||||
$registeredUsers = $serverdata['registered-users'] ?? 0;
|
||||
$serverdata['registered-users'] = max($data['totalResults'], $registeredUsers, 1);
|
||||
$serverdata['directory-type'] = self::DT_POCO;
|
||||
$serverdata['poco'] = $url . '/poco';
|
||||
$serverdata['directory-type'] = self::DT_POCO;
|
||||
$serverdata['poco'] = $url . '/poco';
|
||||
}
|
||||
|
||||
return $serverdata;
|
||||
|
@ -1886,8 +1888,8 @@ class GServer
|
|||
|
||||
if (!empty($data['instance']) && !empty($data['serverVersion'])) {
|
||||
$serverdata['platform'] = 'peertube';
|
||||
$serverdata['version'] = $data['serverVersion'];
|
||||
$serverdata['network'] = Protocol::ACTIVITYPUB;
|
||||
$serverdata['version'] = $data['serverVersion'];
|
||||
$serverdata['network'] = Protocol::ACTIVITYPUB;
|
||||
|
||||
if (!empty($data['instance']['name'])) {
|
||||
$serverdata['site_name'] = $data['instance']['name'];
|
||||
|
@ -1934,7 +1936,7 @@ class GServer
|
|||
|
||||
if (!empty($data['version'])) {
|
||||
$serverdata['platform'] = 'nextcloud';
|
||||
$serverdata['version'] = $data['version'];
|
||||
$serverdata['version'] = $data['version'];
|
||||
|
||||
if ($validHostMeta) {
|
||||
$serverdata['network'] = Protocol::ACTIVITYPUB;
|
||||
|
@ -2012,9 +2014,9 @@ class GServer
|
|||
|
||||
if (!empty($data['version'])) {
|
||||
$serverdata['platform'] = 'mastodon';
|
||||
$serverdata['version'] = $data['version'] ?? '';
|
||||
$serverdata['network'] = Protocol::ACTIVITYPUB;
|
||||
$valid = true;
|
||||
$serverdata['version'] = $data['version'] ?? '';
|
||||
$serverdata['network'] = Protocol::ACTIVITYPUB;
|
||||
$valid = true;
|
||||
}
|
||||
|
||||
if (!empty($data['title'])) {
|
||||
|
@ -2023,8 +2025,8 @@ class GServer
|
|||
|
||||
if (!empty($data['title']) && empty($serverdata['platform']) && ($serverdata['network'] == Protocol::PHANTOM)) {
|
||||
$serverdata['platform'] = 'mastodon';
|
||||
$serverdata['network'] = Protocol::ACTIVITYPUB;
|
||||
$valid = true;
|
||||
$serverdata['network'] = Protocol::ACTIVITYPUB;
|
||||
$valid = true;
|
||||
}
|
||||
|
||||
if (!empty($data['description'])) {
|
||||
|
@ -2037,20 +2039,20 @@ class GServer
|
|||
|
||||
if (!empty($serverdata['version']) && preg_match('/.*?\(compatible;\s(.*)\s(.*)\)/ism', $serverdata['version'], $matches)) {
|
||||
$serverdata['platform'] = strtolower($matches[1]);
|
||||
$serverdata['version'] = $matches[2];
|
||||
$valid = true;
|
||||
$serverdata['version'] = $matches[2];
|
||||
$valid = true;
|
||||
}
|
||||
|
||||
if (!empty($serverdata['version']) && strstr(strtolower($serverdata['version']), 'pleroma')) {
|
||||
$serverdata['platform'] = 'pleroma';
|
||||
$serverdata['version'] = trim(str_ireplace('pleroma', '', $serverdata['version']));
|
||||
$valid = true;
|
||||
$serverdata['version'] = trim(str_ireplace('pleroma', '', $serverdata['version']));
|
||||
$valid = true;
|
||||
}
|
||||
|
||||
if (!empty($serverdata['platform']) && strstr($serverdata['platform'], 'pleroma')) {
|
||||
$serverdata['version'] = trim(str_ireplace('pleroma', '', $serverdata['platform']));
|
||||
$serverdata['version'] = trim(str_ireplace('pleroma', '', $serverdata['platform']));
|
||||
$serverdata['platform'] = 'pleroma';
|
||||
$valid = true;
|
||||
$valid = true;
|
||||
}
|
||||
|
||||
if ($valid && in_array($serverdata['detection-method'], self::DETECT_UNSPECIFIC)) {
|
||||
|
@ -2086,14 +2088,14 @@ class GServer
|
|||
|
||||
if (!empty($data['site']['platform'])) {
|
||||
$serverdata['platform'] = strtolower($data['site']['platform']['PLATFORM_NAME']);
|
||||
$serverdata['version'] = $data['site']['platform']['STD_VERSION'];
|
||||
$serverdata['network'] = Protocol::ZOT;
|
||||
$serverdata['version'] = $data['site']['platform']['STD_VERSION'];
|
||||
$serverdata['network'] = Protocol::ZOT;
|
||||
}
|
||||
|
||||
if (!empty($data['site']['hubzilla'])) {
|
||||
$serverdata['platform'] = strtolower($data['site']['hubzilla']['PLATFORM_NAME']);
|
||||
$serverdata['version'] = $data['site']['hubzilla']['RED_VERSION'];
|
||||
$serverdata['network'] = Protocol::ZOT;
|
||||
$serverdata['version'] = $data['site']['hubzilla']['RED_VERSION'];
|
||||
$serverdata['network'] = Protocol::ZOT;
|
||||
}
|
||||
|
||||
if (!empty($data['site']['redmatrix'])) {
|
||||
|
@ -2107,9 +2109,9 @@ class GServer
|
|||
$serverdata['network'] = Protocol::ZOT;
|
||||
}
|
||||
|
||||
$private = false;
|
||||
$private = false;
|
||||
$inviteonly = false;
|
||||
$closed = false;
|
||||
$closed = false;
|
||||
|
||||
if (!empty($data['site']['closed'])) {
|
||||
$closed = self::toBoolean($data['site']['closed']);
|
||||
|
@ -2196,11 +2198,11 @@ class GServer
|
|||
|
||||
if (!empty($serverdata['version']) && strtolower(substr($serverdata['version'], 0, 7)) == 'pleroma') {
|
||||
$serverdata['platform'] = 'pleroma';
|
||||
$serverdata['version'] = trim(str_ireplace('pleroma', '', $serverdata['version']));
|
||||
$serverdata['network'] = Protocol::ACTIVITYPUB;
|
||||
$serverdata['version'] = trim(str_ireplace('pleroma', '', $serverdata['version']));
|
||||
$serverdata['network'] = Protocol::ACTIVITYPUB;
|
||||
} else {
|
||||
$serverdata['platform'] = 'statusnet';
|
||||
$serverdata['network'] = Protocol::OSTATUS;
|
||||
$serverdata['network'] = Protocol::OSTATUS;
|
||||
}
|
||||
|
||||
if (in_array($serverdata['detection-method'], self::DETECT_UNSPECIFIC)) {
|
||||
|
@ -2226,11 +2228,11 @@ class GServer
|
|||
$curlResult = DI::httpClient()->get($url . '/friendica/json', HttpClientAccept::DEFAULT, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]);
|
||||
if (!$curlResult->isSuccess()) {
|
||||
$curlResult = DI::httpClient()->get($url . '/friendika/json', HttpClientAccept::DEFAULT, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]);
|
||||
$friendika = true;
|
||||
$platform = 'Friendika';
|
||||
$friendika = true;
|
||||
$platform = 'Friendika';
|
||||
} else {
|
||||
$friendika = false;
|
||||
$platform = 'Friendica';
|
||||
$platform = 'Friendica';
|
||||
}
|
||||
|
||||
if (!$curlResult->isSuccess()) {
|
||||
|
@ -2316,14 +2318,14 @@ class GServer
|
|||
|
||||
$doc = new DOMDocument();
|
||||
@$doc->loadHTML($curlResult->getBodyString());
|
||||
$xpath = new DOMXPath($doc);
|
||||
$xpath = new DOMXPath($doc);
|
||||
$assigned = false;
|
||||
|
||||
// We can only detect honk via some HTML element on their page
|
||||
if ($xpath->query('//div[@id="honksonpage"]')->count() == 1) {
|
||||
$serverdata['platform'] = 'honk';
|
||||
$serverdata['network'] = Protocol::ACTIVITYPUB;
|
||||
$assigned = true;
|
||||
$serverdata['network'] = Protocol::ACTIVITYPUB;
|
||||
$assigned = true;
|
||||
}
|
||||
|
||||
$title = trim(XML::getFirstNodeValue($xpath, '//head/title/text()'));
|
||||
|
@ -2356,11 +2358,11 @@ class GServer
|
|||
|
||||
if (in_array($attr['name'], ['application-name', 'al:android:app_name', 'al:ios:app_name',
|
||||
'twitter:app:name:googleplay', 'twitter:app:name:iphone', 'twitter:app:name:ipad', 'generator'])) {
|
||||
$platform = str_ireplace(array_keys($platforms), array_values($platforms), $attr['content']);
|
||||
$platform = str_replace('/', ' ', $platform);
|
||||
$platform = str_ireplace(array_keys($platforms), array_values($platforms), $attr['content']);
|
||||
$platform = str_replace('/', ' ', $platform);
|
||||
$platform_parts = explode(' ', $platform);
|
||||
if ((count($platform_parts) >= 2) && in_array(strtolower($platform_parts[0]), array_values($platforms))) {
|
||||
$platform = $platform_parts[0];
|
||||
$platform = $platform_parts[0];
|
||||
$serverdata['version'] = $platform_parts[1];
|
||||
}
|
||||
if (in_array($platform, array_values($grouped_platforms['dfrn_platforms']))) {
|
||||
|
@ -2372,7 +2374,7 @@ class GServer
|
|||
}
|
||||
if (in_array($platform, array_values($platforms))) {
|
||||
$serverdata['platform'] = $platform;
|
||||
$assigned = true;
|
||||
$assigned = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2407,7 +2409,7 @@ class GServer
|
|||
if (in_array($attr['property'], ['og:platform', 'generator'])) {
|
||||
if (in_array($attr['content'], array_keys($platforms))) {
|
||||
$serverdata['platform'] = $platforms[$attr['content']];
|
||||
$assigned = true;
|
||||
$assigned = true;
|
||||
}
|
||||
|
||||
if (in_array($attr['content'], array_keys($grouped_platforms['ap_platforms']))) {
|
||||
|
@ -2422,10 +2424,10 @@ class GServer
|
|||
foreach ($list as $node) {
|
||||
foreach ($node->attributes as $attribute) {
|
||||
if (parse_url(trim($attribute->value), PHP_URL_HOST) == 'micro.blog') {
|
||||
$serverdata['version'] = trim($serverdata['platform'] . ' ' . $serverdata['version']);
|
||||
$serverdata['version'] = trim($serverdata['platform'] . ' ' . $serverdata['version']);
|
||||
$serverdata['platform'] = 'microblog';
|
||||
$serverdata['network'] = Protocol::ACTIVITYPUB;
|
||||
$assigned = true;
|
||||
$serverdata['network'] = Protocol::ACTIVITYPUB;
|
||||
$assigned = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2435,10 +2437,10 @@ class GServer
|
|||
foreach ($list as $node) {
|
||||
foreach ($node->attributes as $attribute) {
|
||||
if (trim($attribute->value) == 'https://micro.blog/micropub') {
|
||||
$serverdata['version'] = trim($serverdata['platform'] . ' ' . $serverdata['version']);
|
||||
$serverdata['version'] = trim($serverdata['platform'] . ' ' . $serverdata['version']);
|
||||
$serverdata['platform'] = 'microblog';
|
||||
$serverdata['network'] = Protocol::ACTIVITYPUB;
|
||||
$assigned = true;
|
||||
$serverdata['network'] = Protocol::ACTIVITYPUB;
|
||||
$assigned = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2463,15 +2465,15 @@ class GServer
|
|||
{
|
||||
if ($curlResult->getHeader('server') == 'Mastodon') {
|
||||
$serverdata['platform'] = 'mastodon';
|
||||
$serverdata['network'] = Protocol::ACTIVITYPUB;
|
||||
$serverdata['network'] = Protocol::ACTIVITYPUB;
|
||||
} elseif ($curlResult->inHeader('x-diaspora-version')) {
|
||||
$serverdata['platform'] = 'diaspora';
|
||||
$serverdata['network'] = Protocol::DIASPORA;
|
||||
$serverdata['version'] = $curlResult->getHeader('x-diaspora-version')[0] ?? '';
|
||||
$serverdata['network'] = Protocol::DIASPORA;
|
||||
$serverdata['version'] = $curlResult->getHeader('x-diaspora-version')[0] ?? '';
|
||||
} elseif ($curlResult->inHeader('x-friendica-version')) {
|
||||
$serverdata['platform'] = 'friendica';
|
||||
$serverdata['network'] = Protocol::DFRN;
|
||||
$serverdata['version'] = $curlResult->getHeader('x-friendica-version')[0] ?? '';
|
||||
$serverdata['network'] = Protocol::DFRN;
|
||||
$serverdata['version'] = $curlResult->getHeader('x-friendica-version')[0] ?? '';
|
||||
} else {
|
||||
return $serverdata;
|
||||
}
|
||||
|
@ -2501,9 +2503,12 @@ class GServer
|
|||
|
||||
$last_update = date('c', time() - (60 * 60 * 24 * $requery_days));
|
||||
|
||||
$gservers = DBA::select('gserver', ['id', 'url', 'nurl', 'network', 'poco', 'directory-type'],
|
||||
$gservers = DBA::select(
|
||||
'gserver',
|
||||
['id', 'url', 'nurl', 'network', 'poco', 'directory-type'],
|
||||
["NOT `blocked` AND NOT `failed` AND `directory-type` != ? AND `last_poco_query` < ?", GServer::DT_NONE, $last_update],
|
||||
['order' => ['RAND()']]);
|
||||
['order' => ['RAND()']]
|
||||
);
|
||||
|
||||
while ($gserver = DBA::fetch($gservers)) {
|
||||
DI::logger()->info('Update peer list', ['server' => $gserver['url'], 'id' => $gserver['id']]);
|
||||
|
@ -2541,7 +2546,7 @@ class GServer
|
|||
// Discover federated servers
|
||||
$protocols = ['activitypub', 'diaspora', 'dfrn', 'ostatus'];
|
||||
foreach ($protocols as $protocol) {
|
||||
$query = '{nodes(protocol:"' . $protocol . '"){host}}';
|
||||
$query = '{nodes(protocol:"' . $protocol . '"){host}}';
|
||||
$curlResult = DI::httpClient()->fetch('https://the-federation.info/graphql?query=' . urlencode($query), HttpClientAccept::JSON, 0, '', HttpClientRequest::SERVERDISCOVER);
|
||||
if (!empty($curlResult)) {
|
||||
$data = json_decode($curlResult, true);
|
||||
|
@ -2558,7 +2563,7 @@ class GServer
|
|||
$accesstoken = DI::config()->get('system', 'instances_social_key');
|
||||
|
||||
if (!empty($accesstoken)) {
|
||||
$api = 'https://instances.social/api/1.0/instances/list?count=0';
|
||||
$api = 'https://instances.social/api/1.0/instances/list?count=0';
|
||||
$curlResult = DI::httpClient()->get($api, HttpClientAccept::JSON, [HttpClientOptions::HEADERS => ['Authorization' => ['Bearer ' . $accesstoken], HttpClientOptions::REQUEST => HttpClientRequest::SERVERDISCOVER]]);
|
||||
if ($curlResult->isSuccess()) {
|
||||
$servers = json_decode($curlResult->getBodyString(), true);
|
||||
|
|
|
@ -45,38 +45,38 @@ use LanguageDetection\Language;
|
|||
class Item
|
||||
{
|
||||
// Posting types, inspired by https://www.w3.org/TR/activitystreams-vocabulary/#object-types
|
||||
const PT_ARTICLE = 0;
|
||||
const PT_NOTE = 1;
|
||||
const PT_PAGE = 2;
|
||||
const PT_IMAGE = 16;
|
||||
const PT_AUDIO = 17;
|
||||
const PT_VIDEO = 18;
|
||||
const PT_DOCUMENT = 19;
|
||||
const PT_EVENT = 32;
|
||||
const PT_POLL = 33;
|
||||
const PT_ARTICLE = 0;
|
||||
const PT_NOTE = 1;
|
||||
const PT_PAGE = 2;
|
||||
const PT_IMAGE = 16;
|
||||
const PT_AUDIO = 17;
|
||||
const PT_VIDEO = 18;
|
||||
const PT_DOCUMENT = 19;
|
||||
const PT_EVENT = 32;
|
||||
const PT_POLL = 33;
|
||||
const PT_PERSONAL_NOTE = 128;
|
||||
|
||||
// Posting reasons (Why had a post been stored for a user?)
|
||||
const PR_NONE = 0;
|
||||
const PR_TAG = 64;
|
||||
const PR_TO = 65;
|
||||
const PR_CC = 66;
|
||||
const PR_BTO = 67;
|
||||
const PR_BCC = 68;
|
||||
const PR_FOLLOWER = 69;
|
||||
const PR_NONE = 0;
|
||||
const PR_TAG = 64;
|
||||
const PR_TO = 65;
|
||||
const PR_CC = 66;
|
||||
const PR_BTO = 67;
|
||||
const PR_BCC = 68;
|
||||
const PR_FOLLOWER = 69;
|
||||
const PR_ANNOUNCEMENT = 70;
|
||||
const PR_COMMENT = 71;
|
||||
const PR_STORED = 72;
|
||||
const PR_GLOBAL = 73;
|
||||
const PR_RELAY = 74;
|
||||
const PR_FETCHED = 75;
|
||||
const PR_COMPLETION = 76;
|
||||
const PR_DIRECT = 77;
|
||||
const PR_ACTIVITY = 78;
|
||||
const PR_DISTRIBUTE = 79;
|
||||
const PR_PUSHED = 80;
|
||||
const PR_LOCAL = 81;
|
||||
const PR_AUDIENCE = 82;
|
||||
const PR_COMMENT = 71;
|
||||
const PR_STORED = 72;
|
||||
const PR_GLOBAL = 73;
|
||||
const PR_RELAY = 74;
|
||||
const PR_FETCHED = 75;
|
||||
const PR_COMPLETION = 76;
|
||||
const PR_DIRECT = 77;
|
||||
const PR_ACTIVITY = 78;
|
||||
const PR_DISTRIBUTE = 79;
|
||||
const PR_PUSHED = 80;
|
||||
const PR_LOCAL = 81;
|
||||
const PR_AUDIENCE = 82;
|
||||
|
||||
// system.accept_only_sharer setting values
|
||||
const COMPLETION_NONE = 1;
|
||||
|
@ -145,8 +145,8 @@ class Item
|
|||
];
|
||||
|
||||
// Privacy levels
|
||||
const PUBLIC = 0;
|
||||
const PRIVATE = 1;
|
||||
const PUBLIC = 0;
|
||||
const PRIVATE = 1;
|
||||
const UNLISTED = 2;
|
||||
|
||||
// Item weight for query ordering
|
||||
|
@ -492,7 +492,7 @@ class Item
|
|||
|
||||
// Is it in the format data@host.tld? - Used for mail contacts
|
||||
if (empty($prefix_host) && !empty($item['author-link']) && strstr($item['author-link'], '@')) {
|
||||
$mailparts = explode('@', $item['author-link']);
|
||||
$mailparts = explode('@', $item['author-link']);
|
||||
$prefix_host = array_pop($mailparts);
|
||||
}
|
||||
}
|
||||
|
@ -596,7 +596,7 @@ class Item
|
|||
}
|
||||
|
||||
$condition = [
|
||||
'uri-id' => $item['uri-id'], 'uid' => $item['uid'],
|
||||
'uri-id' => $item['uri-id'], 'uid' => $item['uid'],
|
||||
'network' => [$item['network'], Protocol::DFRN]
|
||||
];
|
||||
if (Post::exists($condition)) {
|
||||
|
@ -681,7 +681,7 @@ class Item
|
|||
}
|
||||
|
||||
$condition = [
|
||||
'verb' => Activity::FOLLOW, 'uid' => $item['uid'],
|
||||
'verb' => Activity::FOLLOW, 'uid' => $item['uid'],
|
||||
'parent-uri' => $item['parent-uri'], 'author-id' => $item['author-id']
|
||||
];
|
||||
if (Post::exists($condition)) {
|
||||
|
@ -716,10 +716,10 @@ class Item
|
|||
// We only log the entries with a different user id than 0. Otherwise we would have too many false positives
|
||||
if ($item['uid'] != 0) {
|
||||
DI::logger()->notice('Item already existed for user', [
|
||||
'uri-id' => $item['uri-id'],
|
||||
'uid' => $item['uid'],
|
||||
'network' => $item['network'],
|
||||
'existing_id' => $existing['id'],
|
||||
'uri-id' => $item['uri-id'],
|
||||
'uid' => $item['uid'],
|
||||
'network' => $item['network'],
|
||||
'existing_id' => $existing['id'],
|
||||
'existing_network' => $existing['network']
|
||||
]);
|
||||
}
|
||||
|
@ -766,8 +766,8 @@ class Item
|
|||
'wall', 'private', 'origin', 'author-id'
|
||||
];
|
||||
$condition = ['uri-id' => [$item['thr-parent-id'], $item['parent-uri-id']], 'uid' => $item['uid']];
|
||||
$params = ['order' => ['id' => false]];
|
||||
$parent = Post::selectFirst($fields, $condition, $params);
|
||||
$params = ['order' => ['id' => false]];
|
||||
$parent = Post::selectFirst($fields, $condition, $params);
|
||||
|
||||
if (!DBA::isResult($parent) && Post::exists(['uri-id' => [$item['thr-parent-id'], $item['parent-uri-id']], 'uid' => 0])) {
|
||||
$stored = Item::storeForUserByUriId($item['thr-parent-id'], $item['uid'], ['post-reason' => Item::PR_COMPLETION]);
|
||||
|
@ -795,11 +795,11 @@ class Item
|
|||
}
|
||||
|
||||
$condition = [
|
||||
'uri-id' => $parent['parent-uri-id'],
|
||||
'uri-id' => $parent['parent-uri-id'],
|
||||
'parent-uri-id' => $parent['parent-uri-id'],
|
||||
'uid' => $parent['uid']
|
||||
'uid' => $parent['uid']
|
||||
];
|
||||
$params = ['order' => ['id' => false]];
|
||||
$params = ['order' => ['id' => false]];
|
||||
$toplevel_parent = Post::selectFirst($fields, $condition, $params);
|
||||
|
||||
if (!DBA::isResult($toplevel_parent) && $item['origin']) {
|
||||
|
@ -884,7 +884,7 @@ class Item
|
|||
$uid = intval($item['uid']);
|
||||
|
||||
$item['guid'] = self::guid($item, $notify);
|
||||
$item['uri'] = substr(trim($item['uri'] ?? '') ?: self::newURI($item['guid']), 0, 255);
|
||||
$item['uri'] = substr(trim($item['uri'] ?? '') ?: self::newURI($item['guid']), 0, 255);
|
||||
|
||||
// Store URI data
|
||||
$item['uri-id'] = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]);
|
||||
|
@ -990,13 +990,13 @@ class Item
|
|||
$item['gravity'] = self::getGravity($item);
|
||||
|
||||
$default = [
|
||||
'url' => $item['author-link'], 'name' => $item['author-name'],
|
||||
'url' => $item['author-link'], 'name' => $item['author-name'],
|
||||
'photo' => $item['author-avatar'], 'network' => $item['network']
|
||||
];
|
||||
$item['author-id'] = ($item['author-id'] ?? 0) ?: Contact::getIdForURL($item['author-link'], 0, null, $default);
|
||||
|
||||
$default = [
|
||||
'url' => $item['owner-link'], 'name' => $item['owner-name'],
|
||||
'url' => $item['owner-link'], 'name' => $item['owner-name'],
|
||||
'photo' => $item['owner-avatar'], 'network' => $item['network']
|
||||
];
|
||||
$item['owner-id'] = ($item['owner-id'] ?? 0) ?: Contact::getIdForURL($item['owner-link'], 0, null, $default);
|
||||
|
@ -1072,7 +1072,7 @@ class Item
|
|||
// Update the contact relations
|
||||
Contact\Relation::store($toplevel_parent['author-id'], $item['author-id'], $item['created']);
|
||||
} else {
|
||||
$parent_id = 0;
|
||||
$parent_id = 0;
|
||||
$parent_origin = $item['origin'];
|
||||
|
||||
if ($item['wall'] && empty($item['context'])) {
|
||||
|
@ -1120,7 +1120,7 @@ class Item
|
|||
}
|
||||
|
||||
if ($notify && $post_local) {
|
||||
$item['edit'] = false;
|
||||
$item['edit'] = false;
|
||||
$item['parent'] = $parent_id;
|
||||
|
||||
// Trigger automatic reactions for addons
|
||||
|
@ -1131,8 +1131,8 @@ class Item
|
|||
// We have to tell the hooks who we are - this really should be improved
|
||||
if (!DI::userSession()->getLocalUserId()) {
|
||||
$_SESSION['authenticated'] = true;
|
||||
$_SESSION['uid'] = $uid;
|
||||
$dummy_session = true;
|
||||
$_SESSION['uid'] = $uid;
|
||||
$dummy_session = true;
|
||||
} else {
|
||||
$dummy_session = false;
|
||||
}
|
||||
|
@ -1250,9 +1250,9 @@ class Item
|
|||
$ev['guid'] = $item['guid'];
|
||||
$ev['plink'] = $item['plink'];
|
||||
$ev['network'] = $item['network'];
|
||||
$ev['protocol'] = $item['protocol'] ?? Conversation::PARCEL_UNKNOWN;
|
||||
$ev['protocol'] = $item['protocol'] ?? Conversation::PARCEL_UNKNOWN;
|
||||
$ev['direction'] = $item['direction'] ?? Conversation::UNKNOWN;
|
||||
$ev['source'] = $item['source'] ?? '';
|
||||
$ev['source'] = $item['source'] ?? '';
|
||||
|
||||
$event = DBA::selectFirst('event', ['id'], ['uri' => $item['uri'], 'uid' => $item['uid']]);
|
||||
if (DBA::isResult($event)) {
|
||||
|
@ -1260,7 +1260,7 @@ class Item
|
|||
}
|
||||
|
||||
$event_id = Event::store($ev);
|
||||
$item = Event::getItemArrayForImportedId($event_id, $item);
|
||||
$item = Event::getItemArrayForImportedId($event_id, $item);
|
||||
|
||||
DI::logger()->info('Event was stored', ['id' => $event_id]);
|
||||
}
|
||||
|
@ -1542,7 +1542,7 @@ class Item
|
|||
$count = 0;
|
||||
foreach (DI::userDefinedChannel()->getMatchingChannelUsers($engagement['searchtext'], $language, $tags, $engagement['media-type'], $item['owner-id'], $reshare_id) as $uid) {
|
||||
$condition = [
|
||||
'verb' => Activity::ANNOUNCE, 'deleted' => false, 'gravity' => self::GRAVITY_ACTIVITY,
|
||||
'verb' => Activity::ANNOUNCE, 'deleted' => false, 'gravity' => self::GRAVITY_ACTIVITY,
|
||||
'author-id' => Contact::getPublicIdByUserId($uid), 'uid' => $uid, 'thr-parent-id' => $uri_id
|
||||
];
|
||||
if (!Post::exists($condition)) {
|
||||
|
@ -1632,7 +1632,7 @@ class Item
|
|||
}
|
||||
|
||||
$self_contact = Contact::selectFirst(['id'], ['uid' => $item['uid'], 'self' => true]);
|
||||
$self = !empty($self_contact) ? $self_contact['id'] : 0;
|
||||
$self = !empty($self_contact) ? $self_contact['id'] : 0;
|
||||
|
||||
$cid = Contact::getIdForURL($author['url'], $item['uid']);
|
||||
if (empty($cid) || (!Contact::isSharing($cid, $item['uid']) && ($cid != $self))) {
|
||||
|
@ -1671,7 +1671,7 @@ class Item
|
|||
|
||||
foreach (Tag::getUIDListByURIId($item['uri-id']) as $uid => $tags) {
|
||||
if (!empty($languages)) {
|
||||
$keep = false;
|
||||
$keep = false;
|
||||
$user_languages = User::getWantedLanguages($uid);
|
||||
foreach ($user_languages as $language) {
|
||||
if (in_array($language, $languages)) {
|
||||
|
@ -1705,7 +1705,7 @@ class Item
|
|||
public static function distribute(int $itemid, string $signed_text = '')
|
||||
{
|
||||
$condition = ["`id` IN (SELECT `parent` FROM `post-user-view` WHERE `id` = ?)", $itemid];
|
||||
$parent = Post::selectFirst(['owner-id'], $condition);
|
||||
$parent = Post::selectFirst(['owner-id'], $condition);
|
||||
if (!DBA::isResult($parent)) {
|
||||
DI::logger()->warning('Item not found', ['condition' => $condition]);
|
||||
return;
|
||||
|
@ -1713,7 +1713,7 @@ class Item
|
|||
|
||||
// Only distribute public items from native networks
|
||||
$condition = [
|
||||
'id' => $itemid, 'uid' => 0,
|
||||
'id' => $itemid, 'uid' => 0,
|
||||
'network' => array_merge(Protocol::FEDERATED, ['']),
|
||||
'visible' => true, 'deleted' => false, 'private' => [self::PUBLIC, self::UNLISTED]
|
||||
];
|
||||
|
@ -1734,7 +1734,7 @@ class Item
|
|||
}
|
||||
|
||||
$condition = ['nurl' => $owner['nurl'], 'rel' => [Contact::SHARING, Contact::FRIEND]];
|
||||
$contacts = DBA::select('contact', ['uid'], $condition);
|
||||
$contacts = DBA::select('contact', ['uid'], $condition);
|
||||
while ($contact = DBA::fetch($contacts)) {
|
||||
if ($contact['uid'] == 0) {
|
||||
continue;
|
||||
|
@ -1745,7 +1745,7 @@ class Item
|
|||
DBA::close($contacts);
|
||||
|
||||
$condition = ['alias' => $owner['url'], 'rel' => [Contact::SHARING, Contact::FRIEND]];
|
||||
$contacts = DBA::select('contact', ['uid'], $condition);
|
||||
$contacts = DBA::select('contact', ['uid'], $condition);
|
||||
while ($contact = DBA::fetch($contacts)) {
|
||||
if ($contact['uid'] == 0) {
|
||||
continue;
|
||||
|
@ -1757,7 +1757,7 @@ class Item
|
|||
|
||||
if (!empty($owner['alias'])) {
|
||||
$condition = ['nurl' => Strings::normaliseLink($owner['alias']), 'rel' => [Contact::SHARING, Contact::FRIEND]];
|
||||
$contacts = DBA::select('contact', ['uid'], $condition);
|
||||
$contacts = DBA::select('contact', ['uid'], $condition);
|
||||
while ($contact = DBA::fetch($contacts)) {
|
||||
if ($contact['uid'] == 0) {
|
||||
continue;
|
||||
|
@ -1979,21 +1979,21 @@ class Item
|
|||
unset($item['postopts']);
|
||||
unset($item['inform']);
|
||||
|
||||
$item['uid'] = $uid;
|
||||
$item['uid'] = $uid;
|
||||
$item['origin'] = 0;
|
||||
$item['wall'] = 0;
|
||||
$item['wall'] = 0;
|
||||
|
||||
$notify = false;
|
||||
if ($item['gravity'] == self::GRAVITY_PARENT) {
|
||||
$contact = DBA::selectFirst('contact', [], ['id' => $item['contact-id'], 'self' => false]);
|
||||
if (DBA::isResult($contact)) {
|
||||
$notify = self::isRemoteSelf($contact, $item);
|
||||
$notify = self::isRemoteSelf($contact, $item);
|
||||
$item['wall'] = (bool)$notify;
|
||||
}
|
||||
}
|
||||
|
||||
$item['contact-id'] = self::contactId($item);
|
||||
$distributed = self::insert($item, $notify);
|
||||
$distributed = self::insert($item, $notify);
|
||||
|
||||
if (!$distributed) {
|
||||
DI::logger()->info("Distributed item wasn't stored", ['uri-id' => $item['uri-id'], 'user' => $uid]);
|
||||
|
@ -2015,9 +2015,9 @@ class Item
|
|||
*/
|
||||
private static function addShadow(int $itemid)
|
||||
{
|
||||
$fields = ['uid', 'private', 'visible', 'deleted', 'network', 'uri-id'];
|
||||
$fields = ['uid', 'private', 'visible', 'deleted', 'network', 'uri-id'];
|
||||
$condition = ['id' => $itemid, 'gravity' => self::GRAVITY_PARENT];
|
||||
$item = Post::selectFirst($fields, $condition);
|
||||
$item = Post::selectFirst($fields, $condition);
|
||||
|
||||
if (!DBA::isResult($item)) {
|
||||
return;
|
||||
|
@ -2029,7 +2029,7 @@ class Item
|
|||
}
|
||||
|
||||
// Is it a visible public post?
|
||||
if (!$item["visible"] || $item["deleted"] || ($item["private"] == self::PRIVATE)) {
|
||||
if (!$item["visible"] || $item["deleted"] || ($item["private"] == self::PRIVATE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2146,7 +2146,7 @@ class Item
|
|||
}
|
||||
|
||||
$transmitted = [];
|
||||
foreach ($item['transmitted-languages'] ?? [] as $language) {
|
||||
foreach ($item['transmitted-languages'] ?? [] as $language) {
|
||||
$transmitted[$language] = 0;
|
||||
}
|
||||
|
||||
|
@ -2279,10 +2279,10 @@ class Item
|
|||
$previous_block = self::getBlockCode($previous);
|
||||
}
|
||||
|
||||
$block = (($next != '') && \IntlChar::isalpha($next)) ? self::getBlockCode($next) : $previous_block;
|
||||
$block = (($next != '') && \IntlChar::isalpha($next)) ? self::getBlockCode($next) : $previous_block;
|
||||
$blocks[$block] = ($blocks[$block] ?? '') . $character;
|
||||
} else {
|
||||
$block = self::getBlockCode($character);
|
||||
$block = self::getBlockCode($character);
|
||||
$blocks[$block] = ($blocks[$block] ?? '') . $character;
|
||||
}
|
||||
}
|
||||
|
@ -2329,7 +2329,7 @@ class Item
|
|||
|
||||
public static function getLanguageMessage(array $item): string
|
||||
{
|
||||
$iso639 = new \Matriphe\ISO639\ISO639;
|
||||
$iso639 = new \Matriphe\ISO639\ISO639();
|
||||
|
||||
$used_languages = '';
|
||||
foreach (json_decode($item['language'], true) as $language => $reliability) {
|
||||
|
@ -2532,7 +2532,7 @@ class Item
|
|||
}
|
||||
|
||||
$basetag = str_replace('_', ' ', substr($tag, 1));
|
||||
$newtag = '#[url=' . DI::baseUrl() . '/search?tag=' . urlencode($basetag) . ']' . $basetag . '[/url]';
|
||||
$newtag = '#[url=' . DI::baseUrl() . '/search?tag=' . urlencode($basetag) . ']' . $basetag . '[/url]';
|
||||
|
||||
$body = str_replace($tag, $newtag, $body);
|
||||
}
|
||||
|
@ -2694,8 +2694,8 @@ class Item
|
|||
|
||||
$datarray['contact-id'] = $self['id'];
|
||||
|
||||
$datarray['author-name'] = $datarray['owner-name'] = $self['name'];
|
||||
$datarray['author-link'] = $datarray['owner-link'] = $self['url'];
|
||||
$datarray['author-name'] = $datarray['owner-name'] = $self['name'];
|
||||
$datarray['author-link'] = $datarray['owner-link'] = $self['url'];
|
||||
$datarray['author-avatar'] = $datarray['owner-avatar'] = $self['thumb'];
|
||||
|
||||
unset($datarray['edited']);
|
||||
|
@ -2705,14 +2705,14 @@ class Item
|
|||
unset($datarray['author-id']);
|
||||
|
||||
if ($contact['network'] != Protocol::FEED) {
|
||||
$old_uri_id = $datarray['uri-id'] ?? 0;
|
||||
$old_uri_id = $datarray['uri-id'] ?? 0;
|
||||
$datarray['guid'] = System::createUUID();
|
||||
unset($datarray['plink']);
|
||||
$datarray['uri'] = self::newURI($datarray['guid']);
|
||||
$datarray['uri'] = self::newURI($datarray['guid']);
|
||||
$datarray['uri-id'] = ItemURI::getIdByURI($datarray['uri']);
|
||||
$datarray['extid'] = Protocol::DFRN;
|
||||
$urlpart = parse_url($datarray2['author-link']);
|
||||
$datarray['app'] = $urlpart['host'];
|
||||
$datarray['extid'] = Protocol::DFRN;
|
||||
$urlpart = parse_url($datarray2['author-link']);
|
||||
$datarray['app'] = $urlpart['host'];
|
||||
if (!empty($old_uri_id)) {
|
||||
Post\Media::copy($old_uri_id, $datarray['uri-id']);
|
||||
}
|
||||
|
@ -2725,7 +2725,7 @@ class Item
|
|||
DI::logger()->info('remote-self post original item', ['contact' => $contact['url'], 'result' => $result, 'item' => $datarray2]);
|
||||
} else {
|
||||
$datarray['app'] = 'Feed';
|
||||
$result = true;
|
||||
$result = true;
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
|
@ -2755,11 +2755,11 @@ class Item
|
|||
$site = substr(DI::baseUrl(), strpos(DI::baseUrl(), '://'));
|
||||
|
||||
$orig_body = $s;
|
||||
$new_body = '';
|
||||
$new_body = '';
|
||||
|
||||
$img_start = strpos($orig_body, '[img');
|
||||
$img_start = strpos($orig_body, '[img');
|
||||
$img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
|
||||
$img_len = ($img_start !== false ? strpos(substr($orig_body, $img_start + $img_st_close + 1), '[/img]') : false);
|
||||
$img_len = ($img_start !== false ? strpos(substr($orig_body, $img_start + $img_st_close + 1), '[/img]') : false);
|
||||
|
||||
while (($img_st_close !== false) && ($img_len !== false)) {
|
||||
$img_st_close++; // make it point to AFTER the closing bracket
|
||||
|
@ -2770,13 +2770,13 @@ class Item
|
|||
if (stristr($image, $site . '/photo/')) {
|
||||
// Only embed locally hosted photos
|
||||
$replace = false;
|
||||
$i = basename($image);
|
||||
$i = str_replace(['.jpg', '.png', '.gif'], ['', '', ''], $i);
|
||||
$x = strpos($i, '-');
|
||||
$i = basename($image);
|
||||
$i = str_replace(['.jpg', '.png', '.gif'], ['', '', ''], $i);
|
||||
$x = strpos($i, '-');
|
||||
|
||||
if ($x) {
|
||||
$res = substr($i, $x + 1);
|
||||
$i = substr($i, 0, $x);
|
||||
$res = substr($i, $x + 1);
|
||||
$i = substr($i, 0, $x);
|
||||
$photo = Photo::getPhotoForUser($uid, $i, $res);
|
||||
if (DBA::isResult($photo)) {
|
||||
/*
|
||||
|
@ -2806,7 +2806,7 @@ class Item
|
|||
if (preg_match("/\[img\=([0-9]*)x([0-9]*)\]/is", substr($orig_body, $img_start, $img_st_close), $match)) {
|
||||
DI::logger()->info('scaling photo');
|
||||
|
||||
$width = intval($match[1]);
|
||||
$width = intval($match[1]);
|
||||
$height = intval($match[2]);
|
||||
|
||||
$photo_img->scaleDown(max($width, $height));
|
||||
|
@ -2823,15 +2823,15 @@ class Item
|
|||
}
|
||||
}
|
||||
|
||||
$new_body = $new_body . substr($orig_body, 0, $img_start + $img_st_close) . $image . '[/img]';
|
||||
$new_body = $new_body . substr($orig_body, 0, $img_start + $img_st_close) . $image . '[/img]';
|
||||
$orig_body = substr($orig_body, $img_start + $img_st_close + $img_len + strlen('[/img]'));
|
||||
if ($orig_body === false) {
|
||||
$orig_body = '';
|
||||
}
|
||||
|
||||
$img_start = strpos($orig_body, '[img');
|
||||
$img_start = strpos($orig_body, '[img');
|
||||
$img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
|
||||
$img_len = ($img_start !== false ? strpos(substr($orig_body, $img_start + $img_st_close + 1), '[/img]') : false);
|
||||
$img_len = ($img_start !== false ? strpos(substr($orig_body, $img_start + $img_st_close + 1), '[/img]') : false);
|
||||
}
|
||||
|
||||
$new_body = $new_body . $orig_body;
|
||||
|
@ -2936,9 +2936,9 @@ class Item
|
|||
$expire_items = true;
|
||||
}
|
||||
|
||||
$expire_notes = (bool)DI::pConfig()->get($uid, 'expire', 'notes', true);
|
||||
$expire_notes = (bool)DI::pConfig()->get($uid, 'expire', 'notes', true);
|
||||
$expire_starred = (bool)DI::pConfig()->get($uid, 'expire', 'starred', true);
|
||||
$expire_photos = (bool)DI::pConfig()->get($uid, 'expire', 'photos', false);
|
||||
$expire_photos = (bool)DI::pConfig()->get($uid, 'expire', 'photos', false);
|
||||
|
||||
$expired = 0;
|
||||
|
||||
|
@ -3114,7 +3114,7 @@ class Item
|
|||
}
|
||||
|
||||
$condition = [
|
||||
'vid' => $vids, 'deleted' => false, 'gravity' => self::GRAVITY_ACTIVITY,
|
||||
'vid' => $vids, 'deleted' => false, 'gravity' => self::GRAVITY_ACTIVITY,
|
||||
'author-id' => $author_id, 'uid' => $uid, 'thr-parent-id' => $uri_id
|
||||
];
|
||||
$like_item = Post::selectFirst(['id', 'guid', 'verb'], $condition);
|
||||
|
@ -3160,29 +3160,29 @@ class Item
|
|||
$objtype = $item['resource-id'] ? Activity\ObjectType::IMAGE : Activity\ObjectType::NOTE;
|
||||
|
||||
$new_item = [
|
||||
'guid' => System::createUUID(),
|
||||
'uri' => self::newURI(),
|
||||
'uid' => $uid,
|
||||
'contact-id' => $owner['id'],
|
||||
'wall' => $item['wall'],
|
||||
'origin' => 1,
|
||||
'network' => Protocol::DFRN,
|
||||
'protocol' => Conversation::PARCEL_DIRECT,
|
||||
'direction' => Conversation::PUSH,
|
||||
'gravity' => self::GRAVITY_ACTIVITY,
|
||||
'parent' => $item['id'],
|
||||
'thr-parent' => $item['uri'],
|
||||
'owner-id' => $author_id,
|
||||
'author-id' => $author_id,
|
||||
'body' => $activity,
|
||||
'verb' => $activity,
|
||||
'object-type' => $objtype,
|
||||
'allow_cid' => $allow_cid ?? $item['allow_cid'],
|
||||
'allow_gid' => $allow_gid ?? $item['allow_gid'],
|
||||
'deny_cid' => $deny_cid ?? $item['deny_cid'],
|
||||
'deny_gid' => $deny_gid ?? $item['deny_gid'],
|
||||
'visible' => 1,
|
||||
'unseen' => 1,
|
||||
'guid' => System::createUUID(),
|
||||
'uri' => self::newURI(),
|
||||
'uid' => $uid,
|
||||
'contact-id' => $owner['id'],
|
||||
'wall' => $item['wall'],
|
||||
'origin' => 1,
|
||||
'network' => Protocol::DFRN,
|
||||
'protocol' => Conversation::PARCEL_DIRECT,
|
||||
'direction' => Conversation::PUSH,
|
||||
'gravity' => self::GRAVITY_ACTIVITY,
|
||||
'parent' => $item['id'],
|
||||
'thr-parent' => $item['uri'],
|
||||
'owner-id' => $author_id,
|
||||
'author-id' => $author_id,
|
||||
'body' => $activity,
|
||||
'verb' => $activity,
|
||||
'object-type' => $objtype,
|
||||
'allow_cid' => $allow_cid ?? $item['allow_cid'],
|
||||
'allow_gid' => $allow_gid ?? $item['allow_gid'],
|
||||
'deny_cid' => $deny_cid ?? $item['deny_cid'],
|
||||
'deny_gid' => $deny_gid ?? $item['deny_gid'],
|
||||
'visible' => 1,
|
||||
'unseen' => 1,
|
||||
];
|
||||
|
||||
if (in_array($activity, [Activity::LIKE, Activity::DISLIKE])) {
|
||||
|
@ -3210,7 +3210,7 @@ class Item
|
|||
*/
|
||||
public static function getPermissionsConditionArrayByUserId(int $owner_id): array
|
||||
{
|
||||
$local_user = DI::userSession()->getLocalUserId();
|
||||
$local_user = DI::userSession()->getLocalUserId();
|
||||
$remote_user = DI::userSession()->getRemoteContactID($owner_id);
|
||||
|
||||
// default permissions - anonymous user
|
||||
|
@ -3244,7 +3244,7 @@ class Item
|
|||
*/
|
||||
public static function getPermissionsSQLByUserId(int $owner_id, string $table = ''): string
|
||||
{
|
||||
$local_user = DI::userSession()->getLocalUserId();
|
||||
$local_user = DI::userSession()->getLocalUserId();
|
||||
$remote_user = DI::userSession()->getRemoteContactID($owner_id);
|
||||
|
||||
if (!empty($table)) {
|
||||
|
@ -3372,7 +3372,7 @@ class Item
|
|||
public static function prepareBody(array &$item, bool $attach = false, bool $is_preview = false, bool $only_cache = false): string
|
||||
{
|
||||
$appHelper = DI::appHelper();
|
||||
$uid = DI::userSession()->getLocalUserId();
|
||||
$uid = DI::userSession()->getLocalUserId();
|
||||
Hook::callAll('prepare_body_init', $item);
|
||||
|
||||
// In order to provide theme developers more possibilities, event items
|
||||
|
@ -3384,7 +3384,7 @@ class Item
|
|||
|
||||
$tags = Tag::populateFromItem($item);
|
||||
|
||||
$item['tags'] = $tags['tags'];
|
||||
$item['tags'] = $tags['tags'];
|
||||
$item['hashtags'] = $tags['hashtags'];
|
||||
$item['mentions'] = $tags['mentions'];
|
||||
|
||||
|
@ -3408,12 +3408,12 @@ class Item
|
|||
|
||||
$shared = DI::contentItem()->getSharedPost($item, $fields);
|
||||
if (!empty($shared['post'])) {
|
||||
$shared_item = $shared['post'];
|
||||
$shared_item = $shared['post'];
|
||||
$shared_item['body'] = Post\Media::removeFromEndOfBody($shared_item['body']);
|
||||
$shared_item['body'] = Post\Media::replaceImage($shared_item['body']);
|
||||
$quote_uri_id = $shared['post']['uri-id'];
|
||||
$shared_links[] = strtolower($shared['post']['uri']);
|
||||
$item['body'] = BBCode::removeSharedData($item['body']);
|
||||
$quote_uri_id = $shared['post']['uri-id'];
|
||||
$shared_links[] = strtolower($shared['post']['uri']);
|
||||
$item['body'] = BBCode::removeSharedData($item['body']);
|
||||
} elseif (empty($shared_item['uri-id']) && empty($item['quote-uri-id']) && ($item['network'] != Protocol::DIASPORA)) {
|
||||
$media = Post\Media::getByURIId($item['uri-id'], [Post\Media::ACTIVITY]);
|
||||
if (!empty($media) && ($media[0]['media-uri-id'] != $item['uri-id'])) {
|
||||
|
@ -3425,7 +3425,7 @@ class Item
|
|||
}
|
||||
|
||||
if (empty($shared_item['uri-id'])) {
|
||||
$shared_item = Post::selectFirst($fields, ['uri' => $media[0]['url'], 'uid' => [$item['uid'], 0]]);
|
||||
$shared_item = Post::selectFirst($fields, ['uri' => $media[0]['url'], 'uid' => [$item['uid'], 0]]);
|
||||
$shared_links[] = strtolower($media[0]['url']);
|
||||
}
|
||||
|
||||
|
@ -3451,21 +3451,21 @@ class Item
|
|||
$sharedSplitAttachments = [];
|
||||
|
||||
if (!empty($shared_item['uri-id'])) {
|
||||
$shared_uri_id = $shared_item['uri-id'];
|
||||
$shared_links[] = strtolower($shared_item['plink']);
|
||||
$shared_uri_id = $shared_item['uri-id'];
|
||||
$shared_links[] = strtolower($shared_item['plink']);
|
||||
$sharedSplitAttachments = DI::postMediaRepository()->splitAttachments($shared_uri_id, [], $shared_item['has-media']);
|
||||
$shared_links = array_merge($shared_links, $sharedSplitAttachments['visual']->column('url'));
|
||||
$shared_links = array_merge($shared_links, $sharedSplitAttachments['link']->column('url'));
|
||||
$shared_links = array_merge($shared_links, $sharedSplitAttachments['additional']->column('url'));
|
||||
$item['body'] = self::replaceVisualAttachments($sharedSplitAttachments['visual'], $item['body']);
|
||||
$shared_links = array_merge($shared_links, $sharedSplitAttachments['visual']->column('url'));
|
||||
$shared_links = array_merge($shared_links, $sharedSplitAttachments['link']->column('url'));
|
||||
$shared_links = array_merge($shared_links, $sharedSplitAttachments['additional']->column('url'));
|
||||
$item['body'] = self::replaceVisualAttachments($sharedSplitAttachments['visual'], $item['body']);
|
||||
}
|
||||
|
||||
$itemSplitAttachments = DI::postMediaRepository()->splitAttachments($item['uri-id'], $shared_links, $item['has-media'] ?? false);
|
||||
$item['body'] = self::replaceVisualAttachments($itemSplitAttachments['visual'], $item['body'] ?? '');
|
||||
$item['body'] = self::replaceVisualAttachments($itemSplitAttachments['visual'], $item['body'] ?? '');
|
||||
|
||||
self::putInCache($item);
|
||||
$item['body'] = $body;
|
||||
$s = $item["rendered-html"];
|
||||
$s = $item["rendered-html"];
|
||||
|
||||
if ($only_cache) {
|
||||
return '';
|
||||
|
@ -3489,7 +3489,7 @@ class Item
|
|||
$item['attachments'] = $itemSplitAttachments;
|
||||
|
||||
$hook_data = [
|
||||
'item' => $item,
|
||||
'item' => $item,
|
||||
'filter_reasons' => $filter_reasons
|
||||
];
|
||||
Hook::callAll('prepare_body_content_filter', $hook_data);
|
||||
|
@ -3502,9 +3502,9 @@ class Item
|
|||
}
|
||||
|
||||
$hook_data = [
|
||||
'item' => $item,
|
||||
'html' => $s,
|
||||
'preview' => $is_preview,
|
||||
'item' => $item,
|
||||
'html' => $s,
|
||||
'preview' => $is_preview,
|
||||
'filter_reasons' => $filter_reasons
|
||||
];
|
||||
Hook::callAll('prepare_body', $hook_data);
|
||||
|
@ -3515,22 +3515,22 @@ class Item
|
|||
if (!$attach) {
|
||||
// Replace the blockquotes with quotes that are used in mails.
|
||||
$mailquote = '<blockquote type="cite" class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">';
|
||||
$s = str_replace(['<blockquote>', '<blockquote class="spoiler">', '<blockquote class="author">'], [$mailquote, $mailquote, $mailquote], $s);
|
||||
$s = str_replace(['<blockquote>', '<blockquote class="spoiler">', '<blockquote class="author">'], [$mailquote, $mailquote, $mailquote], $s);
|
||||
return $s;
|
||||
}
|
||||
|
||||
if (!empty($sharedSplitAttachments)) {
|
||||
$s = self::addGallery($s, $sharedSplitAttachments['visual']);
|
||||
$s = self::addVisualAttachments($sharedSplitAttachments['visual'], $shared_item, $s, true);
|
||||
$s = self::addLinkAttachment($shared_uri_id ?: $item['uri-id'], $sharedSplitAttachments, $body, $s, true, $quote_shared_links);
|
||||
$s = self::addNonVisualAttachments($sharedSplitAttachments['additional'], $item, $s);
|
||||
$s = self::addGallery($s, $sharedSplitAttachments['visual']);
|
||||
$s = self::addVisualAttachments($sharedSplitAttachments['visual'], $shared_item, $s, true);
|
||||
$s = self::addLinkAttachment($shared_uri_id ?: $item['uri-id'], $sharedSplitAttachments, $body, $s, true, $quote_shared_links);
|
||||
$s = self::addNonVisualAttachments($sharedSplitAttachments['additional'], $item, $s);
|
||||
$body = BBCode::removeSharedData($body);
|
||||
}
|
||||
|
||||
$pos = strpos($s, BBCode::SHARED_ANCHOR);
|
||||
if ($pos) {
|
||||
$shared_html = substr($s, $pos + strlen(BBCode::SHARED_ANCHOR));
|
||||
$s = substr($s, 0, $pos);
|
||||
$s = substr($s, 0, $pos);
|
||||
}
|
||||
|
||||
$s = self::addGallery($s, $itemSplitAttachments['visual']);
|
||||
|
@ -3550,7 +3550,7 @@ class Item
|
|||
// Replace friendica image url size with theme preference.
|
||||
if (!empty($appHelper->getThemeInfoValue('item_image_size'))) {
|
||||
$ps = $appHelper->getThemeInfoValue('item_image_size');
|
||||
$s = preg_replace('|(<img[^>]+src="[^"]+/photo/[0-9a-f]+)-[0-9]|', "$1-" . $ps, $s);
|
||||
$s = preg_replace('|(<img[^>]+src="[^"]+/photo/[0-9a-f]+)-[0-9]|', "$1-" . $ps, $s);
|
||||
}
|
||||
|
||||
if (!empty($shared_html)) {
|
||||
|
@ -3592,7 +3592,7 @@ class Item
|
|||
continue;
|
||||
}
|
||||
$element_html = $element->ownerDocument->saveHTML($element);
|
||||
$html = str_replace($element_html, str_replace($src, $svg, $element_html), $html);
|
||||
$html = str_replace($element_html, str_replace($src, $svg, $element_html), $html);
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
@ -3616,8 +3616,8 @@ class Item
|
|||
|
||||
$s = preg_replace_callback($pattern, function () use ($PostMedia) {
|
||||
return Renderer::replaceMacros(Renderer::getMarkupTemplate('content/image/single_with_height_allocation.tpl'), [
|
||||
'$image' => $PostMedia,
|
||||
'$allocated_height' => $PostMedia->getAllocatedHeight(),
|
||||
'$image' => $PostMedia,
|
||||
'$allocated_height' => $PostMedia->getAllocatedHeight(),
|
||||
'$allocated_max_width' => ($PostMedia->previewWidth ?? $PostMedia->width) . 'px',
|
||||
]);
|
||||
}, $s);
|
||||
|
@ -3741,10 +3741,10 @@ class Item
|
|||
|
||||
if ($PostMedia->mimetype->type == 'image' || $PostMedia->preview) {
|
||||
$preview_size = Proxy::SIZE_MEDIUM;
|
||||
$preview_url = DI::baseUrl() . $PostMedia->getPreviewPath($preview_size);
|
||||
$preview_url = DI::baseUrl() . $PostMedia->getPreviewPath($preview_size);
|
||||
} else {
|
||||
$preview_size = 0;
|
||||
$preview_url = '';
|
||||
$preview_url = '';
|
||||
}
|
||||
|
||||
if ($preview_url && self::containsLink($item['body'], $preview_url)) {
|
||||
|
@ -3780,10 +3780,10 @@ class Item
|
|||
} elseif ($PostMedia->mimetype->type == 'audio') {
|
||||
$media = Renderer::replaceMacros(Renderer::getMarkupTemplate('content/audio.tpl'), [
|
||||
'$audio' => [
|
||||
'id' => $PostMedia->id,
|
||||
'src' => (string)$PostMedia->url,
|
||||
'name' => $PostMedia->name ?: $PostMedia->url,
|
||||
'mime' => (string)$PostMedia->mimetype,
|
||||
'id' => $PostMedia->id,
|
||||
'src' => (string)$PostMedia->url,
|
||||
'name' => $PostMedia->name ?: $PostMedia->url,
|
||||
'mime' => (string)$PostMedia->mimetype,
|
||||
],
|
||||
]);
|
||||
if (($item['post-type'] ?? null) == Item::PT_AUDIO) {
|
||||
|
@ -3847,7 +3847,7 @@ class Item
|
|||
{
|
||||
DI::profiler()->startRecording('rendering');
|
||||
// Don't show a preview when there is a visual attachment (audio or video)
|
||||
$types = $attachments['visual']->column('type');
|
||||
$types = $attachments['visual']->column('type');
|
||||
$preview = !in_array(PostMedia::TYPE_IMAGE, $types) && !in_array(PostMedia::TYPE_VIDEO, $types);
|
||||
|
||||
/** @var ?PostMedia $attachment */
|
||||
|
@ -3870,18 +3870,18 @@ class Item
|
|||
|
||||
if (!empty($attachment)) {
|
||||
$data = [
|
||||
'after' => '',
|
||||
'author_name' => $attachment->authorName ?? '',
|
||||
'author_url' => (string)($attachment->authorUrl ?? ''),
|
||||
'description' => $attachment->description ?? '',
|
||||
'image' => '',
|
||||
'preview' => '',
|
||||
'after' => '',
|
||||
'author_name' => $attachment->authorName ?? '',
|
||||
'author_url' => (string)($attachment->authorUrl ?? ''),
|
||||
'description' => $attachment->description ?? '',
|
||||
'image' => '',
|
||||
'preview' => '',
|
||||
'provider_name' => $attachment->publisherName ?? '',
|
||||
'provider_url' => (string)($attachment->publisherUrl ?? ''),
|
||||
'text' => '',
|
||||
'title' => $attachment->name ?? '',
|
||||
'type' => 'link',
|
||||
'url' => (string)$attachment->url,
|
||||
'provider_url' => (string)($attachment->publisherUrl ?? ''),
|
||||
'text' => '',
|
||||
'title' => $attachment->name ?? '',
|
||||
'type' => 'link',
|
||||
'url' => (string)$attachment->url,
|
||||
];
|
||||
|
||||
if ($preview && $attachment->preview) {
|
||||
|
@ -4022,7 +4022,7 @@ class Item
|
|||
$options = Post\QuestionOption::getByURIId($item['uri-id']);
|
||||
foreach ($options as $key => $option) {
|
||||
if ($question['voters'] > 0) {
|
||||
$percent = $option['replies'] / $question['voters'] * 100;
|
||||
$percent = $option['replies'] / $question['voters'] * 100;
|
||||
$options[$key]['vote'] = DI::l10n()->tt('%2$s (%3$d%%, %1$d vote)', '%2$s (%3$d%%, %1$d votes)', $option['replies'] ?? 0, $option['name'], round($percent, 1));
|
||||
} else {
|
||||
$options[$key]['vote'] = DI::l10n()->tt('%2$s (%1$d vote)', '%2$s (%1$d votes)', $option['replies'] ?? 0, $option['name']);
|
||||
|
@ -4073,9 +4073,9 @@ class Item
|
|||
|
||||
if (DI::userSession()->getLocalUserId()) {
|
||||
$ret = [
|
||||
'href' => "display/" . $item['guid'],
|
||||
'orig' => "display/" . $item['guid'],
|
||||
'title' => DI::l10n()->t('View on separate page'),
|
||||
'href' => "display/" . $item['guid'],
|
||||
'orig' => "display/" . $item['guid'],
|
||||
'title' => DI::l10n()->t('View on separate page'),
|
||||
'orig_title' => DI::l10n()->t('View on separate page'),
|
||||
];
|
||||
|
||||
|
@ -4091,14 +4091,14 @@ class Item
|
|||
}
|
||||
|
||||
if (!empty($plink)) {
|
||||
$ret['href'] = DI::baseUrl()->remove($plink);
|
||||
$ret['href'] = DI::baseUrl()->remove($plink);
|
||||
$ret['title'] = DI::l10n()->t('Link to source');
|
||||
}
|
||||
} elseif (!empty($plink) && ($item['private'] != self::PRIVATE)) {
|
||||
$ret = [
|
||||
'href' => $plink,
|
||||
'orig' => $plink,
|
||||
'title' => DI::l10n()->t('Link to source'),
|
||||
'href' => $plink,
|
||||
'orig' => $plink,
|
||||
'title' => DI::l10n()->t('Link to source'),
|
||||
'orig_title' => DI::l10n()->t('Link to source'),
|
||||
];
|
||||
} else {
|
||||
|
@ -4143,7 +4143,7 @@ class Item
|
|||
public static function searchByLink(string $uri, int $uid = 0): int
|
||||
{
|
||||
$ssl_uri = str_replace('http://', 'https://', $uri);
|
||||
$uris = [$uri, $ssl_uri, Strings::normaliseLink($uri)];
|
||||
$uris = [$uri, $ssl_uri, Strings::normaliseLink($uri)];
|
||||
|
||||
$item = Post::selectFirst(['id'], ['uri' => $uris, 'uid' => $uid]);
|
||||
if (DBA::isResult($item)) {
|
||||
|
@ -4168,7 +4168,7 @@ class Item
|
|||
public static function getURIByLink(string $uri): string
|
||||
{
|
||||
$ssl_uri = str_replace('http://', 'https://', $uri);
|
||||
$uris = [$uri, $ssl_uri, Strings::normaliseLink($uri)];
|
||||
$uris = [$uri, $ssl_uri, Strings::normaliseLink($uri)];
|
||||
|
||||
$item = Post::selectFirst(['uri'], ['uri' => $uris]);
|
||||
if (DBA::isResult($item)) {
|
||||
|
@ -4222,7 +4222,7 @@ class Item
|
|||
if (!$mimetype) {
|
||||
try {
|
||||
$curlResult = DI::httpClient()->head($uri, [HttpClientOptions::ACCEPT_CONTENT => HttpClientAccept::JSON_AS, HttpClientOptions::REQUEST => HttpClientRequest::ACTIVITYPUB]);
|
||||
$mimetype = $curlResult->getContentType();
|
||||
$mimetype = $curlResult->getContentType();
|
||||
} catch (\Throwable $th) {
|
||||
DI::logger()->info('Error while fetching HTTP link via HEAD', ['uid' => $uid, 'uri' => $uri, 'code' => $th->getCode(), 'message' => $th->getMessage()]);
|
||||
return 0;
|
||||
|
@ -4233,7 +4233,7 @@ class Item
|
|||
try {
|
||||
// Issue 14126: Workaround for Mastodon servers that return "application/json" on a "head" request.
|
||||
$curlResult = HTTPSignature::fetchRaw($uri, $uid);
|
||||
$mimetype = $curlResult->getContentType();
|
||||
$mimetype = $curlResult->getContentType();
|
||||
} catch (\Throwable $th) {
|
||||
DI::logger()->info('Error while fetching HTTP link via signed GET', ['uid' => $uid, 'uri' => $uri, 'code' => $th->getCode(), 'message' => $th->getMessage()]);
|
||||
return 0;
|
||||
|
@ -4305,7 +4305,7 @@ class Item
|
|||
}
|
||||
|
||||
$url = $shared['message_id'] ?: $shared['link'];
|
||||
$id = self::fetchByLink($url, 0, ActivityPub\Receiver::COMPLETION_ASYNC);
|
||||
$id = self::fetchByLink($url, 0, ActivityPub\Receiver::COMPLETION_ASYNC);
|
||||
if (!$id) {
|
||||
DI::logger()->notice('Post could not be fetched.', ['url' => $url, 'uid' => $uid]);
|
||||
return 0;
|
||||
|
|
|
@ -137,15 +137,15 @@ class Mail
|
|||
Photo::setPermissionFromBody($body, $sender_uid, $me['id'], '<' . $contact['id'] . '>', '', '', '');
|
||||
|
||||
$guid = System::createUUID();
|
||||
$uri = Item::newURI($guid);
|
||||
$uri = Item::newURI($guid);
|
||||
|
||||
$convid = 0;
|
||||
$reply = false;
|
||||
$reply = false;
|
||||
|
||||
// look for any existing conversation structure
|
||||
|
||||
if (strlen($replyto)) {
|
||||
$reply = true;
|
||||
$reply = true;
|
||||
$condition = ["`uid` = ? AND (`uri` = ? OR `parent-uri` = ?)",
|
||||
$sender_uid, $replyto, $replyto];
|
||||
$mail = DBA::selectFirst('mail', ['convid'], $condition);
|
||||
|
@ -158,11 +158,11 @@ class Mail
|
|||
if (!$convid) {
|
||||
// create a new conversation
|
||||
$conv_guid = System::createUUID();
|
||||
$convuri = $contact['addr'] . ':' . $conv_guid;
|
||||
$convuri = $contact['addr'] . ':' . $conv_guid;
|
||||
|
||||
$fields = ['uid' => $sender_uid, 'guid' => $conv_guid, 'creator' => $me['addr'],
|
||||
'created' => DateTimeFormat::utcNow(), 'updated' => DateTimeFormat::utcNow(),
|
||||
'subject' => $subject, 'recips' => $contact['addr'] . ';' . $me['addr']];
|
||||
'created' => DateTimeFormat::utcNow(), 'updated' => DateTimeFormat::utcNow(),
|
||||
'subject' => $subject, 'recips' => $contact['addr'] . ';' . $me['addr']];
|
||||
if (DBA::insert('conv', $fields)) {
|
||||
$convid = DBA::lastInsertId();
|
||||
}
|
||||
|
@ -179,21 +179,21 @@ class Mail
|
|||
|
||||
$post_id = self::insert(
|
||||
[
|
||||
'uid' => $sender_uid,
|
||||
'guid' => $guid,
|
||||
'convid' => $convid,
|
||||
'from-name' => $me['name'],
|
||||
'uid' => $sender_uid,
|
||||
'guid' => $guid,
|
||||
'convid' => $convid,
|
||||
'from-name' => $me['name'],
|
||||
'from-photo' => $me['thumb'],
|
||||
'from-url' => $me['url'],
|
||||
'from-url' => $me['url'],
|
||||
'contact-id' => $recipient,
|
||||
'title' => $subject,
|
||||
'body' => $body,
|
||||
'seen' => 1,
|
||||
'reply' => $reply,
|
||||
'replied' => 0,
|
||||
'uri' => $uri,
|
||||
'title' => $subject,
|
||||
'body' => $body,
|
||||
'seen' => 1,
|
||||
'reply' => $reply,
|
||||
'replied' => 0,
|
||||
'uri' => $uri,
|
||||
'parent-uri' => $replyto,
|
||||
'created' => DateTimeFormat::utcNow()
|
||||
'created' => DateTimeFormat::utcNow()
|
||||
],
|
||||
false
|
||||
);
|
||||
|
|
|
@ -212,7 +212,7 @@ class Post
|
|||
public static function selectOriginal(array $fields = [], array $condition = [], array $params = [])
|
||||
{
|
||||
$original_fields = $fields;
|
||||
$remove = [];
|
||||
$remove = [];
|
||||
if (!empty($fields)) {
|
||||
foreach (['gravity', 'verb', 'thr-parent-id', 'uid'] as $field) {
|
||||
if (!in_array($field, $fields)) {
|
||||
|
@ -447,7 +447,8 @@ class Post
|
|||
$selected = Item::DISPLAY_FIELDLIST;
|
||||
}
|
||||
|
||||
$condition = DBA::mergeConditions($condition,
|
||||
$condition = DBA::mergeConditions(
|
||||
$condition,
|
||||
["`visible` AND NOT `deleted`
|
||||
AND NOT `author-blocked` AND NOT `owner-blocked`
|
||||
AND (NOT `causer-blocked` OR `causer-id` = ? OR `causer-id` IS NULL) AND NOT `contact-blocked`
|
||||
|
@ -456,7 +457,8 @@ class Post
|
|||
AND NOT EXISTS(SELECT `uri-id` FROM `post-user` WHERE `uid` = ? AND `uri-id` = " . DBA::quoteIdentifier($view) . ".`uri-id` AND `hidden`)
|
||||
AND NOT EXISTS(SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` IN (`author-id`, `owner-id`) AND (`blocked` OR `ignored` OR `is-blocked`))
|
||||
AND NOT EXISTS(SELECT `gsid` FROM `user-gserver` WHERE `uid` = ? AND `gsid` IN (`author-gsid`, `owner-gsid`, `causer-gsid`) AND `ignored`)",
|
||||
0, Contact::SHARING, Contact::FRIEND, 0, $uid, $uid, $uid]);
|
||||
0, Contact::SHARING, Contact::FRIEND, 0, $uid, $uid, $uid]
|
||||
);
|
||||
|
||||
$select_string = implode(', ', array_map([DBA::class, 'quoteIdentifier'], $selected));
|
||||
|
||||
|
@ -581,7 +583,7 @@ class Post
|
|||
public static function selectOriginalForUser(int $uid, array $selected = [], array $condition = [], array $params = [])
|
||||
{
|
||||
$original_selected = $selected;
|
||||
$remove = [];
|
||||
$remove = [];
|
||||
if (!empty($selected)) {
|
||||
foreach (['gravity', 'verb', 'thr-parent-id'] as $field) {
|
||||
if (!in_array($field, $selected)) {
|
||||
|
|
|
@ -53,7 +53,7 @@ class Delayed
|
|||
|
||||
$last_publish = DI::pConfig()->get($item['uid'], 'system', 'last_publish', 0, true);
|
||||
$next_publish = max($last_publish + (60 * $min_posting), time());
|
||||
$delayed = date(DateTimeFormat::MYSQL, $next_publish);
|
||||
$delayed = date(DateTimeFormat::MYSQL, $next_publish);
|
||||
DI::pConfig()->set($item['uid'], 'system', 'last_publish', $next_publish);
|
||||
}
|
||||
|
||||
|
@ -151,13 +151,13 @@ class Delayed
|
|||
}
|
||||
|
||||
return [
|
||||
'parameters' => $delayed,
|
||||
'item' => $parameters[0],
|
||||
'notify' => $parameters[1],
|
||||
'taglist' => $parameters[2],
|
||||
'parameters' => $delayed,
|
||||
'item' => $parameters[0],
|
||||
'notify' => $parameters[1],
|
||||
'taglist' => $parameters[2],
|
||||
'attachments' => $parameters[3],
|
||||
'unprepared' => $parameters[4],
|
||||
'uri' => $parameters[5],
|
||||
'unprepared' => $parameters[4],
|
||||
'uri' => $parameters[5],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -27,16 +27,16 @@ class Engagement
|
|||
const KEYWORDS = ['source', 'server', 'from', 'to', 'group', 'application', 'tag', 'network', 'platform', 'visibility', 'language', 'media'];
|
||||
const SHORTCUTS = ['lang' => 'language', 'net' => 'network', 'relay' => 'application'];
|
||||
const ALTERNATIVES = ['source:news' => 'source:service', 'source:relay' => 'source:application',
|
||||
'media:picture' => 'media:image', 'media:photo' => 'media:image',
|
||||
'network:activitypub' => 'network:apub', 'network:friendica' => 'network:dfrn',
|
||||
'network:diaspora' => 'network:dspr', 'network:discourse' => 'network:dscs',
|
||||
'network:tumblr' => 'network:tmbl', 'network:bluesky' => 'network:bsky'];
|
||||
const MEDIA_NONE = 0;
|
||||
'media:picture' => 'media:image', 'media:photo' => 'media:image',
|
||||
'network:activitypub' => 'network:apub', 'network:friendica' => 'network:dfrn',
|
||||
'network:diaspora' => 'network:dspr', 'network:discourse' => 'network:dscs',
|
||||
'network:tumblr' => 'network:tmbl', 'network:bluesky' => 'network:bsky'];
|
||||
const MEDIA_NONE = 0;
|
||||
const MEDIA_IMAGE = 1;
|
||||
const MEDIA_VIDEO = 2;
|
||||
const MEDIA_AUDIO = 4;
|
||||
const MEDIA_CARD = 8;
|
||||
const MEDIA_POST = 16;
|
||||
const MEDIA_CARD = 8;
|
||||
const MEDIA_POST = 16;
|
||||
|
||||
/**
|
||||
* Store engagement data from an item array
|
||||
|
@ -51,11 +51,13 @@ class Engagement
|
|||
return 0;
|
||||
}
|
||||
|
||||
$parent = Post::selectFirst(['uri-id', 'created', 'uid', 'private', 'quote-uri-id',
|
||||
'contact-contact-type', 'network', 'title', 'content-warning', 'body', 'language',
|
||||
'author-id', 'author-contact-type', 'author-nick', 'author-addr', 'author-gsid',
|
||||
'owner-id', 'owner-contact-type', 'owner-nick', 'owner-addr', 'owner-gsid'],
|
||||
['uri-id' => $item['parent-uri-id']]);
|
||||
$parent = Post::selectFirst(
|
||||
['uri-id', 'created', 'uid', 'private', 'quote-uri-id',
|
||||
'contact-contact-type', 'network', 'title', 'content-warning', 'body', 'language',
|
||||
'author-id', 'author-contact-type', 'author-nick', 'author-addr', 'author-gsid',
|
||||
'owner-id', 'owner-contact-type', 'owner-nick', 'owner-addr', 'owner-gsid'],
|
||||
['uri-id' => $item['parent-uri-id']]
|
||||
);
|
||||
|
||||
if ($parent['created'] < self::getCreationDateLimit(false)) {
|
||||
DI::logger()->debug('Post is too old', ['uri-id' => $item['uri-id'], 'parent-uri-id' => $item['parent-uri-id'], 'created' => $parent['created']]);
|
||||
|
@ -134,7 +136,7 @@ class Engagement
|
|||
$body = BBCode::removeSharedData($body);
|
||||
$body = preg_replace('/[^@!#]\[url\=.*?\].*?\[\/url\]/ism', '', $body);
|
||||
$body = BBCode::removeLinks($body);
|
||||
$msg = BBCode::toPlaintext($body, false);
|
||||
$msg = BBCode::toPlaintext($body, false);
|
||||
|
||||
return mb_strlen($msg);
|
||||
}
|
||||
|
@ -203,7 +205,7 @@ class Engagement
|
|||
$body = '[nosmile]network_' . $item['network'];
|
||||
|
||||
if (!empty($item['author-gsid'])) {
|
||||
$gserver = DBA::selectFirst('gserver', ['platform', 'nurl'], ['id' => $item['author-gsid']]);
|
||||
$gserver = DBA::selectFirst('gserver', ['platform', 'nurl'], ['id' => $item['author-gsid']]);
|
||||
$platform = preg_replace('/[\W]/', '', $gserver['platform'] ?? '');
|
||||
if (!empty($platform)) {
|
||||
$body .= ' platform_' . $platform;
|
||||
|
@ -212,7 +214,7 @@ class Engagement
|
|||
}
|
||||
|
||||
if (($item['owner-contact-type'] == Contact::TYPE_COMMUNITY) && !empty($item['owner-gsid']) && ($item['owner-gsid'] != ($item['author-gsid'] ?? 0))) {
|
||||
$gserver = DBA::selectFirst('gserver', ['platform', 'nurl'], ['id' => $item['owner-gsid']]);
|
||||
$gserver = DBA::selectFirst('gserver', ['platform', 'nurl'], ['id' => $item['owner-gsid']]);
|
||||
$platform = preg_replace('/[\W]/', '', $gserver['platform'] ?? '');
|
||||
if (!empty($platform) && !strpos($body, 'platform_' . $platform)) {
|
||||
$body .= ' platform_' . $platform;
|
||||
|
@ -252,7 +254,7 @@ class Engagement
|
|||
$body .= ' from_' . $item['author-nick'] . ' from_' . $item['author-addr'];
|
||||
}
|
||||
|
||||
if ($item['author-id'] != $item['owner-id']) {
|
||||
if ($item['author-id'] != $item['owner-id']) {
|
||||
if ($item['owner-contact-type'] == Contact::TYPE_COMMUNITY) {
|
||||
$body .= ' group_' . $item['owner-nick'] . ' group_' . $item['owner-addr'];
|
||||
} elseif (in_array($item['owner-contact-type'], [Contact::TYPE_PERSON, Contact::TYPE_NEWS, Contact::TYPE_ORGANISATION])) {
|
||||
|
@ -314,8 +316,10 @@ class Engagement
|
|||
|
||||
private static function addResharers(string $text, int $uri_id): string
|
||||
{
|
||||
$result = Post::selectPosts(['author-addr', 'author-nick', 'author-contact-type'],
|
||||
['thr-parent-id' => $uri_id, 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::ANNOUNCE, 'author-contact-type' => [Contact::TYPE_RELAY, Contact::TYPE_COMMUNITY]]);
|
||||
$result = Post::selectPosts(
|
||||
['author-addr', 'author-nick', 'author-contact-type'],
|
||||
['thr-parent-id' => $uri_id, 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::ANNOUNCE, 'author-contact-type' => [Contact::TYPE_RELAY, Contact::TYPE_COMMUNITY]]
|
||||
);
|
||||
while ($reshare = Post::fetch($result)) {
|
||||
$prefix = '';
|
||||
|
||||
|
@ -392,11 +396,11 @@ class Engagement
|
|||
|
||||
public static function escapeKeywords(string $fullTextSearch): string
|
||||
{
|
||||
foreach (SELF::SHORTCUTS as $search => $replace) {
|
||||
foreach (self::SHORTCUTS as $search => $replace) {
|
||||
$fullTextSearch = preg_replace('~' . $search . ':(.[\w\*@\.-]+)~', $replace . ':$1', $fullTextSearch);
|
||||
}
|
||||
|
||||
foreach (SELF::ALTERNATIVES as $search => $replace) {
|
||||
foreach (self::ALTERNATIVES as $search => $replace) {
|
||||
$fullTextSearch = str_replace($search, $replace, $fullTextSearch);
|
||||
}
|
||||
|
||||
|
|
|
@ -61,9 +61,9 @@ class Link
|
|||
$id = $link['id'];
|
||||
DI::logger()->info('Found', ['id' => $id, 'uri-id' => $uriId, 'url' => $url]);
|
||||
} else {
|
||||
$fields = self::fetchMimeType($url);
|
||||
$fields = self::fetchMimeType($url);
|
||||
$fields['uri-id'] = $uriId;
|
||||
$fields['url'] = Network::sanitizeUrl($url);
|
||||
$fields['url'] = Network::sanitizeUrl($url);
|
||||
|
||||
DBA::insert('post-link', $fields, Database::INSERT_IGNORE);
|
||||
$id = DBA::lastInsertId();
|
||||
|
@ -126,7 +126,7 @@ class Link
|
|||
|
||||
if (Images::isSupportedMimeType($fields['mimetype'])) {
|
||||
$img_str = $curlResult->getBodyString();
|
||||
$image = new Image($img_str, $fields['mimetype'], $url, false);
|
||||
$image = new Image($img_str, $fields['mimetype'], $url, false);
|
||||
if ($image->isValid()) {
|
||||
$fields['mimetype'] = $image->getType();
|
||||
$fields['width'] = $image->getWidth();
|
||||
|
|
|
@ -118,7 +118,7 @@ class UserNotification
|
|||
$fields = ['id', 'uri-id', 'parent-uri-id', 'uid', 'body', 'parent', 'gravity', 'vid', 'gravity',
|
||||
'contact-id', 'author-id', 'author-gsid', 'owner-id', 'owner-gsid', 'causer-id', 'causer-gsid',
|
||||
'private', 'thr-parent', 'thr-parent-id', 'parent-uri-id', 'parent-uri', 'verb'];
|
||||
$item = Post::selectFirst($fields, ['uri-id' => $uri_id, 'uid' => $uid, 'origin' => false]);
|
||||
$item = Post::selectFirst($fields, ['uri-id' => $uri_id, 'uid' => $uid, 'origin' => false]);
|
||||
if (!DBA::isResult($item)) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -266,7 +266,7 @@ class Profile
|
|||
*/
|
||||
public static function getVCardHtml(array $profile, bool $block, bool $show_contacts): string
|
||||
{
|
||||
$o = '';
|
||||
$o = '';
|
||||
$location = false;
|
||||
|
||||
$profile_contact = [];
|
||||
|
@ -293,8 +293,8 @@ class Profile
|
|||
|
||||
$cid = $contact['id'];
|
||||
|
||||
$follow_link = null;
|
||||
$unfollow_link = null;
|
||||
$follow_link = null;
|
||||
$unfollow_link = null;
|
||||
$wallmessage_link = null;
|
||||
|
||||
// Who is the logged-in user to this profile?
|
||||
|
@ -303,13 +303,11 @@ class Profile
|
|||
$visitor_contact = Contact::selectFirst(['rel'], ['uid' => $profile['uid'], 'nurl' => Strings::normaliseLink(DI::userSession()->getMyUrl())]);
|
||||
}
|
||||
|
||||
$local_user_is_self = DI::userSession()->getMyUrl() && ($profile['url'] == DI::userSession()->getMyUrl());
|
||||
$local_user_is_self = DI::userSession()->getMyUrl() && ($profile['url'] == DI::userSession()->getMyUrl());
|
||||
$visitor_is_authenticated = (bool)DI::userSession()->getMyUrl();
|
||||
$visitor_is_following =
|
||||
in_array($visitor_contact['rel'] ?? 0, [Contact::FOLLOWER, Contact::FRIEND])
|
||||
$visitor_is_following = in_array($visitor_contact['rel'] ?? 0, [Contact::FOLLOWER, Contact::FRIEND])
|
||||
|| in_array($profile_contact['rel'] ?? 0, [Contact::SHARING, Contact::FRIEND]);
|
||||
$visitor_is_followed =
|
||||
in_array($visitor_contact['rel'] ?? 0, [Contact::SHARING, Contact::FRIEND])
|
||||
$visitor_is_followed = in_array($visitor_contact['rel'] ?? 0, [Contact::SHARING, Contact::FRIEND])
|
||||
|| in_array($profile_contact['rel'] ?? 0, [Contact::FOLLOWER, Contact::FRIEND]);
|
||||
$visitor_base_path = DI::userSession()->getMyUrl() ? preg_replace('=/profile/(.*)=ism', '', DI::userSession()->getMyUrl()) : '';
|
||||
|
||||
|
@ -341,15 +339,15 @@ class Profile
|
|||
$profile['edit'] = [DI::baseUrl() . '/settings/profile', DI::l10n()->t('Edit profile'), '', DI::l10n()->t('Edit profile')];
|
||||
$profile['menu'] = [
|
||||
'chg_photo' => DI::l10n()->t('Change profile photo'),
|
||||
'cr_new' => null,
|
||||
'entries' => [],
|
||||
'cr_new' => null,
|
||||
'entries' => [],
|
||||
];
|
||||
}
|
||||
|
||||
// Fetch the account type
|
||||
$account_type = Contact::getAccountType($profile['account-type']);
|
||||
|
||||
if (!empty($profile['address']) || !empty($profile['location'])) {
|
||||
if (!empty($profile['address']) || !empty($profile['location'])) {
|
||||
$location = DI::l10n()->t('Location:');
|
||||
}
|
||||
|
||||
|
@ -363,8 +361,8 @@ class Profile
|
|||
}
|
||||
|
||||
$split_name = Diaspora::splitName($profile['name']);
|
||||
$firstname = $split_name['first'];
|
||||
$lastname = $split_name['last'];
|
||||
$firstname = $split_name['first'];
|
||||
$lastname = $split_name['last'];
|
||||
|
||||
if (!empty($profile['guid'])) {
|
||||
$diaspora = [
|
||||
|
@ -384,7 +382,7 @@ class Profile
|
|||
}
|
||||
|
||||
$contact_block = '';
|
||||
$updated = '';
|
||||
$updated = '';
|
||||
$contact_count = 0;
|
||||
|
||||
if (!empty($profile['last-item'])) {
|
||||
|
@ -415,7 +413,7 @@ class Profile
|
|||
'upubkey' => null,
|
||||
];
|
||||
foreach ($profile as $k => $v) {
|
||||
$k = str_replace('-', '_', $k);
|
||||
$k = str_replace('-', '_', $k);
|
||||
$p[$k] = $v;
|
||||
}
|
||||
|
||||
|
@ -444,35 +442,35 @@ class Profile
|
|||
$mention_url = 'compose/0?body=@' . $profile['addr'];
|
||||
$network_label = DI::l10n()->t('Network Posts');
|
||||
}
|
||||
$network_url = 'contact/' . $cid . '/conversations';
|
||||
$network_url = 'contact/' . $cid . '/conversations';
|
||||
|
||||
$tpl = Renderer::getMarkupTemplate('profile/vcard.tpl');
|
||||
$o .= Renderer::replaceMacros($tpl, [
|
||||
'$profile' => $p,
|
||||
'$xmpp' => $xmpp,
|
||||
'$matrix' => $matrix,
|
||||
'$follow' => DI::l10n()->t('Follow'),
|
||||
'$follow_link' => $follow_link,
|
||||
'$unfollow' => DI::l10n()->t('Unfollow'),
|
||||
'$unfollow_link' => $unfollow_link,
|
||||
'$subscribe_feed' => DI::l10n()->t('Atom feed'),
|
||||
'$profile' => $p,
|
||||
'$xmpp' => $xmpp,
|
||||
'$matrix' => $matrix,
|
||||
'$follow' => DI::l10n()->t('Follow'),
|
||||
'$follow_link' => $follow_link,
|
||||
'$unfollow' => DI::l10n()->t('Unfollow'),
|
||||
'$unfollow_link' => $unfollow_link,
|
||||
'$subscribe_feed' => DI::l10n()->t('Atom feed'),
|
||||
'$subscribe_feed_link' => $profile['hidewall'] ?? 0 ? '' : $profile['poll'],
|
||||
'$wallmessage' => DI::l10n()->t('Message'),
|
||||
'$wallmessage_link' => $wallmessage_link,
|
||||
'$account_type' => $account_type,
|
||||
'$location' => $location,
|
||||
'$homepage' => $homepage,
|
||||
'$homepage_verified' => DI::l10n()->t('This website has been verified to belong to the same person.'),
|
||||
'$about' => $about,
|
||||
'$network' => DI::l10n()->t('Network:'),
|
||||
'$contacts' => $contact_count,
|
||||
'$updated' => $updated,
|
||||
'$diaspora' => $diaspora,
|
||||
'$contact_block' => $contact_block,
|
||||
'$mention_label' => $mention_label,
|
||||
'$mention_url' => $mention_url,
|
||||
'$network_label' => $network_label,
|
||||
'$network_url' => $network_url,
|
||||
'$wallmessage' => DI::l10n()->t('Message'),
|
||||
'$wallmessage_link' => $wallmessage_link,
|
||||
'$account_type' => $account_type,
|
||||
'$location' => $location,
|
||||
'$homepage' => $homepage,
|
||||
'$homepage_verified' => DI::l10n()->t('This website has been verified to belong to the same person.'),
|
||||
'$about' => $about,
|
||||
'$network' => DI::l10n()->t('Network:'),
|
||||
'$contacts' => $contact_count,
|
||||
'$updated' => $updated,
|
||||
'$diaspora' => $diaspora,
|
||||
'$contact_block' => $contact_block,
|
||||
'$mention_label' => $mention_label,
|
||||
'$mention_url' => $mention_url,
|
||||
'$network_label' => $network_label,
|
||||
'$network_url' => $network_url,
|
||||
]);
|
||||
|
||||
$arr = ['profile' => &$profile, 'entry' => &$o];
|
||||
|
@ -603,7 +601,7 @@ class Profile
|
|||
*/
|
||||
public static function getEventsReminderHTML(int $uid, int $pcid): string
|
||||
{
|
||||
$bd_format = DI::l10n()->t('g A l F d'); // 8 AM Friday January 18
|
||||
$bd_format = DI::l10n()->t('g A l F d'); // 8 AM Friday January 18
|
||||
$classtoday = '';
|
||||
|
||||
$condition = [
|
||||
|
@ -616,13 +614,13 @@ class Profile
|
|||
|
||||
if (DBA::isResult($s)) {
|
||||
$istoday = false;
|
||||
$total = 0;
|
||||
$total = 0;
|
||||
|
||||
while ($rr = DBA::fetch($s)) {
|
||||
$condition = [
|
||||
'parent-uri' => $rr['uri'], 'uid' => $rr['uid'], 'author-id' => $pcid,
|
||||
'vid' => [Verb::getID(Activity::ATTEND), Verb::getID(Activity::ATTENDMAYBE)],
|
||||
'visible' => true, 'deleted' => false
|
||||
'vid' => [Verb::getID(Activity::ATTEND), Verb::getID(Activity::ATTENDMAYBE)],
|
||||
'visible' => true, 'deleted' => false
|
||||
];
|
||||
if (!Post::exists($condition)) {
|
||||
continue;
|
||||
|
@ -656,11 +654,11 @@ class Profile
|
|||
|
||||
$today = substr($strt, 0, 10) === DateTimeFormat::localNow('Y-m-d');
|
||||
|
||||
$rr['title'] = $title;
|
||||
$rr['title'] = $title;
|
||||
$rr['description'] = $description;
|
||||
$rr['date'] = DI::l10n()->getDay(DateTimeFormat::local($rr['start'], $bd_format)) . (($today) ? ' ' . DI::l10n()->t('[today]') : '');
|
||||
$rr['startime'] = $strt;
|
||||
$rr['today'] = $today;
|
||||
$rr['date'] = DI::l10n()->getDay(DateTimeFormat::local($rr['start'], $bd_format)) . (($today) ? ' ' . DI::l10n()->t('[today]') : '');
|
||||
$rr['startime'] = $strt;
|
||||
$rr['today'] = $today;
|
||||
|
||||
$r[] = $rr;
|
||||
}
|
||||
|
@ -669,11 +667,11 @@ class Profile
|
|||
}
|
||||
$tpl = Renderer::getMarkupTemplate('events_reminder.tpl');
|
||||
return Renderer::replaceMacros($tpl, [
|
||||
'$classtoday' => $classtoday,
|
||||
'$count' => count($r),
|
||||
'$classtoday' => $classtoday,
|
||||
'$count' => count($r),
|
||||
'$event_reminders' => DI::l10n()->t('Event Reminders'),
|
||||
'$event_title' => DI::l10n()->t('Upcoming events the next 7 days:'),
|
||||
'$events' => $r,
|
||||
'$event_title' => DI::l10n()->t('Upcoming events the next 7 days:'),
|
||||
'$events' => $r,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -708,9 +706,9 @@ class Profile
|
|||
public static function searchProfiles(int $start = 0, int $count = 100, string $search = null): array
|
||||
{
|
||||
if (!empty($search)) {
|
||||
$publish = (DI::config()->get('system', 'publish_all') ? '' : "AND `publish` ");
|
||||
$publish = (DI::config()->get('system', 'publish_all') ? '' : "AND `publish` ");
|
||||
$searchTerm = '%' . $search . '%';
|
||||
$condition = [
|
||||
$condition = [
|
||||
"`verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired`
|
||||
$publish
|
||||
AND ((`name` LIKE ?) OR
|
||||
|
@ -822,7 +820,7 @@ class Profile
|
|||
$profile['profile-name'] = null;
|
||||
$profile['is-default'] = null;
|
||||
DBA::update('profile', $profile, ['id' => $profile['id']]);
|
||||
} else if (!empty($profile['id'])) {
|
||||
} elseif (!empty($profile['id'])) {
|
||||
DBA::delete('profile', ['id' => $profile['id']]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,13 +26,13 @@ use Friendica\Util\Strings;
|
|||
*/
|
||||
class Tag
|
||||
{
|
||||
const UNKNOWN = 0;
|
||||
const HASHTAG = 1;
|
||||
const MENTION = 2;
|
||||
const UNKNOWN = 0;
|
||||
const HASHTAG = 1;
|
||||
const MENTION = 2;
|
||||
/**
|
||||
* An implicit mention is a mention in a comment body that is redundant with the threading information.
|
||||
*/
|
||||
const IMPLICIT_MENTION = 8;
|
||||
const IMPLICIT_MENTION = 8;
|
||||
/**
|
||||
* An exclusive mention transmits the post only to the target account without transmitting it to the followers, usually a group.
|
||||
*/
|
||||
|
@ -90,7 +90,7 @@ class Tag
|
|||
return;
|
||||
}
|
||||
|
||||
$cid = 0;
|
||||
$cid = 0;
|
||||
$tagid = 0;
|
||||
|
||||
if (in_array($type, [self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION, self::TO, self::CC, self::BTO, self::BCC, self::AUDIENCE, self::ATTRIBUTED])) {
|
||||
|
@ -137,7 +137,7 @@ class Tag
|
|||
$fields = ['uri-id' => $uriId, 'type' => $type, 'tid' => $tagid, 'cid' => $cid];
|
||||
|
||||
if (in_array($type, [self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION])) {
|
||||
$condition = $fields;
|
||||
$condition = $fields;
|
||||
$condition['type'] = [self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION];
|
||||
if (DBA::exists('post-tag', $condition)) {
|
||||
DI::logger()->info('Tag already exists', $fields);
|
||||
|
@ -528,9 +528,9 @@ class Tag
|
|||
public static function populateFromItem(array &$item): array
|
||||
{
|
||||
$return = [
|
||||
'tags' => [],
|
||||
'hashtags' => [],
|
||||
'mentions' => [],
|
||||
'tags' => [],
|
||||
'hashtags' => [],
|
||||
'mentions' => [],
|
||||
'implicit_mentions' => [],
|
||||
];
|
||||
|
||||
|
@ -556,7 +556,7 @@ class Tag
|
|||
}
|
||||
|
||||
$return['hashtags'][] = '<bdi>' . $prefix . '<a href="' . $tag['url'] . '" target="_blank" rel="noopener noreferrer">' . htmlspecialchars($tag['name']) . '</a></bdi>';
|
||||
$return['tags'][] = '<bdi>' . $prefix . '<a href="' . $tag['url'] . '" target="_blank" rel="noopener noreferrer">' . htmlspecialchars($tag['name']) . '</a></bdi>';
|
||||
$return['tags'][] = '<bdi>' . $prefix . '<a href="' . $tag['url'] . '" target="_blank" rel="noopener noreferrer">' . htmlspecialchars($tag['name']) . '</a></bdi>';
|
||||
break;
|
||||
|
||||
case self::MENTION:
|
||||
|
@ -567,7 +567,7 @@ class Tag
|
|||
$tag['url'] = Contact::magicLink($tag['url']);
|
||||
}
|
||||
$return['mentions'][] = '<bdi>' . $prefix . '<a href="' . $tag['url'] . '" target="_blank" rel="noopener noreferrer">' . htmlspecialchars($tag['name']) . '</a></bdi>';
|
||||
$return['tags'][] = '<bdi>' . $prefix . '<a href="' . $tag['url'] . '" target="_blank" rel="noopener noreferrer">' . htmlspecialchars($tag['name']) . '</a></bdi>';
|
||||
$return['tags'][] = '<bdi>' . $prefix . '<a href="' . $tag['url'] . '" target="_blank" rel="noopener noreferrer">' . htmlspecialchars($tag['name']) . '</a></bdi>';
|
||||
break;
|
||||
|
||||
case self::IMPLICIT_MENTION:
|
||||
|
@ -808,7 +808,7 @@ class Tag
|
|||
*/
|
||||
private static function getUIDListByTag(string $tag): array
|
||||
{
|
||||
$uids = [];
|
||||
$uids = [];
|
||||
$searches = DBA::select('search', ['uid'], ['term' => $tag]);
|
||||
while ($search = DBA::fetch($searches)) {
|
||||
$uids[] = $search['uid'];
|
||||
|
|
|
@ -84,12 +84,12 @@ class User
|
|||
* This will only be assigned to contacts, not to user accounts
|
||||
* @{
|
||||
*/
|
||||
const ACCOUNT_TYPE_PERSON = 0;
|
||||
const ACCOUNT_TYPE_PERSON = 0;
|
||||
const ACCOUNT_TYPE_ORGANISATION = 1;
|
||||
const ACCOUNT_TYPE_NEWS = 2;
|
||||
const ACCOUNT_TYPE_COMMUNITY = 3;
|
||||
const ACCOUNT_TYPE_RELAY = 4;
|
||||
const ACCOUNT_TYPE_DELETED = 127;
|
||||
const ACCOUNT_TYPE_NEWS = 2;
|
||||
const ACCOUNT_TYPE_COMMUNITY = 3;
|
||||
const ACCOUNT_TYPE_RELAY = 4;
|
||||
const ACCOUNT_TYPE_DELETED = 127;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
@ -150,42 +150,42 @@ class User
|
|||
}
|
||||
}
|
||||
|
||||
$system['name'] = App::PLATFORM . " '" . App::CODENAME . "' " . App::VERSION . '-' . DB_UPDATE_VERSION;
|
||||
$system['uprvkey'] = $system['prvkey'];
|
||||
$system['upubkey'] = $system['pubkey'];
|
||||
$system['nickname'] = $system['nick'];
|
||||
$system['page-flags'] = self::PAGE_FLAGS_SOAPBOX;
|
||||
$system['name'] = App::PLATFORM . " '" . App::CODENAME . "' " . App::VERSION . '-' . DB_UPDATE_VERSION;
|
||||
$system['uprvkey'] = $system['prvkey'];
|
||||
$system['upubkey'] = $system['pubkey'];
|
||||
$system['nickname'] = $system['nick'];
|
||||
$system['page-flags'] = self::PAGE_FLAGS_SOAPBOX;
|
||||
$system['account-type'] = $system['contact-type'];
|
||||
$system['guid'] = '';
|
||||
$system['picdate'] = '';
|
||||
$system['theme'] = '';
|
||||
$system['publish'] = false;
|
||||
$system['net-publish'] = false;
|
||||
$system['guid'] = '';
|
||||
$system['picdate'] = '';
|
||||
$system['theme'] = '';
|
||||
$system['publish'] = false;
|
||||
$system['net-publish'] = false;
|
||||
$system['hide-friends'] = true;
|
||||
$system['hidewall'] = true;
|
||||
$system['hidewall'] = true;
|
||||
$system['prv_keywords'] = '';
|
||||
$system['pub_keywords'] = '';
|
||||
$system['address'] = '';
|
||||
$system['locality'] = '';
|
||||
$system['region'] = '';
|
||||
$system['postal-code'] = '';
|
||||
$system['address'] = '';
|
||||
$system['locality'] = '';
|
||||
$system['region'] = '';
|
||||
$system['postal-code'] = '';
|
||||
$system['country-name'] = '';
|
||||
$system['homepage'] = (string)DI::baseUrl();
|
||||
$system['dob'] = '0000-00-00';
|
||||
$system['homepage'] = (string)DI::baseUrl();
|
||||
$system['dob'] = '0000-00-00';
|
||||
|
||||
// Ensure that the user contains data
|
||||
$user = DBA::selectFirst('user', ['prvkey', 'guid', 'language'], ['uid' => 0]);
|
||||
if (empty($user['prvkey']) || empty($user['guid'])) {
|
||||
$fields = [
|
||||
'username' => $system['name'],
|
||||
'nickname' => $system['nick'],
|
||||
'username' => $system['name'],
|
||||
'nickname' => $system['nick'],
|
||||
'register_date' => $system['created'],
|
||||
'pubkey' => $system['pubkey'],
|
||||
'prvkey' => $system['prvkey'],
|
||||
'guid' => System::createUUID(),
|
||||
'verified' => true,
|
||||
'page-flags' => self::PAGE_FLAGS_SOAPBOX,
|
||||
'account-type' => self::ACCOUNT_TYPE_RELAY,
|
||||
'pubkey' => $system['pubkey'],
|
||||
'prvkey' => $system['prvkey'],
|
||||
'guid' => System::createUUID(),
|
||||
'verified' => true,
|
||||
'page-flags' => self::PAGE_FLAGS_SOAPBOX,
|
||||
'account-type' => self::ACCOUNT_TYPE_RELAY,
|
||||
];
|
||||
|
||||
DBA::update('user', $fields, ['uid' => 0]);
|
||||
|
@ -349,12 +349,12 @@ class User
|
|||
DI::pConfig()->set($uid, 'system', 'unlisted', true);
|
||||
|
||||
$fields = [
|
||||
'allow_cid' => '',
|
||||
'allow_gid' => $user['page-flags'] == self::PAGE_FLAGS_PRVGROUP ? '<' . Circle::FOLLOWERS . '>' : '',
|
||||
'deny_cid' => '',
|
||||
'deny_gid' => '',
|
||||
'blockwall' => true,
|
||||
'blocktags' => true,
|
||||
'allow_cid' => '',
|
||||
'allow_gid' => $user['page-flags'] == self::PAGE_FLAGS_PRVGROUP ? '<' . Circle::FOLLOWERS . '>' : '',
|
||||
'deny_cid' => '',
|
||||
'deny_gid' => '',
|
||||
'blockwall' => true,
|
||||
'blocktags' => true,
|
||||
];
|
||||
|
||||
self::update($fields, $uid);
|
||||
|
@ -490,12 +490,12 @@ class User
|
|||
// Check if the returned data is valid, otherwise fix it. See issue #6122
|
||||
|
||||
// Check for correct url and normalised nurl
|
||||
$url = DI::baseUrl() . '/profile/' . $owner['nickname'];
|
||||
$url = DI::baseUrl() . '/profile/' . $owner['nickname'];
|
||||
$repair = empty($owner['baseurl']) || empty($owner['network']) || ($owner['url'] != $url) || ($owner['nurl'] != Strings::normaliseLink($owner['url']));
|
||||
|
||||
if (!$repair) {
|
||||
// Check if "addr" is present and correct
|
||||
$addr = $owner['nickname'] . '@' . substr(DI::baseUrl(), strpos(DI::baseUrl(), '://') + 3);
|
||||
$addr = $owner['nickname'] . '@' . substr(DI::baseUrl(), strpos(DI::baseUrl(), '://') + 3);
|
||||
$repair = ($addr != $owner['addr']) || empty($owner['prvkey']) || empty($owner['pubkey']);
|
||||
}
|
||||
|
||||
|
@ -628,7 +628,7 @@ class User
|
|||
$users = DBA::select('user', ['uid', 'language'], $condition);
|
||||
while ($user = DBA::fetch($users)) {
|
||||
$uids[] = $user['uid'];
|
||||
$code = DI::l10n()->toISO6391($user['language']);
|
||||
$code = DI::l10n()->toISO6391($user['language']);
|
||||
if (!in_array($code, $supported)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -644,7 +644,7 @@ class User
|
|||
$values = unserialize($channel['v']);
|
||||
if (!empty($values) && is_array($values)) {
|
||||
foreach ($values as $language) {
|
||||
$language = DI::l10n()->toISO6391($language);
|
||||
$language = DI::l10n()->toISO6391($language);
|
||||
$languages[$language] = $language;
|
||||
}
|
||||
}
|
||||
|
@ -807,11 +807,11 @@ class User
|
|||
} elseif (is_int($user_info) || is_string($user_info)) {
|
||||
$fields = ['uid', 'nickname', 'password', 'legacy_password'];
|
||||
if (is_int($user_info)) {
|
||||
$condition = [
|
||||
'uid' => $user_info,
|
||||
$condition = [
|
||||
'uid' => $user_info,
|
||||
'account_expired' => false,
|
||||
'account_removed' => false,
|
||||
'verified' => true
|
||||
'verified' => true
|
||||
];
|
||||
if (!$with_blocked) {
|
||||
$condition = DBA::mergeConditions($condition, ['blocked' => false]);
|
||||
|
@ -898,9 +898,9 @@ class User
|
|||
return $passwordExposedChecker->passwordExposed($password) === PasswordExposed\Enums\PasswordStatus::EXPOSED;
|
||||
} catch (Exception $e) {
|
||||
DI::logger()->error('Password Exposed Exception: ' . $e->getMessage(), [
|
||||
'code' => $e->getCode(),
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
'code' => $e->getCode(),
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
]);
|
||||
|
||||
|
@ -1001,9 +1001,9 @@ class User
|
|||
private static function updatePasswordHashed(int $uid, string $password_hashed): bool
|
||||
{
|
||||
$fields = [
|
||||
'password' => $password_hashed,
|
||||
'pwdreset' => null,
|
||||
'pwdreset_time' => null,
|
||||
'password' => $password_hashed,
|
||||
'pwdreset' => null,
|
||||
'pwdreset_time' => null,
|
||||
'legacy_password' => false
|
||||
];
|
||||
return DBA::update('user', $fields, ['uid' => $uid]);
|
||||
|
@ -1109,7 +1109,7 @@ class User
|
|||
break;
|
||||
}
|
||||
|
||||
$updated = '';
|
||||
$updated = '';
|
||||
$mimetype = '';
|
||||
|
||||
$photo = Photo::selectFirst(['type', 'created', 'edited', 'updated'], ["scale" => $scale, 'uid' => $user['uid'], 'profile' => true]);
|
||||
|
@ -1214,14 +1214,14 @@ class User
|
|||
throw new Exception(DI::l10n()->t('Invalid OpenID url'));
|
||||
}
|
||||
$_SESSION['register'] = 1;
|
||||
$_SESSION['openid'] = $openid_url;
|
||||
$_SESSION['openid'] = $openid_url;
|
||||
|
||||
$openid = new LightOpenID(DI::baseUrl()->getHost());
|
||||
/** @phpstan-ignore-next-line $openid->identity is private, but will be set via magic setter */
|
||||
$openid->identity = $openid_url;
|
||||
$openid->identity = $openid_url;
|
||||
$openid->returnUrl = DI::baseUrl() . '/openid';
|
||||
$openid->required = ['namePerson/friendly', 'contact/email', 'namePerson'];
|
||||
$openid->optional = ['namePerson/first', 'media/image/aspect11', 'media/image/default'];
|
||||
$openid->required = ['namePerson/friendly', 'contact/email', 'namePerson'];
|
||||
$openid->optional = ['namePerson/first', 'media/image/aspect11', 'media/image/default'];
|
||||
try {
|
||||
$authurl = $openid->authUrl();
|
||||
} catch (Exception $e) {
|
||||
|
@ -1246,7 +1246,7 @@ class User
|
|||
|
||||
if ($username_min_length > $username_max_length) {
|
||||
DI::logger()->error(DI::l10n()->t('system.username_min_length (%s) and system.username_max_length (%s) are excluding each other, swapping values.', $username_min_length, $username_max_length));
|
||||
$tmp = $username_min_length;
|
||||
$tmp = $username_min_length;
|
||||
$username_min_length = $username_max_length;
|
||||
$username_max_length = $tmp;
|
||||
}
|
||||
|
@ -1303,7 +1303,7 @@ class User
|
|||
throw new Exception(DI::l10n()->t('Nickname is already registered. Please choose another.'));
|
||||
}
|
||||
|
||||
$new_password = strlen($password) ? $password : self::generateNewPassword();
|
||||
$new_password = strlen($password) ? $password : self::generateNewPassword();
|
||||
$new_password_encoded = self::hashPassword($new_password);
|
||||
|
||||
$return['password'] = $new_password;
|
||||
|
@ -1317,24 +1317,24 @@ class User
|
|||
$pubkey = $keys['pubkey'];
|
||||
|
||||
$insert_result = DBA::insert('user', [
|
||||
'guid' => System::createUUID(),
|
||||
'username' => $username,
|
||||
'password' => $new_password_encoded,
|
||||
'email' => $email,
|
||||
'openid' => $openid_url,
|
||||
'nickname' => $nickname,
|
||||
'pubkey' => $pubkey,
|
||||
'prvkey' => $prvkey,
|
||||
'verified' => $verified,
|
||||
'blocked' => $blocked,
|
||||
'language' => $language,
|
||||
'timezone' => 'UTC',
|
||||
'register_date' => DateTimeFormat::utcNow(),
|
||||
'guid' => System::createUUID(),
|
||||
'username' => $username,
|
||||
'password' => $new_password_encoded,
|
||||
'email' => $email,
|
||||
'openid' => $openid_url,
|
||||
'nickname' => $nickname,
|
||||
'pubkey' => $pubkey,
|
||||
'prvkey' => $prvkey,
|
||||
'verified' => $verified,
|
||||
'blocked' => $blocked,
|
||||
'language' => $language,
|
||||
'timezone' => 'UTC',
|
||||
'register_date' => DateTimeFormat::utcNow(),
|
||||
'default-location' => ''
|
||||
]);
|
||||
|
||||
if ($insert_result) {
|
||||
$uid = DBA::lastInsertId();
|
||||
$uid = DBA::lastInsertId();
|
||||
$user = DBA::selectFirst('user', [], ['uid' => $uid]);
|
||||
} else {
|
||||
throw new Exception(DI::l10n()->t('An error occurred during registration. Please try again.'));
|
||||
|
@ -1354,11 +1354,11 @@ class User
|
|||
}
|
||||
|
||||
$insert_result = DBA::insert('profile', [
|
||||
'uid' => $uid,
|
||||
'name' => $username,
|
||||
'photo' => self::getAvatarUrl($user),
|
||||
'thumb' => self::getAvatarUrl($user, Proxy::SIZE_THUMB),
|
||||
'publish' => $publish,
|
||||
'uid' => $uid,
|
||||
'name' => $username,
|
||||
'photo' => self::getAvatarUrl($user),
|
||||
'thumb' => self::getAvatarUrl($user, Proxy::SIZE_THUMB),
|
||||
'publish' => $publish,
|
||||
'net-publish' => $netpublish,
|
||||
]);
|
||||
if (!$insert_result) {
|
||||
|
@ -1410,15 +1410,15 @@ class User
|
|||
if ($curlResult->isSuccess()) {
|
||||
DI::logger()->debug('Got picture', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $photo]);
|
||||
$img_str = $curlResult->getBodyString();
|
||||
$type = $curlResult->getContentType();
|
||||
$type = $curlResult->getContentType();
|
||||
} else {
|
||||
$img_str = '';
|
||||
$type = '';
|
||||
$type = '';
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
DI::logger()->notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
|
||||
$img_str = '';
|
||||
$type = '';
|
||||
$type = '';
|
||||
}
|
||||
|
||||
$image = new Image($img_str, $type, $photo);
|
||||
|
@ -1496,7 +1496,7 @@ class User
|
|||
* @param bool $block Block state (default is true)
|
||||
*
|
||||
* @return bool True, if successfully blocked
|
||||
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function block(int $uid, bool $block = true): bool
|
||||
|
@ -1601,21 +1601,21 @@ class User
|
|||
public static function createMinimal(string $name, string $email, string $nick, string $lang = L10n::DEFAULT, string $avatar = ''): bool
|
||||
{
|
||||
if (empty($name) ||
|
||||
empty($email) ||
|
||||
empty($nick)) {
|
||||
empty($email) ||
|
||||
empty($nick)) {
|
||||
throw new HTTPException\InternalServerErrorException('Invalid arguments.');
|
||||
}
|
||||
|
||||
$result = self::create([
|
||||
'username' => $name,
|
||||
'email' => $email,
|
||||
'email' => $email,
|
||||
'nickname' => $nick,
|
||||
'verified' => 1,
|
||||
'language' => $lang,
|
||||
'photo' => $avatar
|
||||
'photo' => $avatar
|
||||
]);
|
||||
|
||||
$user = $result['user'];
|
||||
$user = $result['user'];
|
||||
$preamble = Strings::deindent(DI::l10n()->t('
|
||||
Dear %1$s,
|
||||
the administrator of %2$s has set up an account for you.'));
|
||||
|
@ -1647,7 +1647,7 @@ class User
|
|||
Thank you and welcome to %4$s.'));
|
||||
|
||||
$preamble = sprintf($preamble, $user['username'], DI::config()->get('config', 'sitename'));
|
||||
$body = sprintf($body, DI::baseUrl(), $user['nickname'], $result['password'], DI::config()->get('config', 'sitename'));
|
||||
$body = sprintf($body, DI::baseUrl(), $user['nickname'], $result['password'], DI::config()->get('config', 'sitename'));
|
||||
|
||||
$email = DI::emailer()
|
||||
->newSystemMail()
|
||||
|
@ -1848,7 +1848,7 @@ class User
|
|||
if (!$user['parent-uid']) {
|
||||
// First add our own entry
|
||||
$identities = [[
|
||||
'uid' => $user['uid'],
|
||||
'uid' => $user['uid'],
|
||||
'username' => $user['username'],
|
||||
'nickname' => $user['nickname']
|
||||
]];
|
||||
|
@ -1946,17 +1946,20 @@ class User
|
|||
'active_users_weekly' => 0,
|
||||
];
|
||||
|
||||
$userStmt = DBA::select('owner-view', ['uid', 'last-activity', 'last-item'],
|
||||
$userStmt = DBA::select(
|
||||
'owner-view',
|
||||
['uid', 'last-activity', 'last-item'],
|
||||
["`verified` AND `last-activity` > ? AND NOT `blocked`
|
||||
AND NOT `account_removed` AND NOT `account_expired`",
|
||||
DBA::NULL_DATETIME]);
|
||||
DBA::NULL_DATETIME]
|
||||
);
|
||||
if (!DBA::isResult($userStmt)) {
|
||||
return $statistics;
|
||||
}
|
||||
|
||||
$halfyear = time() - (180 * 24 * 60 * 60);
|
||||
$month = time() - (30 * 24 * 60 * 60);
|
||||
$week = time() - (7 * 24 * 60 * 60);
|
||||
$month = time() - (30 * 24 * 60 * 60);
|
||||
$week = time() - (7 * 24 * 60 * 60);
|
||||
|
||||
while ($user = DBA::fetch($userStmt)) {
|
||||
$statistics['total_users']++;
|
||||
|
@ -1994,18 +1997,18 @@ class User
|
|||
*/
|
||||
public static function getList(int $start = 0, int $count = Pager::ITEMS_PER_PAGE, string $type = 'all', string $order = 'name', bool $descending = false)
|
||||
{
|
||||
$param = ['limit' => [$start, $count], 'order' => [$order => $descending]];
|
||||
$param = ['limit' => [$start, $count], 'order' => [$order => $descending]];
|
||||
$condition = [];
|
||||
switch ($type) {
|
||||
case 'active':
|
||||
$condition['account_removed'] = false;
|
||||
$condition['blocked'] = false;
|
||||
$condition['blocked'] = false;
|
||||
break;
|
||||
|
||||
case 'blocked':
|
||||
$condition['account_removed'] = false;
|
||||
$condition['blocked'] = true;
|
||||
$condition['verified'] = true;
|
||||
$condition['blocked'] = true;
|
||||
$condition['verified'] = true;
|
||||
break;
|
||||
|
||||
case 'removed':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue