Move Activity/Namespaces defines to constants
authorPhilipp Holzer <admin+github@philipp.info>
Wed, 23 Oct 2019 22:25:42 +0000 (00:25 +0200)
committerPhilipp Holzer <admin+github@philipp.info>
Wed, 23 Oct 2019 22:25:42 +0000 (00:25 +0200)
mailstream/mailstream.php
pumpio/pumpio.php
statusnet/statusnet.php
twitter/twitter.php

index a58dfc1..d6d880f 100644 (file)
@@ -14,6 +14,7 @@ use Friendica\Core\Logger;
 use Friendica\Core\PConfig;
 use Friendica\Core\Renderer;
 use Friendica\Database\DBA;
+use Friendica\Protocol\Activity;
 use Friendica\Util\Network;
 use Friendica\Model\Item;
 
@@ -122,7 +123,7 @@ function mailstream_post_hook(&$a, &$item) {
                return;
        }
        if (PConfig::get($item['uid'], 'mailstream', 'nolikes')) {
-               if ($item['verb'] == ACTIVITY_LIKE) {
+               if ($item['verb'] == Activity::LIKE) {
                        Logger::debug('mailstream: like item ' . $item['id']);
                        return;
                }
index 537bf28..7bbaf24 100644 (file)
@@ -21,6 +21,7 @@ use Friendica\Model\Contact;
 use Friendica\Model\Group;
 use Friendica\Model\Item;
 use Friendica\Model\User;
+use Friendica\Protocol\Activity;
 use Friendica\Util\ConfigFileLoader;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
@@ -480,7 +481,7 @@ function pumpio_send(App $a, array &$b)
                }
        }
 
