From 82987d018ae680cd937c5bdf4ffe71143644988d Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 30 Sep 2018 07:21:57 +0000 Subject: [PATCH] Some changes for better code quality --- src/Model/Item.php | 5 ++--- src/Model/Profile.php | 2 +- src/Model/Term.php | 4 ++-- src/Module/Outbox.php | 4 ++-- src/Module/Owa.php | 2 +- src/Network/Probe.php | 4 +--- src/Protocol/ActivityPub.php | 19 ++++++++----------- 7 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 619f5dc349..2c9be633a9 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -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]); } diff --git a/src/Model/Profile.php b/src/Model/Profile.php index d25bdd4fad..cb2754cc80 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -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; diff --git a/src/Model/Term.php b/src/Model/Term.php index 2623125329..fb7670a306 100644 --- a/src/Model/Term.php +++ b/src/Model/Term.php @@ -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 []; diff --git a/src/Module/Outbox.php b/src/Module/Outbox.php index 722315145f..8ddc861836 100644 --- a/src/Module/Outbox.php +++ b/src/Module/Outbox.php @@ -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(); } } diff --git a/src/Module/Owa.php b/src/Module/Owa.php index 68f31c59de..7a5fe128c8 100644 --- a/src/Module/Owa.php +++ b/src/Module/Owa.php @@ -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); diff --git a/src/Network/Probe.php b/src/Network/Probe.php index b19f34b762..2c84ddb85a 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -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"])) { diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index a02031f003..58bd9dcfe1 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -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]]; } -- 2.39.5