From 3897c74debb303c45c3678d379edea4d3b480fbc Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Fri, 25 Oct 2019 00:10:20 +0200 Subject: [PATCH] Add docs --- include/conversation.php | 14 +- mod/item.php | 14 +- mod/photos.php | 8 +- mod/poke.php | 4 +- mod/subthread.php | 3 +- mod/tagger.php | 7 +- src/Content/Text/BBCode.php | 2 +- src/Model/Contact.php | 2 +- src/Model/Event.php | 6 +- src/Model/Item.php | 10 +- src/Object/Post.php | 4 +- src/Protocol/Activity.php | 179 ++++++++++++++++++++----- src/Protocol/Activity/ANamespace.php | 105 +++++++++++++++ src/Protocol/Activity/ObjectType.php | 103 ++++++++++++++ src/Protocol/ActivityPub/Processor.php | 16 +-- src/Protocol/DFRN.php | 20 +-- src/Protocol/Diaspora.php | 10 +- src/Protocol/Feed.php | 4 +- src/Protocol/OStatus.php | 36 ++--- src/Worker/OnePoll.php | 2 +- tests/src/Protocol/ActivityTest.php | 12 +- 21 files changed, 439 insertions(+), 122 deletions(-) create mode 100644 src/Protocol/Activity/ObjectType.php diff --git a/include/conversation.php b/include/conversation.php index 75a8f020be..84e47d34e3 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -27,12 +27,12 @@ use Friendica\Model\Term; use Friendica\Object\Post; use Friendica\Object\Thread; use Friendica\Protocol\Activity; +use Friendica\Util\Crypto; use Friendica\Util\DateTimeFormat; use Friendica\Util\Proxy as ProxyUtils; -use Friendica\Util\Temporal; use Friendica\Util\Strings; +use Friendica\Util\Temporal; use Friendica\Util\XML; -use Friendica\Util\Crypto; function item_extract_images($body) { @@ -163,7 +163,7 @@ function localize_item(&$item) switch ($obj['verb']) { case Activity::POST: switch ($obj['object-type']) { - case Activity::OBJ_EVENT: + case Activity\ObjectType::EVENT: $post_type = L10n::t('event'); break; default: @@ -201,7 +201,7 @@ function localize_item(&$item) if ($activity->match($item['verb'], Activity::FRIEND)) { - if ($item['object-type']=="" || $item['object-type']!== Activity::OBJ_PERSON) return; + if ($item['object-type']=="" || $item['object-type']!== Activity\ObjectType::PERSON) return; $Aname = $item['author-name']; $Alink = $item['author-link']; @@ -236,7 +236,7 @@ function localize_item(&$item) if (!$verb) { return; } - if ($item['object-type']=="" || $item['object-type']!== Activity::OBJ_PERSON) { + if ($item['object-type']=="" || $item['object-type']!== Activity\ObjectType::PERSON) { return; } @@ -300,7 +300,7 @@ function localize_item(&$item) switch ($obj['verb']) { case Activity::POST: switch ($obj['object-type']) { - case Activity::OBJ_EVENT: + case Activity\ObjectType::EVENT: $post_type = L10n::t('event'); break; default: @@ -408,7 +408,7 @@ function visible_activity($item) { // @TODO below if() block can be rewritten to a single line: $isVisible = allConditionsHere; if ($activity->match($item['verb'], Activity::FOLLOW) && - $item['object-type'] === Activity::OBJ_NOTE && + $item['object-type'] === Activity\ObjectType::NOTE && empty($item['self']) && $item['uid'] == local_user()) { return false; diff --git a/mod/item.php b/mod/item.php index bc69ff7c3c..a96d288193 100644 --- a/mod/item.php +++ b/mod/item.php @@ -134,7 +134,7 @@ function item_post(App $a) { $toplevel_item_id = $toplevel_item['id']; $parent_user = $toplevel_item['uid']; - $objecttype = Activity::OBJ_COMMENT; + $objecttype = Activity\ObjectType::COMMENT; } if ($toplevel_item_id) { @@ -467,7 +467,7 @@ function item_post(App $a) { $match = null; if (!$preview && Photo::setPermissionFromBody($body, $profile_uid, $original_contact_id, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny)) { - $objecttype = Activity::OBJ_IMAGE; + $objecttype = Activity\ObjectType::IMAGE; } /* @@ -503,7 +503,7 @@ function item_post(App $a) { if ((preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", $body, $match, PREG_SET_ORDER) || isset($data["type"])) && ($posttype != Item::PT_PERSONAL_NOTE)) { $posttype = Item::PT_PAGE; - $objecttype = Activity::OBJ_BOOKMARK; + $objecttype = Activity\ObjectType::BOOKMARK; } /** @var BBCode\Video $bbCodeVideo */ @@ -517,15 +517,15 @@ function item_post(App $a) { // Setting the object type if not defined before if (!$objecttype) { - $objecttype = Activity::OBJ_NOTE; // Default value + $objecttype = Activity\ObjectType::NOTE; // Default value $objectdata = BBCode::getAttachedData($body); if ($objectdata["type"] == "link") { - $objecttype = Activity::OBJ_BOOKMARK; + $objecttype = Activity\ObjectType::BOOKMARK; } elseif ($objectdata["type"] == "video") { - $objecttype = Activity::OBJ_VIDEO; + $objecttype = Activity\ObjectType::VIDEO; } elseif ($objectdata["type"] == "photo") { - $objecttype = Activity::OBJ_IMAGE; + $objecttype = Activity\ObjectType::IMAGE; } } diff --git a/mod/photos.php b/mod/photos.php index c1195284cc..037da64b10 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -569,22 +569,22 @@ function photos_post(App $a) $arr['visible'] = 1; $arr['verb'] = Activity::TAG; $arr['gravity'] = GRAVITY_PARENT; - $arr['object-type'] = Activity::OBJ_PERSON; - $arr['target-type'] = Activity::OBJ_IMAGE; + $arr['object-type'] = Activity\ObjectType::PERSON; + $arr['target-type'] = Activity\ObjectType::IMAGE; $arr['tag'] = $tagged[4]; $arr['inform'] = $tagged[2]; $arr['origin'] = 1; $arr['body'] = L10n::t('%1$s was tagged in %2$s by %3$s', '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]', '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . ']' . L10n::t('a photo') . '[/url]', '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]') ; $arr['body'] .= "\n\n" . '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . ']' . '[img]' . System::baseUrl() . "/photo/" . $photo['resource-id'] . '-' . $best . '.' . $ext . '[/img][/url]' . "\n" ; - $arr['object'] = '' . Activity::OBJ_PERSON . '' . $tagged[0] . '' . $tagged[1] . '/' . $tagged[0] . ''; + $arr['object'] = '' . Activity\ObjectType::PERSON . '' . $tagged[0] . '' . $tagged[1] . '/' . $tagged[0] . ''; $arr['object'] .= '' . XML::escape('' . "\n"); if ($tagged[3]) { $arr['object'] .= XML::escape('' . "\n"); } $arr['object'] .= '' . "\n"; - $arr['target'] = '' . Activity::OBJ_IMAGE . '' . $photo['desc'] . '' + $arr['target'] = '' . Activity\ObjectType::IMAGE . '' . $photo['desc'] . '' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . ''; $arr['target'] .= '' . XML::escape('' . "\n" . '') . ''; diff --git a/mod/poke.php b/mod/poke.php index d667d1448f..69fd42c72c 100644 --- a/mod/poke.php +++ b/mod/poke.php @@ -118,12 +118,12 @@ function poke_init(App $a) $arr['visible'] = 1; $arr['verb'] = $activity; $arr['private'] = $private; - $arr['object-type'] = Activity::OBJ_PERSON; + $arr['object-type'] = Activity\ObjectType::PERSON; $arr['origin'] = 1; $arr['body'] = '[url=' . $poster['url'] . ']' . $poster['name'] . '[/url]' . ' ' . L10n::t($verbs[$verb][0]) . ' ' . '[url=' . $target['url'] . ']' . $target['name'] . '[/url]'; - $arr['object'] = '' . Activity::OBJ_PERSON . '' . $target['name'] . '' . $target['url'] . ''; + $arr['object'] = '' . Activity\ObjectType::PERSON . '' . $target['name'] . '' . $target['url'] . ''; $arr['object'] .= '' . XML::escape('' . "\n"); $arr['object'] .= XML::escape('' . "\n"); diff --git a/mod/subthread.php b/mod/subthread.php index 58bf265341..aa65b86218 100644 --- a/mod/subthread.php +++ b/mod/subthread.php @@ -2,6 +2,7 @@ /** * @file mod/subthread.php */ + use Friendica\App; use Friendica\Core\Hook; use Friendica\Core\L10n; @@ -88,7 +89,7 @@ function subthread_content(App $a) { $uri = Item::newURI($owner_uid); $post_type = (($item['resource-id']) ? L10n::t('photo') : L10n::t('status')); - $objtype = (($item['resource-id']) ? Activity::OBJ_IMAGE : Activity::OBJ_NOTE ); + $objtype = (($item['resource-id']) ? Activity\ObjectType::IMAGE : Activity\ObjectType::NOTE ); $link = XML::escape('' . "\n"); $body = $item['body']; diff --git a/mod/tagger.php b/mod/tagger.php index 22359c64e2..7532adb3fb 100644 --- a/mod/tagger.php +++ b/mod/tagger.php @@ -2,12 +2,13 @@ /** * @file mod/tagger.php */ + use Friendica\App; use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Logger; -use Friendica\Core\System; use Friendica\Core\Session; +use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\Model\Item; @@ -69,7 +70,7 @@ function tagger_content(App $a) { $uri = Item::newURI($owner_uid); $xterm = XML::escape($term); $post_type = (($item['resource-id']) ? L10n::t('photo') : L10n::t('status')); - $targettype = (($item['resource-id']) ? Activity::OBJ_IMAGE : Activity::OBJ_NOTE ); + $targettype = (($item['resource-id']) ? Activity\ObjectType::IMAGE : Activity\ObjectType::NOTE ); $href = System::baseUrl() . '/display/' . $item['guid']; $link = XML::escape('' . "\n"); @@ -88,7 +89,7 @@ function tagger_content(App $a) { EOT; $tagid = System::baseUrl() . '/search?tag=' . $xterm; - $objtype = Activity::OBJ_TAGTERM; + $objtype = Activity\ObjectType::TAGTERM; $obj = <<< EOT diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 8187521582..11e7840b0a 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -277,7 +277,7 @@ class BBCode extends BaseObject if (preg_match_all("(\[url=(.*?)\]\s*\[img\](.*?)\[\/img\]\s*\[\/url\])ism", $body, $pictures, PREG_SET_ORDER)) { if ((count($pictures) == 1) && !$has_title) { - if (!empty($item['object-type']) && ($item['object-type'] == Activity::OBJ_IMAGE)) { + if (!empty($item['object-type']) && ($item['object-type'] == Activity\ObjectType::IMAGE)) { // Replace the preview picture with the real picture $url = str_replace('-1.', '-0.', $pictures[0][2]); $data = ['url' => $url, 'type' => 'photo']; diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 08cad6cd84..c7cfddbb84 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -828,7 +828,7 @@ class Contact extends BaseObject } elseif (in_array($protocol, [Protocol::OSTATUS, Protocol::DFRN])) { // create an unfollow slap $item = []; - $item['verb'] = Activity\ANamespace::OSTATUS . "/unfollow"; + $item['verb'] = Activity::O_UNFOLLOW; $item['follow'] = $contact["url"]; $item['body'] = ''; $item['title'] = ''; diff --git a/src/Model/Event.php b/src/Model/Event.php index ef1096c8ea..fe81a5e958 100644 --- a/src/Model/Event.php +++ b/src/Model/Event.php @@ -304,7 +304,7 @@ class Event extends BaseObject $item = Item::selectFirst(['id'], ['event-id' => $event['id'], 'uid' => $event['uid']]); if (DBA::isResult($item)) { - $object = '' . XML::escape(Activity::OBJ_EVENT) . '' . XML::escape($event['uri']) . ''; + $object = '' . XML::escape(Activity\ObjectType::EVENT) . '' . XML::escape($event['uri']) . ''; $object .= '' . XML::escape(self::getBBCode($event)) . ''; $object .= '' . "\n"; @@ -352,12 +352,12 @@ class Event extends BaseObject $item_arr['private'] = $private; $item_arr['visible'] = 1; $item_arr['verb'] = Activity::POST; - $item_arr['object-type'] = Activity::OBJ_EVENT; + $item_arr['object-type'] = Activity\ObjectType::EVENT; $item_arr['origin'] = $event['cid'] === 0 ? 1 : 0; $item_arr['body'] = self::getBBCode($event); $item_arr['event-id'] = $event['id']; - $item_arr['object'] = '' . XML::escape(Activity::OBJ_EVENT) . '' . XML::escape($event['uri']) . ''; + $item_arr['object'] = '' . XML::escape(Activity\ObjectType::EVENT) . '' . XML::escape($event['uri']) . ''; $item_arr['object'] .= '' . XML::escape(self::getBBCode($event)) . ''; $item_arr['object'] .= '' . "\n"; diff --git a/src/Model/Item.php b/src/Model/Item.php index 6a37a1cf86..9501c8e5d2 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -214,7 +214,7 @@ class Item extends BaseObject $row['object'] = ''; } if (array_key_exists('object-type', $row)) { - $row['object-type'] = Activity::OBJ_NOTE; + $row['object-type'] = Activity\ObjectType::NOTE; } } elseif (array_key_exists('verb', $row) && in_array($row['verb'], ['', Activity::POST, Activity::SHARE])) { // Posts don't have an object or target - but having tags or files. @@ -1157,14 +1157,14 @@ class Item extends BaseObject private static function deleteTagsFromItem($item) { - if (($item["verb"] != Activity::TAG) || ($item["object-type"] != Activity::OBJ_TAGTERM)) { + if (($item["verb"] != Activity::TAG) || ($item["object-type"] != Activity\ObjectType::TAGTERM)) { return; } $xo = XML::parseString($item["object"], false); $xt = XML::parseString($item["target"], false); - if ($xt->type != Activity::OBJ_NOTE) { + if ($xt->type != Activity\ObjectType::NOTE) { return; } @@ -3156,7 +3156,7 @@ class Item extends BaseObject return true; } - $objtype = $item['resource-id'] ? Activity::OBJ_IMAGE : Activity::OBJ_NOTE; + $objtype = $item['resource-id'] ? Activity\ObjectType::IMAGE : Activity\ObjectType::NOTE; $new_item = [ 'guid' => System::createUUID(), @@ -3436,7 +3436,7 @@ class Item extends BaseObject // In order to provide theme developers more possibilities, event items // are treated differently. - if ($item['object-type'] === Activity::OBJ_EVENT && isset($item['event-id'])) { + if ($item['object-type'] === Activity\ObjectType::EVENT && isset($item['event-id'])) { $ev = Event::getItemHTML($item); return $ev; } diff --git a/src/Object/Post.php b/src/Object/Post.php index 9f392cb82e..babf24e0d6 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -15,8 +15,8 @@ use Friendica\Core\L10n; use Friendica\Core\Logger; use Friendica\Core\PConfig; use Friendica\Core\Protocol; -use Friendica\Core\Session; use Friendica\Core\Renderer; +use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\Model\Contact; use Friendica\Model\Item; @@ -240,7 +240,7 @@ class Post extends BaseObject $isevent = false; $attend = []; - if ($item['object-type'] === Activity::OBJ_EVENT) { + if ($item['object-type'] === Activity\ObjectType::EVENT) { $response_verbs[] = 'attendyes'; $response_verbs[] = 'attendno'; $response_verbs[] = 'attendmaybe'; diff --git a/src/Protocol/Activity.php b/src/Protocol/Activity.php index b1cae7f353..83e0327525 100644 --- a/src/Protocol/Activity.php +++ b/src/Protocol/Activity.php @@ -5,50 +5,157 @@ namespace Friendica\Protocol; use Friendica\Protocol\Activity\ANamespace; /** - * Base class for the Activity constants and particular method + * Base class for the Activity Verbs */ final class Activity { - const LIKE = ANamespace::ACTIVITY_SCHEMA . 'like'; + /** + * Indicates that the actor marked the object as an item of special interest. + * + * @see http://activitystrea.ms/head/activity-schema.html#verbs + * @var string + */ + const LIKE = ANamespace::ACTIVITY_SCHEMA . 'like'; + /** + * Dislike a message ("I don't like the post") + * + * @see http://purl.org/macgirvin/dfrn/1.0/dislike + * @var string + */ + const DISLIKE = ANamespace::DFRN . '/dislike'; - const DISLIKE = ANamespace::DFRN . '/dislike'; - const ATTEND = ANamespace::ZOT . '/activity/attendyes'; - const ATTENDNO = ANamespace::ZOT . '/activity/attendno'; - const ATTENDMAYBE = ANamespace::ZOT . '/activity/attendmaybe'; - const OBJ_HEART = ANamespace::DFRN . '/heart'; + /** + * Attend an event + * + * @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_attend + * @var string + */ + const ATTEND = ANamespace::ZOT . '/activity/attendyes'; + /** + * Don't attend an event + * + * @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_attendno + * @var string + */ + const ATTENDNO = ANamespace::ZOT . '/activity/attendno'; + /** + * Attend maybe an event + * + * @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_attendmaybe + * @var string + */ + const ATTENDMAYBE = ANamespace::ZOT . '/activity/attendmaybe'; - const FRIEND = ANamespace::ACTIVITY_SCHEMA . 'make-friend'; - const REQ_FRIEND = ANamespace::ACTIVITY_SCHEMA . 'request-friend'; - const UNFRIEND = ANamespace::ACTIVITY_SCHEMA . 'remove-friend'; - const FOLLOW = ANamespace::ACTIVITY_SCHEMA . 'follow'; - const UNFOLLOW = ANamespace::ACTIVITY_SCHEMA . 'stop-following'; - const JOIN = ANamespace::ACTIVITY_SCHEMA . 'join'; - const POST = ANamespace::ACTIVITY_SCHEMA . 'post'; - const UPDATE = ANamespace::ACTIVITY_SCHEMA . 'update'; - const TAG = ANamespace::ACTIVITY_SCHEMA . 'tag'; - const FAVORITE = ANamespace::ACTIVITY_SCHEMA . 'favorite'; - const UNFAVORITE = ANamespace::ACTIVITY_SCHEMA . 'unfavorite'; - const SHARE = ANamespace::ACTIVITY_SCHEMA . 'share'; - const DELETE = ANamespace::ACTIVITY_SCHEMA . 'delete'; - const ANNOUNCE = ANamespace::ACTIVITY2 . 'Announce'; + /** + * Indicates the creation of a friendship that is reciprocated by the object. + * + * @see http://activitystrea.ms/head/activity-schema.html#verbs + * @var string + */ + const FRIEND = ANamespace::ACTIVITY_SCHEMA . 'make-friend'; + /** + * Indicates the creation of a friendship that has not yet been reciprocated by the object. + * + * @see http://activitystrea.ms/head/activity-schema.html#verbs + * @var string + */ + const REQ_FRIEND = ANamespace::ACTIVITY_SCHEMA . 'request-friend'; + /** + * Indicates that the actor has removed the object from the collection of friends. + * + * @see http://activitystrea.ms/head/activity-schema.html#verbs + * @var string + */ + const UNFRIEND = ANamespace::ACTIVITY_SCHEMA . 'remove-friend'; + /** + * Indicates that the actor began following the activity of the object. + * + * @see http://activitystrea.ms/head/activity-schema.html#verbs + * @var string + */ + const FOLLOW = ANamespace::ACTIVITY_SCHEMA . 'follow'; + /** + * Indicates that the actor has stopped following the object. + * + * @see http://activitystrea.ms/head/activity-schema.html#verbs + * @var string + */ + const UNFOLLOW = ANamespace::ACTIVITY_SCHEMA . 'stop-following'; + /** + * Indicates that the actor has become a member of the object. + * + * @see http://activitystrea.ms/head/activity-schema.html#verbs + * @var string + */ + const JOIN = ANamespace::ACTIVITY_SCHEMA . 'join'; + /** + * Implementors SHOULD use verbs such as post where the actor is adding new items to a collection or similar. + * + * @see http://activitystrea.ms/head/activity-schema.html#verbs + * @var string + */ + const POST = ANamespace::ACTIVITY_SCHEMA . 'post'; + /** + * The "update" verb indicates that the actor has modified the object. + * + * @see http://activitystrea.ms/head/activity-schema.html#verbs + * @var string + */ + const UPDATE = ANamespace::ACTIVITY_SCHEMA . 'update'; + /** + * Indicates that the actor has identified the presence of a target inside another object. + * + * @see http://activitystrea.ms/head/activity-schema.html#verbs + * @var string + */ + const TAG = ANamespace::ACTIVITY_SCHEMA . 'tag'; + /** + * Indicates that the actor marked the object as an item of special interest. + * + * @see http://activitystrea.ms/head/activity-schema.html#verbs + * @var string + */ + const FAVORITE = ANamespace::ACTIVITY_SCHEMA . 'favorite'; + /** + * Indicates that the actor has removed the object from the collection of favorited items. + * + * @see http://activitystrea.ms/head/activity-schema.html#verbs + * @var string + */ + const UNFAVORITE = ANamespace::ACTIVITY_SCHEMA . 'unfavorite'; + /** + * Indicates that the actor has called out the object to readers. + * + * @see http://activitystrea.ms/head/activity-schema.html#verbs + * @var string + */ + const SHARE = ANamespace::ACTIVITY_SCHEMA . 'share'; + /** + * Indicates that the actor has deleted the object. + * + * @see http://activitystrea.ms/head/activity-schema.html#verbs + * @var string + */ + const DELETE = ANamespace::ACTIVITY_SCHEMA . 'delete'; + /** + * Indicates that the actor is calling the target's attention the object. + * + * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-announce + * @var string + */ + const ANNOUNCE = ANamespace::ACTIVITY2 . 'Announce'; - const POKE = ANamespace::ZOT . '/activity/poke'; + /** + * Pokes an user. + * + * @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_poke + * @var string + */ + const POKE = ANamespace::ZOT . '/activity/poke'; - const OBJ_BOOKMARK = ANamespace::ACTIVITY_SCHEMA . 'bookmark'; - const OBJ_COMMENT = ANamespace::ACTIVITY_SCHEMA . 'comment'; - const OBJ_NOTE = ANamespace::ACTIVITY_SCHEMA . 'note'; - const OBJ_PERSON = ANamespace::ACTIVITY_SCHEMA . 'person'; - const OBJ_IMAGE = ANamespace::ACTIVITY_SCHEMA . 'image'; - const OBJ_PHOTO = ANamespace::ACTIVITY_SCHEMA . 'photo'; - const OBJ_VIDEO = ANamespace::ACTIVITY_SCHEMA . 'video'; - const OBJ_P_PHOTO = ANamespace::ACTIVITY_SCHEMA . 'profile-photo'; - const OBJ_ALBUM = ANamespace::ACTIVITY_SCHEMA . 'photo-album'; - const OBJ_EVENT = ANamespace::ACTIVITY_SCHEMA . 'event'; - const OBJ_GROUP = ANamespace::ACTIVITY_SCHEMA . 'group'; - const OBJ_TAGTERM = ANamespace::DFRN . '/tagterm'; - const OBJ_PROFILE = ANamespace::DFRN . '/profile'; - const OBJ_QUESTION = 'http://activityschema.org/object/question'; + const O_UNFOLLOW = ANamespace::OSTATUS . '/unfollow'; + const O_UNFAVOURITE = ANamespace::OSTATUS . '/unfavorite'; /** * likes (etc.) can apply to other things besides posts. Check if they are post children, diff --git a/src/Protocol/Activity/ANamespace.php b/src/Protocol/Activity/ANamespace.php index 9cdf970f45..55fcc83742 100644 --- a/src/Protocol/Activity/ANamespace.php +++ b/src/Protocol/Activity/ANamespace.php @@ -7,21 +7,126 @@ namespace Friendica\Protocol\Activity; */ final class ANamespace { + /** + * Zot is a WebMTA which provides a decentralised identity and communications protocol using HTTPS/JSON. + * + * @var string + * @see https://zotlabs.org/page/zotlabs/specs+zot6+home + */ const ZOT = 'http://purl.org/zot'; + /** + * Friendica is using ActivityStreams in version 1.0 for its activities and object types. + * Additional types are used for non standard activities. + * + * @var string + * @see https://github.com/friendica/friendica/wiki/ActivityStreams + */ const DFRN = 'http://purl.org/macgirvin/dfrn/1.0'; + /** + * This namespace defines an extension for expressing threaded + * discussions within the Atom Syndication Format [RFC4287] + * + * @see https://tools.ietf.org/rfc/rfc4685.txt + * @var string + */ const THREAD = 'http://purl.org/syndication/thread/1.0'; + /** + * This namespace adds mechanisms to the Atom Syndication Format + * that publishers of Atom Feed and Entry documents can use to + * explicitly identify Atom entries that have been removed. + * + * @see https://tools.ietf.org/html/rfc6721 + * @var string + */ const TOMB = 'http://purl.org/atompub/tombstones/1.0'; + /** + * This specification details a model for representing potential and completed activities + * using the JSON format. + * + * @see https://www.w3.org/ns/activitystreams + * @var string + */ const ACTIVITY2 = 'https://www.w3.org/ns/activitystreams#'; + /** + * Atom Activities 1.0 + * + * This namespace presents an XML format that allows activities on social objects + * to be expressed within the Atom Syndication Format. + * + * @see http://activitystrea.ms/spec/1.0 + * @var string + */ const ACTIVITY = 'http://activitystrea.ms/spec/1.0/'; + /** + * This namespace presents a base set of Object types and Verbs for use with Activity Streams. + * + * @see http://activitystrea.ms/head/activity-schema.html + * @var string + */ const ACTIVITY_SCHEMA = 'http://activitystrea.ms/schema/1.0/'; + /** + * Atom Media Extensions + * + * @var string + */ const MEDIA = 'http://purl.org/syndication/atommedia'; + /** + * The Salmon Protocol is an open, simple, standards-based solution that lets + * aggregators and sources unify the conversations. + * + * @see http://www.salmon-protocol.org/salmon-protocol-summary + * @var string + */ const SALMON_ME = 'http://salmon-protocol.org/ns/magic-env'; + /** + * OStatus is a minimal specification for distributed status updates or microblogging. + * + * @see https://ostatus.github.io/spec/OStatus%201.0%20Draft%202.html + * @var string + */ const OSTATUSSUB = 'http://ostatus.org/schema/1.0/subscribe'; + /** + * GeoRSS was designed as a lightweight, community driven way to extend existing feeds with geographic information. + * + * @see http://www.georss.org/ + * @var string + */ const GEORSS = 'http://www.georss.org/georss'; + /** + * The Portable Contacts specification is designed to make it easier for developers + * to give their users a secure way to access the address books and friends lists + * they have built up all over the web. + * + * @see http://portablecontacts.net/draft-spec/ + * @var string + */ const POCO = 'http://portablecontacts.net/spec/1.0'; + /** + * @var string + */ const FEED = 'http://schemas.google.com/g/2010#updates-from'; + /** + * OStatus is a minimal specification for distributed status updates or microblogging. + * + * @see https://ostatus.github.io/spec/OStatus%201.0%20Draft%202.html + * @var string + */ const OSTATUS = 'http://ostatus.org/schema/1.0'; + /** + * @var string + */ const STATUSNET = 'http://status.net/schema/api/1/'; + /** + * This namespace describes the Atom Activity Streams in RDF Vocabulary (AAIR), + * defined as a dictionary of named properties and classes using W3C's RDF technology, + * and specifically a mapping of the Atom Activity Streams work to RDF. + * + * @see http://xmlns.notu.be/aair/#RFC4287 + * @var string + */ const ATOM1 = 'http://www.w3.org/2005/Atom'; + /** + * @var string + */ const MASTODON = 'http://mastodon.social/schema/1.0'; } diff --git a/src/Protocol/Activity/ObjectType.php b/src/Protocol/Activity/ObjectType.php new file mode 100644 index 0000000000..71c7a21576 --- /dev/null +++ b/src/Protocol/Activity/ObjectType.php @@ -0,0 +1,103 @@ + $activity['reply-to-id']])) { @@ -255,7 +255,7 @@ class Processor $item['verb'] = $verb; $item['thr-parent'] = $activity['object_id']; $item['gravity'] = GRAVITY_ACTIVITY; - $item['object-type'] = Activity::OBJ_NOTE; + $item['object-type'] = Activity\ObjectType::NOTE; $item['diaspora_signed_text'] = $activity['diaspora:like'] ?? ''; diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 1e841f3047..6bf3e6e4fa 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -1078,9 +1078,9 @@ class DFRN if ($item['object-type'] != "") { XML::addElement($doc, $entry, "activity:object-type", $item['object-type']); } elseif ($item['id'] == $item['parent']) { - XML::addElement($doc, $entry, "activity:object-type", Activity::OBJ_NOTE); + XML::addElement($doc, $entry, "activity:object-type", Activity\ObjectType::NOTE); } else { - XML::addElement($doc, $entry, "activity:object-type", Activity::OBJ_COMMENT); + XML::addElement($doc, $entry, "activity:object-type", Activity\ObjectType::COMMENT); } $actobj = self::createActivity($doc, "activity:object", $item['object']); @@ -1123,7 +1123,7 @@ class DFRN "link", "", ["rel" => "mentioned", - "ostatus:object-type" => Activity::OBJ_GROUP, + "ostatus:object-type" => Activity\ObjectType::GROUP, "href" => $mention] ); } else { @@ -1133,7 +1133,7 @@ class DFRN "link", "", ["rel" => "mentioned", - "ostatus:object-type" => Activity::OBJ_PERSON, + "ostatus:object-type" => Activity\ObjectType::PERSON, "href" => $mention] ); } @@ -2116,7 +2116,7 @@ class DFRN } $xo = XML::parseString($item["object"], false); - if (($xo->type == Activity::OBJ_PERSON) && ($xo->id)) { + if (($xo->type == Activity\ObjectType::PERSON) && ($xo->id)) { // somebody was poked/prodded. Was it me? $Blink = ''; foreach ($xo->link as $l) { @@ -2237,11 +2237,11 @@ class DFRN $is_like = false; } - if (($item["verb"] == Activity::TAG) && ($item["object-type"] == Activity::OBJ_TAGTERM)) { + if (($item["verb"] == Activity::TAG) && ($item["object-type"] == Activity\ObjectType::TAGTERM)) { $xo = XML::parseString($item["object"], false); $xt = XML::parseString($item["target"], false); - if ($xt->type == Activity::OBJ_NOTE) { + if ($xt->type == Activity\ObjectType::NOTE) { $item_tag = Item::selectFirst(['id', 'tag'], ['uri' => $xt->id, 'uid' => $importer["importer_uid"]]); if (!DBA::isResult($item_tag)) { @@ -2516,7 +2516,7 @@ class DFRN // Now assign the rest of the values that depend on the type of the message if (in_array($entrytype, [DFRN::REPLY, DFRN::REPLY_RC])) { if (!isset($item["object-type"])) { - $item["object-type"] = Activity::OBJ_COMMENT; + $item["object-type"] = Activity\ObjectType::COMMENT; } if ($item["contact-id"] != $owner["contact-id"]) { @@ -2540,11 +2540,11 @@ class DFRN $item["wall"] = 1; } elseif ($entrytype == DFRN::TOP_LEVEL) { if (!isset($item["object-type"])) { - $item["object-type"] = Activity::OBJ_NOTE; + $item["object-type"] = Activity\ObjectType::NOTE; } // Is it an event? - if (($item["object-type"] == Activity::OBJ_EVENT) && !$owner_unknown) { + if (($item["object-type"] == Activity\ObjectType::EVENT) && !$owner_unknown) { Logger::log("Item ".$item["uri"]." seems to contain an event.", Logger::DEBUG); $ev = Event::fromBBCode($item["body"]); if ((!empty($ev['desc']) || !empty($ev['summary'])) && !empty($ev['start'])) { diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 0bc3ed39e0..709dfa02fd 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -1855,7 +1855,7 @@ class Diaspora $datarray["parent-uri"] = $parent_item["uri"]; } - $datarray["object-type"] = Activity::OBJ_COMMENT; + $datarray["object-type"] = Activity\ObjectType::COMMENT; $datarray["protocol"] = Conversation::PARCEL_DIASPORA; $datarray["source"] = $xml; @@ -2086,7 +2086,7 @@ class Diaspora $datarray["gravity"] = GRAVITY_ACTIVITY; $datarray["parent-uri"] = $parent_item["uri"]; - $datarray["object-type"] = Activity::OBJ_NOTE; + $datarray["object-type"] = Activity\ObjectType::NOTE; $datarray["body"] = $verb; @@ -2687,7 +2687,7 @@ class Diaspora $datarray['verb'] = $datarray['body'] = Activity::ANNOUNCE; $datarray['gravity'] = GRAVITY_ACTIVITY; - $datarray['object-type'] = Activity::OBJ_NOTE; + $datarray['object-type'] = Activity\ObjectType::NOTE; $datarray['protocol'] = $item['protocol']; @@ -2963,9 +2963,9 @@ class Diaspora XML::unescape($photo->remote_photo_name)."[/img]\n".$body; } - $datarray["object-type"] = Activity::OBJ_IMAGE; + $datarray["object-type"] = Activity\ObjectType::IMAGE; } else { - $datarray["object-type"] = Activity::OBJ_NOTE; + $datarray["object-type"] = Activity\ObjectType::NOTE; // Add OEmbed and other information to the body if (!self::isRedmatrix($contact["url"])) { diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index f13716e4b7..816820bc4a 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -200,7 +200,7 @@ class Feed { $header["gravity"] = GRAVITY_PARENT; $header["private"] = 2; $header["verb"] = Activity::POST; - $header["object-type"] = Activity::OBJ_NOTE; + $header["object-type"] = Activity\ObjectType::NOTE; $header["contact-id"] = $contact["id"]; @@ -421,7 +421,7 @@ class Feed { $item["title"] = ""; $item["body"] = $item["body"].add_page_info($item["plink"], false, $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]); $item["tag"] = add_page_keywords($item["plink"], $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]); - $item["object-type"] = Activity::OBJ_BOOKMARK; + $item["object-type"] = Activity\ObjectType::BOOKMARK; unset($item["attach"]); } else { if (!empty($summary)) { diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 391353274e..d0f7d7edf2 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -434,7 +434,7 @@ class OStatus continue; } - if (in_array($item["verb"], [ANamespace::OSTATUS . "/unfavorite", Activity::UNFAVORITE])) { + if (in_array($item["verb"], [Activity::O_UNFAVOURITE, Activity::UNFAVORITE])) { // Ignore "Unfavorite" message Logger::log("Ignore unfavorite message ".print_r($item, true), Logger::DEBUG); continue; @@ -465,7 +465,7 @@ class OStatus continue; } - if ($item["verb"] == ANamespace::OSTATUS . "/unfollow") { + if ($item["verb"] == Activity::O_UNFOLLOW) { $dummy = null; Contact::removeFollower($importer, $contact, $item, $dummy); continue; @@ -478,7 +478,7 @@ class OStatus $item["verb"] = Activity::LIKE; $item["parent-uri"] = $orig_uri; $item["gravity"] = GRAVITY_ACTIVITY; - $item["object-type"] = Activity::OBJ_NOTE; + $item["object-type"] = Activity\ObjectType::NOTE; } // http://activitystrea.ms/schema/1.0/rsvp-yes @@ -593,10 +593,10 @@ class OStatus { $item["body"] = HTML::toBBCode(XML::getFirstNodeValue($xpath, 'atom:content/text()', $entry)); $item["object-type"] = XML::getFirstNodeValue($xpath, 'activity:object-type/text()', $entry); - if (($item["object-type"] == Activity::OBJ_BOOKMARK) || ($item["object-type"] == Activity::OBJ_EVENT)) { + if (($item["object-type"] == Activity\ObjectType::BOOKMARK) || ($item["object-type"] == Activity\ObjectType::EVENT)) { $item["title"] = XML::getFirstNodeValue($xpath, 'atom:title/text()', $entry); $item["body"] = XML::getFirstNodeValue($xpath, 'atom:summary/text()', $entry); - } elseif ($item["object-type"] == Activity::OBJ_QUESTION) { + } elseif ($item["object-type"] == Activity\ObjectType::QUESTION) { $item["title"] = XML::getFirstNodeValue($xpath, 'atom:title/text()', $entry); } @@ -1106,8 +1106,8 @@ class OStatus switch ($attribute['rel']) { case "alternate": $item["plink"] = $attribute['href']; - if (($item["object-type"] == Activity::OBJ_QUESTION) - || ($item["object-type"] == Activity::OBJ_EVENT) + if (($item["object-type"] == Activity\ObjectType::QUESTION) + || ($item["object-type"] == Activity\ObjectType::EVENT) ) { $item["body"] .= add_page_info($attribute['href']); } @@ -1136,7 +1136,7 @@ class OStatus } break; case "related": - if ($item["object-type"] != Activity::OBJ_BOOKMARK) { + if ($item["object-type"] != Activity\ObjectType::BOOKMARK) { if (!isset($item["parent-uri"])) { $item["parent-uri"] = $attribute['href']; } @@ -1462,9 +1462,9 @@ class OStatus $author = $doc->createElement("author"); XML::addElement($doc, $author, "id", $owner["url"]); if ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) { - XML::addElement($doc, $author, "activity:object-type", Activity::OBJ_GROUP); + XML::addElement($doc, $author, "activity:object-type", Activity\ObjectType::GROUP); } else { - XML::addElement($doc, $author, "activity:object-type", Activity::OBJ_PERSON); + XML::addElement($doc, $author, "activity:object-type", Activity\ObjectType::PERSON); } XML::addElement($doc, $author, "uri", $owner["url"]); XML::addElement($doc, $author, "name", $owner["nick"]); @@ -1557,11 +1557,11 @@ class OStatus */ private static function constructObjecttype(array $item) { - if (!empty($item['object-type']) && in_array($item['object-type'], [Activity::OBJ_NOTE, Activity::OBJ_COMMENT])) { + if (!empty($item['object-type']) && in_array($item['object-type'], [Activity\ObjectType::NOTE, Activity\ObjectType::COMMENT])) { return $item['object-type']; } - return Activity::OBJ_NOTE; + return Activity\ObjectType::NOTE; } /** @@ -1592,7 +1592,7 @@ class OStatus if ($item["verb"] == Activity::LIKE) { return self::likeEntry($doc, $item, $owner, $toplevel); - } elseif (in_array($item["verb"], [Activity::FOLLOW, ANamespace::OSTATUS . "/unfollow"])) { + } elseif (in_array($item["verb"], [Activity::FOLLOW, Activity::O_UNFOLLOW])) { return self::followEntry($doc, $item, $owner, $toplevel); } else { return self::noteEntry($doc, $item, $owner, $toplevel, $feed_mode); @@ -1791,7 +1791,7 @@ class OStatus private static function addPersonObject(DOMDocument $doc, array $owner, array $contact) { $object = $doc->createElement("activity:object"); - XML::addElement($doc, $object, "activity:object-type", Activity::OBJ_PERSON); + XML::addElement($doc, $object, "activity:object-type", Activity\ObjectType::PERSON); if ($contact['network'] == Protocol::PHANTOM) { XML::addElement($doc, $object, "id", $contact['url']); @@ -1919,7 +1919,7 @@ class OStatus $entry = self::entryHeader($doc, $owner, $item, $toplevel); - XML::addElement($doc, $entry, "activity:object-type", Activity::OBJ_NOTE); + XML::addElement($doc, $entry, "activity:object-type", Activity\ObjectType::NOTE); self::entryContent($doc, $entry, $item, $owner, $title, '', true, $feed_mode); @@ -2112,14 +2112,14 @@ class OStatus XML::addElement($doc, $entry, "link", "", [ "rel" => "mentioned", - "ostatus:object-type" => Activity::OBJ_GROUP, + "ostatus:object-type" => Activity\ObjectType::GROUP, "href" => $mention] ); } else { XML::addElement($doc, $entry, "link", "", [ "rel" => "mentioned", - "ostatus:object-type" => Activity::OBJ_PERSON, + "ostatus:object-type" => Activity\ObjectType::PERSON, "href" => $mention] ); } @@ -2232,7 +2232,7 @@ class OStatus if ($filter === 'comments') { $condition[0] .= " AND `object-type` = ? "; - $condition[] = Activity::OBJ_COMMENT; + $condition[] = Activity\ObjectType::COMMENT; } if ($owner['account-type'] != User::ACCOUNT_TYPE_COMMUNITY) { diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php index 03ae572311..3f8b98ead1 100644 --- a/src/Worker/OnePoll.php +++ b/src/Worker/OnePoll.php @@ -495,7 +495,7 @@ class OnePoll $datarray = []; $datarray['verb'] = Activity::POST; - $datarray['object-type'] = Activity::OBJ_NOTE; + $datarray['object-type'] = Activity\ObjectType::NOTE; $datarray['network'] = Protocol::MAIL; // $meta = Email::messageMeta($mbox, $msg_uid); diff --git a/tests/src/Protocol/ActivityTest.php b/tests/src/Protocol/ActivityTest.php index fe34eac1d0..ac332a7f79 100644 --- a/tests/src/Protocol/ActivityTest.php +++ b/tests/src/Protocol/ActivityTest.php @@ -16,13 +16,13 @@ class ActivityTest extends MockedTest 'assert' => true, ], 'simple' => [ - 'haystack' => Activity::OBJ_TAGTERM, - 'needle' => Activity::OBJ_TAGTERM, + 'haystack' => Activity\ObjectType::TAGTERM, + 'needle' => Activity\ObjectType::TAGTERM, 'assert' => true, ], 'withNamespace' => [ 'haystack' => 'tagterm', - 'needle' => Activity\ANamespace::ACTIVITY_SCHEMA . Activity::OBJ_TAGTERM, + 'needle' => Activity\ANamespace::ACTIVITY_SCHEMA . Activity\ObjectType::TAGTERM, 'assert' => true, ], 'invalidSimple' => [ @@ -32,12 +32,12 @@ class ActivityTest extends MockedTest ], 'invalidWithOutNamespace' => [ 'haystack' => 'tagterm', - 'needle' => Activity::OBJ_TAGTERM, + 'needle' => Activity\ObjectType::TAGTERM, 'assert' => false, ], 'withSubPath' => [ 'haystack' => 'tagterm', - 'needle' => Activity\ANamespace::ACTIVITY_SCHEMA . '/bla/' . Activity::OBJ_TAGTERM, + 'needle' => Activity\ANamespace::ACTIVITY_SCHEMA . '/bla/' . Activity\ObjectType::TAGTERM, 'assert' => true, ], ]; @@ -60,6 +60,6 @@ class ActivityTest extends MockedTest $activity = new Activity(); $this->assertTrue($activity->isHidden(Activity::LIKE)); - $this->assertFalse($activity->isHidden(Activity::OBJ_BOOKMARK)); + $this->assertFalse($activity->isHidden(Activity\ObjectType::BOOKMARK)); } } -- 2.39.5