-       if ($b['verb'] == ACTIVITY_LIKE) {
+       if ($b['verb'] == Activity::LIKE) {
                if ($b['deleted']) {
                        pumpio_action($a, $b["uid"], $b["thr-parent"], "unlike");
                } else {
@@ -489,15 +490,15 @@ function pumpio_send(App $a, array &$b)
                return;
        }
 
-       if ($b['verb'] == ACTIVITY_DISLIKE) {
+       if ($b['verb'] == Activity::DISLIKE) {
                return;
        }
 
-       if (($b['verb'] == ACTIVITY_POST) && ($b['created'] !== $b['edited']) && !$b['deleted']) {
+       if (($b['verb'] == Activity::POST) && ($b['created'] !== $b['edited']) && !$b['deleted']) {
                pumpio_action($a, $b["uid"], $b["uri"], "update", $b["body"]);
        }
 
-       if (($b['verb'] == ACTIVITY_POST) && $b['deleted']) {
+       if (($b['verb'] == Activity::POST) && $b['deleted']) {
                pumpio_action($a, $b["uid"], $b["uri"], "delete");
        }
 
@@ -560,8 +561,8 @@ function pumpio_send(App $a, array &$b)
                        $inReplyTo = ["id" => $orig_post["uri"],
                                "objectType" => "note"];
 
-                       if (($orig_post["object-type"] != "") && (strstr($orig_post["object-type"], NAMESPACE_ACTIVITY_SCHEMA))) {
-                               $inReplyTo["objectType"] = str_replace(NAMESPACE_ACTIVITY_SCHEMA, '', $orig_post["object-type"]);
+                       if (($orig_post["object-type"] != "") && (strstr($orig_post["object-type"], Activity\Namespaces::ACTIVITY_SCHEMA))) {
+                               $inReplyTo["objectType"] = str_replace(Activity\Namespaces::ACTIVITY_SCHEMA, '', $orig_post["object-type"]);
                        }
 
                        $params["object"] = [
@@ -636,8 +637,8 @@ function pumpio_action(App $a, $uid, $uri, $action, $content = "")
                $uri = $orig_post["uri"];
        }
 
-       if (($orig_post["object-type"] != "") && (strstr($orig_post["object-type"], NAMESPACE_ACTIVITY_SCHEMA))) {
-               $objectType = str_replace(NAMESPACE_ACTIVITY_SCHEMA, '', $orig_post["object-type"]);
+       if (($orig_post["object-type"] != "") && (strstr($orig_post["object-type"], Activity\Namespaces::ACTIVITY_SCHEMA))) {
+               $objectType = str_replace(Activity\Namespaces::ACTIVITY_SCHEMA, '', $orig_post["object-type"]);
        } elseif (strstr($uri, "/api/comment/")) {
                $objectType = "comment";
        } elseif (strstr($uri, "/api/note/")) {
@@ -914,7 +915,7 @@ function pumpio_dounlike(App $a, $uid, $self, $post, $own_id)
                }
        }
 
-       Item::delete(['verb' => ACTIVITY_LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']]);
+       Item::delete(['verb' => Activity::LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']]);
 
        if (DBA::isResult($r)) {
                Logger::log("pumpio_dounlike: unliked existing like. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']);
@@ -969,7 +970,7 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion =
                }
        }
 
-       $condition = ['verb' => ACTIVITY_LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']];
+       $condition = ['verb' => Activity::LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']];
        if (Item::exists($condition)) {
                Logger::log("pumpio_dolike: found existing like. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']);
                return;
@@ -977,7 +978,7 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion =
 
        $likedata = [];
        $likedata['parent'] = $orig_post['id'];
-       $likedata['verb'] = ACTIVITY_LIKE;
+       $likedata['verb'] = Activity::LIKE;
        $likedata['gravity'] = GRAVITY_ACTIVITY;
        $likedata['uid'] = $uid;
        $likedata['wall'] = 0;
@@ -996,11 +997,11 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion =
        $objauthor =  '[url=' . $orig_post['author-link'] . ']' . $orig_post['author-name'] . '[/url]';
        $post_type = L10n::t('status');
        $plink = '[url=' . $orig_post['plink'] . ']' . $post_type . '[/url]';
-       $likedata['object-type'] = ACTIVITY_OBJ_NOTE;
+       $likedata['object-type'] = Activity::OBJ_NOTE;
 
        $likedata['body'] = L10n::t('%1$s likes %2$s\'s %3$s', $author, $objauthor, $plink);
 
-       $likedata['object'] = '<object><type>' . ACTIVITY_OBJ_NOTE . '</type><local>1</local>' .
+       $likedata['object'] = '<object><type>' . Activity::OBJ_NOTE . '</type><local>1</local>' .
                '<id>' . $orig_post['uri'] . '</id><link>' . XML::escape('<link rel="alternate" type="text/html" href="' . XML::escape($orig_post['plink']) . '" />') . '</link><title>' . $orig_post['title'] . '</title><content>' . $orig_post['body'] . '</content></object>';
 
        $ret = Item::insert($likedata);
@@ -1147,7 +1148,7 @@ function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcomp
        $postarray['uid'] = $uid;
        $postarray['wall'] = 0;
        $postarray['uri'] = $post->object->id;
-       $postarray['object-type'] = NAMESPACE_ACTIVITY_SCHEMA.strtolower($post->object->objectType);
+       $postarray['object-type'] = Activity\Namespaces::ACTIVITY_SCHEMA.strtolower($post->object->objectType);
 
        if ($post->object->objectType != "comment") {
                $contact_id = pumpio_get_contact($uid, $post->actor);
@@ -1230,7 +1231,7 @@ function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcomp
        }
 
        $postarray['contact-id'] = $contact_id;
-       $postarray['verb'] = ACTIVITY_POST;
+       $postarray['verb'] = Activity::POST;
        $postarray['owner-name'] = $post->actor->displayName;
        $postarray['owner-link'] = $post->actor->url;
        $postarray['author-name'] = $postarray['owner-name'];
index ed7b87d..f78252f 100644 (file)
@@ -56,6 +56,7 @@ use Friendica\Model\Item;
 use Friendica\Model\ItemContent;
 use Friendica\Model\Photo;
 use Friendica\Model\User;
+use Friendica\Protocol\Activity;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\Strings;
@@ -550,11 +551,11 @@ function statusnet_post_hook(App $a, &$b)
                }
        }
 
-       if (($b['verb'] == ACTIVITY_POST) && $b['deleted']) {
+       if (($b['verb'] == Activity::POST) && $b['deleted']) {
                statusnet_action($a, $b["uid"], substr($orig_post["uri"], $hostlength), "delete");
        }
 
-       if ($b['verb'] == ACTIVITY_LIKE) {
+       if ($b['verb'] == Activity::LIKE) {
                Logger::log("statusnet_post_hook: parameter 2 " . substr($b["thr-parent"], $hostlength), Logger::DEBUG);
                if ($b['deleted'])
                        statusnet_action($a, $b["uid"], substr($b["thr-parent"], $hostlength), "unlike");
@@ -1139,11 +1140,11 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex
                        $postarray['thr-parent'] = $item['uri'];
                        $postarray['parent-uri'] = $item['parent-uri'];
                        $postarray['parent'] = $item['parent'];
-                       $postarray['object-type'] = ACTIVITY_OBJ_COMMENT;
+                       $postarray['object-type'] = Activity::OBJ_COMMENT;
                } else {
                        $postarray['thr-parent'] = $postarray['uri'];
                        $postarray['parent-uri'] = $postarray['uri'];
-                       $postarray['object-type'] = ACTIVITY_OBJ_NOTE;
+                       $postarray['object-type'] = Activity::OBJ_NOTE;
                }
 
                // Is it me?
@@ -1167,7 +1168,7 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex
                $create_user = false;
        } else {
                $postarray['parent-uri'] = $postarray['uri'];
-               $postarray['object-type'] = ACTIVITY_OBJ_NOTE;
+               $postarray['object-type'] = Activity::OBJ_NOTE;
        }
 
        if ($contactid == 0) {
@@ -1184,7 +1185,7 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex
 
        $postarray['contact-id'] = $contactid;
 
-       $postarray['verb'] = ACTIVITY_POST;
+       $postarray['verb'] = Activity::POST;
 
        $postarray['author-name'] = $content->user->name;
        $postarray['author-link'] = $content->user->statusnet_profile_url;
index a43e835..9a2aea7 100644 (file)
@@ -85,6 +85,7 @@ use Friendica\Model\Item;
 use Friendica\Model\ItemContent;
 use Friendica\Model\User;
 use Friendica\Object\Image;
+use Friendica\Protocol\Activity;
 use Friendica\Util\ConfigFileLoader;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
@@ -556,11 +557,11 @@ function twitter_post_hook(App $a, array &$b)
                }
        }
 
-       if (($b['verb'] == ACTIVITY_POST) && $b['deleted']) {
+       if (($b['verb'] == Activity::POST) && $b['deleted']) {
                twitter_action($a, $b["uid"], substr($orig_post["uri"], 9), "delete");
        }
 
-       if ($b['verb'] == ACTIVITY_LIKE) {
+       if ($b['verb'] == Activity::LIKE) {
                Logger::log("twitter_post_hook: parameter 2 " . substr($b["thr-parent"], 9), Logger::DEBUG);
                if ($b['deleted']) {
                        twitter_action($a, $b["uid"], substr($b["thr-parent"], 9), "unlike");
@@ -1340,7 +1341,7 @@ function twitter_media_entities($post, array &$postarray)
                                        $media[$medium->url] .= "\n[img]" . $medium->media_url_https . '[/img]';
                                }
 
-                               $postarray['object-type'] = ACTIVITY_OBJ_IMAGE;
+                               $postarray['object-type'] = Activity::OBJ_IMAGE;
                                break;
                        case 'video':
                        case 'animated_gif':
@@ -1351,7 +1352,7 @@ function twitter_media_entities($post, array &$postarray)
                                        $media[$medium->url] .= "\n[img]" . $medium->media_url_https . '[/img]';
                                }
 
-                               $postarray['object-type'] = ACTIVITY_OBJ_VIDEO;
+                               $postarray['object-type'] = Activity::OBJ_VIDEO;
                                if (is_array($medium->video_info->variants)) {
                                        $bitrate = 0;
                                        // We take the video with the highest bitrate
@@ -1408,11 +1409,11 @@ function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $onl
                        $postarray['thr-parent'] = $parent_item['uri'];
                        $postarray['parent-uri'] = $parent_item['parent-uri'];
                        $postarray['parent'] = $parent_item['parent'];
-                       $postarray['object-type'] = ACTIVITY_OBJ_COMMENT;
+                       $postarray['object-type'] = Activity::OBJ_COMMENT;
                } else {
                        $postarray['thr-parent'] = $postarray['uri'];
                        $postarray['parent-uri'] = $postarray['uri'];
-                       $postarray['object-type'] = ACTIVITY_OBJ_NOTE;
+                       $postarray['object-type'] = Activity::OBJ_NOTE;
                }
 
                // Is it me?
@@ -1437,7 +1438,7 @@ function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $onl
                $create_user = false;
        } else {
                $postarray['parent-uri'] = $postarray['uri'];
-               $postarray['object-type'] = ACTIVITY_OBJ_NOTE;
+               $postarray['object-type'] = Activity::OBJ_NOTE;
        }
 
        if ($contactid == 0) {
@@ -1457,7 +1458,7 @@ function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $onl
 
        $postarray['contact-id'] = $contactid;
 
-       $postarray['verb'] = ACTIVITY_POST;
+       $postarray['verb'] = Activity::POST;
        $postarray['author-name'] = $postarray['owner-name'];
        $postarray['author-link'] = $postarray['owner-link'];
        $postarray['author-avatar'] = $postarray['owner-avatar'];
@@ -1480,7 +1481,7 @@ function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $onl
 
        // When the post contains links then use the correct object type
        if (count($post->entities->urls) > 0) {
-               $postarray['object-type'] = ACTIVITY_OBJ_BOOKMARK;
+               $postarray['object-type'] = Activity::OBJ_BOOKMARK;
        }
 
        // Search for media links
@@ -1518,9 +1519,9 @@ function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $onl
                        Item::insert($retweet);
 
                        // CHange the other post into a reshare activity
-                       $postarray['verb'] = ACTIVITY2_ANNOUNCE;
+                       $postarray['verb'] = Activity::ANNOUNCE;
                        $postarray['gravity'] = GRAVITY_ACTIVITY;
-                       $postarray['object-type'] = ACTIVITY_OBJ_NOTE;
+                       $postarray['object-type'] = Activity::OBJ_NOTE;
 
                        $postarray['thr-parent'] = $retweet['uri'];
                        $postarray['parent-uri'] = $retweet['uri'];