]> git.mxchange.org Git - friendica.git/blob - src/Protocol/Activity.php
Merge pull request #13561 from annando/log-callstack
[friendica.git] / src / Protocol / Activity.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Protocol;
23
24 use Friendica\Protocol\ActivityNamespace;
25
26 /**
27  * Base class for the Activity Verbs
28  */
29 final class Activity
30 {
31         /**
32          * Indicates that the actor marked the object as an item of special interest.
33          *
34          * @see http://activitystrea.ms/head/activity-schema.html#verbs
35          * @var string
36          */
37         const LIKE = ActivityNamespace::ACTIVITY_SCHEMA . 'like';
38         /**
39          * Dislike a message ("I don't like the post")
40          *
41          * @see http://purl.org/macgirvin/dfrn/1.0/dislike
42          * @var string
43          */
44         const DISLIKE = ActivityNamespace::DFRN . '/dislike';
45
46         /**
47          * Attend an event
48          *
49          * @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_attend
50          * @var string
51          */
52         const ATTEND      = ActivityNamespace::ZOT . '/activity/attendyes';
53         /**
54          * Don't attend an event
55          *
56          * @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_attendno
57          * @var string
58          */
59         const ATTENDNO    = ActivityNamespace::ZOT . '/activity/attendno';
60         /**
61          * Attend maybe an event
62          *
63          * @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_attendmaybe
64          * @var string
65          */
66         const ATTENDMAYBE = ActivityNamespace::ZOT . '/activity/attendmaybe';
67
68         /**
69          * Indicates the creation of a friendship that is reciprocated by the object.
70          *
71          * @see http://activitystrea.ms/head/activity-schema.html#verbs
72          * @var string
73          */
74         const FRIEND      = ActivityNamespace::ACTIVITY_SCHEMA . 'make-friend';
75         /**
76          * Indicates the creation of a friendship that has not yet been reciprocated by the object.
77          *
78          * @see http://activitystrea.ms/head/activity-schema.html#verbs
79          * @var string
80          */
81         const REQ_FRIEND = ActivityNamespace::ACTIVITY_SCHEMA . 'request-friend';
82         /**
83          * Indicates that the actor has removed the object from the collection of friends.
84          *
85          * @see http://activitystrea.ms/head/activity-schema.html#verbs
86          * @var string
87          */
88         const UNFRIEND   = ActivityNamespace::ACTIVITY_SCHEMA . 'remove-friend';
89         /**
90          * Indicates that the actor began following the activity of the object.
91          *
92          * @see http://activitystrea.ms/head/activity-schema.html#verbs
93          * @var string
94          */
95         const FOLLOW     = ActivityNamespace::ACTIVITY_SCHEMA . 'follow';
96         /**
97          * Indicates that the actor has stopped following the object.
98          *
99          * @see http://activitystrea.ms/head/activity-schema.html#verbs
100          * @var string
101          */
102         const UNFOLLOW   = ActivityNamespace::ACTIVITY_SCHEMA . 'stop-following';
103         /**
104          * Indicates that the actor has become a member of the object.
105          *
106          * @see http://activitystrea.ms/head/activity-schema.html#verbs
107          * @var string
108          */
109         const JOIN       = ActivityNamespace::ACTIVITY_SCHEMA . 'join';
110         /**
111          * Implementors SHOULD use verbs such as post where the actor is adding new items to a collection or similar.
112          *
113          * @see http://activitystrea.ms/head/activity-schema.html#verbs
114          * @var string
115          */
116         const POST       = ActivityNamespace::ACTIVITY_SCHEMA . 'post';
117         /**
118          * The "update" verb indicates that the actor has modified the object.
119          *
120          * @see http://activitystrea.ms/head/activity-schema.html#verbs
121          * @var string
122          */
123         const UPDATE     = ActivityNamespace::ACTIVITY_SCHEMA . 'update';
124         /**
125          * Indicates that the actor has identified the presence of a target inside another object.
126          *
127          * @see http://activitystrea.ms/head/activity-schema.html#verbs
128          * @var string
129          */
130         const TAG        = ActivityNamespace::ACTIVITY_SCHEMA . 'tag';
131         /**
132          * Indicates that the actor marked the object as an item of special interest.
133          *
134          * @see http://activitystrea.ms/head/activity-schema.html#verbs
135          * @var string
136          */
137         const FAVORITE   = ActivityNamespace::ACTIVITY_SCHEMA . 'favorite';
138         /**
139          * Indicates that the actor has removed the object from the collection of favorited items.
140          *
141          * @see http://activitystrea.ms/head/activity-schema.html#verbs
142          * @var string
143          */
144         const UNFAVORITE = ActivityNamespace::ACTIVITY_SCHEMA . 'unfavorite';
145         /**
146          * Indicates that the actor has called out the object to readers.
147          *
148          * @see http://activitystrea.ms/head/activity-schema.html#verbs
149          * @var string
150          */
151         const SHARE      = ActivityNamespace::ACTIVITY_SCHEMA . 'share';
152         /**
153          * Indicates that the actor has deleted the object.
154          *
155          * @see http://activitystrea.ms/head/activity-schema.html#verbs
156          * @var string
157          */
158         const DELETE     = ActivityNamespace::ACTIVITY_SCHEMA . 'delete';
159         /**
160          * Indicates that the actor is calling the target's attention the object.
161          *
162          * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-announce
163          * @var string
164          */
165         const ANNOUNCE   = ActivityNamespace::ACTIVITY2 . 'Announce';
166         /**
167          * Indicates that the actor has read the object.
168          *
169          * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-read
170          * @var string
171          */
172         const READ       = ActivityNamespace::ACTIVITY2 . 'Read';
173         /**
174          *  Indicates that the actor has listened to the object. 
175          *
176          * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-listen
177          * @var string
178          */
179         const LISTEN     = ActivityNamespace::ACTIVITY2 . 'Listen';
180         /**
181          * Indicates that the actor has viewed the object.
182          *
183          * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-view
184          * @var string
185          */
186         const VIEW       = ActivityNamespace::ACTIVITY2 . 'View';
187
188         const O_UNFOLLOW    = ActivityNamespace::OSTATUS . '/unfollow';
189         const O_UNFAVOURITE = ActivityNamespace::OSTATUS . '/unfavorite';
190
191         /**
192          * React to a post via an emoji
193          *
194          * @var string
195          */
196         const EMOJIREACT = ActivityNamespace::LITEPUB . '/emojireact';
197
198         /**
199          * likes (etc.) can apply to other things besides posts. Check if they are post children,
200          * in which case we handle them specially
201          *
202          * Hidden activities, which doesn't need to be shown
203          */
204         const HIDDEN_ACTIVITIES = [
205                 self::LIKE, self::DISLIKE,
206                 self::ATTEND, self::ATTENDNO, self::ATTENDMAYBE,
207                 self::FOLLOW,
208                 self::ANNOUNCE,
209                 self::EMOJIREACT,
210                 self::VIEW,
211                 self::READ,
212         ];
213
214         /**
215          * Checks if the given activity is a hidden activity
216          *
217          * @param string $activity The current activity
218          *
219          * @return bool True, if the activity is hidden
220          */
221         public function isHidden(string $activity): bool
222         {
223                 foreach (self::HIDDEN_ACTIVITIES as $hiddenActivity) {
224                         if ($this->match($activity, $hiddenActivity)) {
225                                 return true;
226                         }
227                 }
228
229                 return false;
230         }
231
232         /**
233          * Compare activity uri. Knows about activity namespace.
234          *
235          * @param string $haystack
236          * @param string $needle
237          *
238          * @return boolean
239          */
240         public function match(string $haystack, string $needle): bool
241         {
242                 return (($haystack === $needle) ||
243                         ((basename($needle) === $haystack) &&
244                          strstr($needle, ActivityNamespace::ACTIVITY_SCHEMA)));
245         }
246 }