1
0
Fork 0

Some changes for better code quality

This commit is contained in:
Michael 2018-09-30 07:21:57 +00:00
parent b043c7e0f2
commit 82987d018a
7 changed files with 17 additions and 23 deletions

View file

@ -1081,9 +1081,8 @@ class Item extends BaseObject
DBA::delete('item-delivery-data', ['iid' => $item['id']]);
//if (!empty($item['iaid']) && !self::exists(['iaid' => $item['iaid'], 'deleted' => false])) {
// DBA::delete('item-activity', ['id' => $item['iaid']], ['cascade' => false]);
//}
// We don't delete the item-activity here, since we need some of the data for ActivityPub
if (!empty($item['icid']) && !self::exists(['icid' => $item['icid'], 'deleted' => false])) {
DBA::delete('item-content', ['id' => $item['icid']], ['cascade' => false]);
}

View file

@ -35,7 +35,7 @@ class Profile
*
* @return array Profile data
*/
public static function getProfileForUser($uid)
public static function getByUID($uid)
{
$profile = DBA::selectFirst('profile', [], ['uid' => $uid, 'is-default' => true]);
return $profile;

View file

@ -33,9 +33,9 @@ class Term
return $tag_text;
}
public static function tagArrayFromItemId($itemid)
public static function tagArrayFromItemId($itemid, $type = [TERM_HASHTAG, TERM_MENTION])
{
$condition = ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => [TERM_HASHTAG, TERM_MENTION]];
$condition = ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => $type];
$tags = DBA::select('term', ['type', 'term', 'url'], $condition);
if (!DBA::isResult($tags)) {
return [];

View file

@ -29,10 +29,10 @@ class Outbox extends BaseModule
$page = defaults($_REQUEST, 'page', null);
$Outbox = ActivityPub::getOutbox($owner, $page);
$outbox = ActivityPub::getOutbox($owner, $page);
header('Content-Type: application/activity+json');
echo json_encode($Outbox);
echo json_encode($outbox);
exit();
}
}

View file

@ -54,7 +54,7 @@ class Owa extends BaseModule
if (DBA::isResult($contact)) {
// Try to verify the signed header with the public key of the contact record
// we have found.
$verified = HTTPSignature:verifyMagic($contact['pubkey']);
$verified = HTTPSignature::verifyMagic($contact['pubkey']);
if ($verified && $verified['header_signed'] && $verified['header_valid']) {
logger('OWA header: ' . print_r($verified, true), LOGGER_DATA);

View file

@ -338,9 +338,7 @@ class Probe
$ap_profile = ActivityPub::probeProfile($uri);
if (!empty($ap_profile) && (defaults($data, 'network', '') != Protocol::DFRN)) {
if (!empty($ap_profile) && ($ap_profile['network'] == Protocol::ACTIVITYPUB)) {
$data = $ap_profile;
}
$data = $ap_profile;
}
if (!isset($data["url"])) {

View file

@ -113,7 +113,7 @@ class ActivityPub
$data['totalItems'] = $count;
// When we hide our friends we will only show the pure number but don't allow more.
$profile = Profile::getProfileForUser($owner['uid']);
$profile = Profile::getByUID($owner['uid']);
if (!empty($profile['hide-friends'])) {
return $data;
}
@ -160,7 +160,7 @@ class ActivityPub
$data['totalItems'] = $count;
// When we hide our friends we will only show the pure number but don't allow more.
$profile = Profile::getProfileForUser($owner['uid']);
$profile = Profile::getByUID($owner['uid']);
if (!empty($profile['hide-friends'])) {
return $data;
}
@ -323,8 +323,7 @@ class ActivityPub
$permissions['to'][] = $actor;
$elements = ['to', 'cc', 'bto', 'bcc'];
foreach ($elements as $element) {
foreach (['to', 'cc', 'bto', 'bcc'] as $element) {
if (empty($activity[$element])) {
continue;
}
@ -359,7 +358,7 @@ class ActivityPub
$actor_profile = APContact::getProfileByURL($item['author-link']);
$terms = Term::tagArrayFromItemId($item['id']);
$terms = Term::tagArrayFromItemId($item['id'], TERM_MENTION);
$contacts[$item['author-link']] = $item['author-link'];
@ -461,8 +460,7 @@ class ActivityPub
$item_profile = APContact::getProfileByURL($item['owner-link']);
}
$elements = ['to', 'cc', 'bto', 'bcc'];
foreach ($elements as $element) {
foreach (['to', 'cc', 'bto', 'bcc'] as $element) {
if (empty($permissions[$element])) {
continue;
}
@ -624,7 +622,7 @@ class ActivityPub
{
$tags = [];
$terms = Term::tagArrayFromItemId($item['id']);
$terms = Term::tagArrayFromItemId($item['id'], TERM_MENTION);
foreach ($terms as $term) {
if ($term['type'] == TERM_MENTION) {
$contact = Contact::getDetailsByURL($term['url']);
@ -1160,13 +1158,12 @@ class ActivityPub
$followers = '';
}
$elements = ['to', 'cc', 'bto', 'bcc'];
foreach ($elements as $element) {
foreach (['to', 'cc', 'bto', 'bcc'] as $element) {
if (empty($activity[$element])) {
continue;
}
// The receiver can be an arror or a string
// The receiver can be an array or a string
if (is_string($activity[$element])) {
$activity[$element] = [$activity[$element]];
}