]> git.mxchange.org Git - friendica.git/commitdiff
Some changes for better code quality
authorMichael <heluecht@pirati.ca>
Sun, 30 Sep 2018 07:21:57 +0000 (07:21 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 30 Sep 2018 07:21:57 +0000 (07:21 +0000)
src/Model/Item.php
src/Model/Profile.php
src/Model/Term.php
src/Module/Outbox.php
src/Module/Owa.php
src/Network/Probe.php
src/Protocol/ActivityPub.php

index 619f5dc34927a28aad7447bdb6a6c06b9e778228..2c9be633a9ae8083e1c2178d140bfac0895ed5a9 100644 (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]);
                }
index d25bdd4fadbdd5f5c04951f06e117c8170c79636..cb2754cc80ce6a8ef218421ec7952ccb00327fed 100644 (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;
index 262312532995c1b1b2753fc0c5dcc311e7ef0a20..fb7670a3066276ab05012718f72f0c2231255261 100644 (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 [];
index 722315145f1b3b9682254cfab1e848aab5b2aad0..8ddc861836eebe7d24d55317d30ee12fb819cee6 100644 (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();
        }
 }
index 68f31c59de23aab272d19b7a17b1254c259affeb..7a5fe128c8424cea51c99de816e95dfae501a01b 100644 (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);
index b19f34b7625c241e273c8f897c5adaa22f829f79..2c84ddb85a8312f42a6e3f5d5723051e56045161 100644 (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"])) {
index a02031f0030a2a911983c0c95a06f255e8133780..58bd9dcfe1719e22131ccc061dc10e7f99dbd496 100644 (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]];
                        }