]> git.mxchange.org Git - friendica.git/blob - src/Protocol/Activity.php
Add docs
[friendica.git] / src / Protocol / Activity.php
1 <?php
2
3 namespace Friendica\Protocol;
4
5 use Friendica\Protocol\Activity\ANamespace;
6
7 /**
8  * Base class for the Activity Verbs
9  */
10 final class Activity
11 {
12         /**
13          * Indicates that the actor marked the object as an item of special interest.
14          *
15          * @see http://activitystrea.ms/head/activity-schema.html#verbs
16          * @var string
17          */
18         const LIKE = ANamespace::ACTIVITY_SCHEMA . 'like';
19         /**
20          * Dislike a message ("I don't like the post")
21          *
22          * @see http://purl.org/macgirvin/dfrn/1.0/dislike
23          * @var string
24          */
25         const DISLIKE = ANamespace::DFRN . '/dislike';
26
27         /**
28          * Attend an event
29          *
30          * @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_attend
31          * @var string
32          */
33         const ATTEND      = ANamespace::ZOT . '/activity/attendyes';
34         /**
35          * Don't attend an event
36          *
37          * @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_attendno
38          * @var string
39          */
40         const ATTENDNO    = ANamespace::ZOT . '/activity/attendno';
41         /**
42          * Attend maybe an event
43          *
44          * @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_attendmaybe
45          * @var string
46          */
47         const ATTENDMAYBE = ANamespace::ZOT . '/activity/attendmaybe';
48
49         /**
50          * Indicates the creation of a friendship that is reciprocated by the object.
51          *
52          * @see http://activitystrea.ms/head/activity-schema.html#verbs
53          * @var string
54          */
55         const FRIEND      = ANamespace::ACTIVITY_SCHEMA . 'make-friend';
56         /**
57          * Indicates the creation of a friendship that has not yet been reciprocated by the object.
58          *
59          * @see http://activitystrea.ms/head/activity-schema.html#verbs
60          * @var string
61          */
62         const REQ_FRIEND = ANamespace::ACTIVITY_SCHEMA . 'request-friend';
63         /**
64          * Indicates that the actor has removed the object from the collection of friends.
65          *
66          * @see http://activitystrea.ms/head/activity-schema.html#verbs
67          * @var string
68          */
69         const UNFRIEND   = ANamespace::ACTIVITY_SCHEMA . 'remove-friend';
70         /**
71          * Indicates that the actor began following the activity of the object.
72          *
73          * @see http://activitystrea.ms/head/activity-schema.html#verbs
74          * @var string
75          */
76         const FOLLOW     = ANamespace::ACTIVITY_SCHEMA . 'follow';
77         /**
78          * Indicates that the actor has stopped following the object.
79          *
80          * @see http://activitystrea.ms/head/activity-schema.html#verbs
81          * @var string
82          */
83         const UNFOLLOW   = ANamespace::ACTIVITY_SCHEMA . 'stop-following';
84         /**
85          * Indicates that the actor has become a member of the object.
86          *
87          * @see http://activitystrea.ms/head/activity-schema.html#verbs
88          * @var string
89          */
90         const JOIN       = ANamespace::ACTIVITY_SCHEMA . 'join';
91         /**
92          * Implementors SHOULD use verbs such as post where the actor is adding new items to a collection or similar.
93          *
94          * @see http://activitystrea.ms/head/activity-schema.html#verbs
95          * @var string
96          */
97         const POST       = ANamespace::ACTIVITY_SCHEMA . 'post';
98         /**
99          * The "update" verb indicates that the actor has modified the object.
100          *
101          * @see http://activitystrea.ms/head/activity-schema.html#verbs
102          * @var string
103          */
104         const UPDATE     = ANamespace::ACTIVITY_SCHEMA . 'update';
105         /**
106          * Indicates that the actor has identified the presence of a target inside another object.
107          *
108          * @see http://activitystrea.ms/head/activity-schema.html#verbs
109          * @var string
110          */
111         const TAG        = ANamespace::ACTIVITY_SCHEMA . 'tag';
112         /**
113          * Indicates that the actor marked the object as an item of special interest.
114          *
115          * @see http://activitystrea.ms/head/activity-schema.html#verbs
116          * @var string
117          */
118         const FAVORITE   = ANamespace::ACTIVITY_SCHEMA . 'favorite';
119         /**
120          * Indicates that the actor has removed the object from the collection of favorited items.
121          *
122          * @see http://activitystrea.ms/head/activity-schema.html#verbs
123          * @var string
124          */
125         const UNFAVORITE = ANamespace::ACTIVITY_SCHEMA . 'unfavorite';
126         /**
127          * Indicates that the actor has called out the object to readers.
128          *
129          * @see http://activitystrea.ms/head/activity-schema.html#verbs
130          * @var string
131          */
132         const SHARE      = ANamespace::ACTIVITY_SCHEMA . 'share';
133         /**
134          * Indicates that the actor has deleted the object.
135          *
136          * @see http://activitystrea.ms/head/activity-schema.html#verbs
137          * @var string
138          */
139         const DELETE     = ANamespace::ACTIVITY_SCHEMA . 'delete';
140         /**
141          * Indicates that the actor is calling the target's attention the object.
142          *
143          * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-announce
144          * @var string
145          */
146         const ANNOUNCE   = ANamespace::ACTIVITY2 . 'Announce';
147
148         /**
149          * Pokes an user.
150          *
151          * @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_poke
152          * @var string
153          */
154         const POKE       = ANamespace::ZOT . '/activity/poke';
155
156
157         const O_UNFOLLOW    = ANamespace::OSTATUS . '/unfollow';
158         const O_UNFAVOURITE = ANamespace::OSTATUS . '/unfavorite';
159
160         /**
161          * likes (etc.) can apply to other things besides posts. Check if they are post children,
162          * in which case we handle them specially
163          *
164          * Hidden activities, which doesn't need to be shown
165          */
166         const HIDDEN_ACTIVITIES = [
167                 Activity::LIKE, Activity::DISLIKE,
168                 Activity::ATTEND, Activity::ATTENDNO, Activity::ATTENDMAYBE,
169                 Activity::FOLLOW,
170                 Activity::ANNOUNCE,
171         ];
172
173         /**
174          * Checks if the given activity is a hidden activity
175          *
176          * @param string $activity The current activity
177          *
178          * @return bool True, if the activity is hidden
179          */
180         public function isHidden(string $activity)
181         {
182                 foreach (self::HIDDEN_ACTIVITIES as $hiddenActivity) {
183                         if ($this->match($activity, $hiddenActivity)) {
184                                 return true;
185                         }
186                 }
187
188                 return false;
189         }
190
191         /**
192          * Compare activity uri. Knows about activity namespace.
193          *
194          * @param string $haystack
195          * @param string $needle
196          *
197          * @return boolean
198          */
199         public function match(string $haystack, string $needle)
200         {
201                 return (($haystack === $needle) ||
202                         ((basename($needle) === $haystack) &&
203                          strstr($needle, ANamespace::ACTIVITY_SCHEMA)));
204         }
205 }