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']]); DBA::delete('item-delivery-data', ['iid' => $item['id']]);
//if (!empty($item['iaid']) && !self::exists(['iaid' => $item['iaid'], 'deleted' => false])) { // We don't delete the item-activity here, since we need some of the data for ActivityPub
// DBA::delete('item-activity', ['id' => $item['iaid']], ['cascade' => false]);
//}
if (!empty($item['icid']) && !self::exists(['icid' => $item['icid'], 'deleted' => false])) { if (!empty($item['icid']) && !self::exists(['icid' => $item['icid'], 'deleted' => false])) {
DBA::delete('item-content', ['id' => $item['icid']], ['cascade' => false]); DBA::delete('item-content', ['id' => $item['icid']], ['cascade' => false]);
} }

View File

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

View File

@ -33,9 +33,9 @@ class Term
return $tag_text; 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); $tags = DBA::select('term', ['type', 'term', 'url'], $condition);
if (!DBA::isResult($tags)) { if (!DBA::isResult($tags)) {
return []; return [];

View File

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

View File

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

View File

@ -338,10 +338,8 @@ class Probe
$ap_profile = ActivityPub::probeProfile($uri); $ap_profile = ActivityPub::probeProfile($uri);
if (!empty($ap_profile) && (defaults($data, 'network', '') != Protocol::DFRN)) { 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"])) { if (!isset($data["url"])) {
$data["url"] = $uri; $data["url"] = $uri;

View File

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