2019-10-23 00:05:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Protocol;
|
|
|
|
|
2019-10-23 22:25:43 +00:00
|
|
|
use Friendica\Protocol\Activity\Namespaces;
|
|
|
|
|
2019-10-23 00:05:11 +00:00
|
|
|
/**
|
2019-10-23 22:25:43 +00:00
|
|
|
* Base class for the Activity constants and match method
|
2019-10-23 00:05:11 +00:00
|
|
|
*/
|
|
|
|
final class Activity
|
|
|
|
{
|
2019-10-23 22:25:43 +00:00
|
|
|
const LIKE = Namespaces::ACTIVITY_SCHEMA . 'like';
|
|
|
|
|
|
|
|
const DISLIKE = Namespaces::DFRN . '/dislike';
|
|
|
|
const ATTEND = Namespaces::ZOT . '/activity/attendyes';
|
|
|
|
const ATTENDNO = Namespaces::ZOT . '/activity/attendno';
|
|
|
|
const ATTENDMAYBE = Namespaces::ZOT . '/activity/attendmaybe';
|
|
|
|
const OBJ_HEART = Namespaces::DFRN . '/heart';
|
|
|
|
|
|
|
|
const FRIEND = Namespaces::ACTIVITY_SCHEMA . 'make-friend';
|
|
|
|
const REQ_FRIEND = Namespaces::ACTIVITY_SCHEMA . 'request-friend';
|
|
|
|
const UNFRIEND = Namespaces::ACTIVITY_SCHEMA . 'remove-friend';
|
|
|
|
const FOLLOW = Namespaces::ACTIVITY_SCHEMA . 'follow';
|
|
|
|
const UNFOLLOW = Namespaces::ACTIVITY_SCHEMA . 'stop-following';
|
|
|
|
const JOIN = Namespaces::ACTIVITY_SCHEMA . 'join';
|
|
|
|
const POST = Namespaces::ACTIVITY_SCHEMA . 'post';
|
|
|
|
const UPDATE = Namespaces::ACTIVITY_SCHEMA . 'update';
|
|
|
|
const TAG = Namespaces::ACTIVITY_SCHEMA . 'tag';
|
|
|
|
const FAVORITE = Namespaces::ACTIVITY_SCHEMA . 'favorite';
|
|
|
|
const UNFAVORITE = Namespaces::ACTIVITY_SCHEMA . 'unfavorite';
|
|
|
|
const SHARE = Namespaces::ACTIVITY_SCHEMA . 'share';
|
|
|
|
const DELETE = Namespaces::ACTIVITY_SCHEMA . 'delete';
|
|
|
|
const ANNOUNCE = Namespaces::ACTIVITY2 . 'Announce';
|
|
|
|
|
|
|
|
const POKE = Namespaces::ZOT . '/activity/poke';
|
|
|
|
|
|
|
|
const OBJ_BOOKMARK = Namespaces::ACTIVITY_SCHEMA . 'bookmark';
|
|
|
|
const OBJ_COMMENT = Namespaces::ACTIVITY_SCHEMA . 'comment';
|
|
|
|
const OBJ_NOTE = Namespaces::ACTIVITY_SCHEMA . 'note';
|
|
|
|
const OBJ_PERSON = Namespaces::ACTIVITY_SCHEMA . 'person';
|
|
|
|
const OBJ_IMAGE = Namespaces::ACTIVITY_SCHEMA . 'image';
|
|
|
|
const OBJ_PHOTO = Namespaces::ACTIVITY_SCHEMA . 'photo';
|
|
|
|
const OBJ_VIDEO = Namespaces::ACTIVITY_SCHEMA . 'video';
|
|
|
|
const OBJ_P_PHOTO = Namespaces::ACTIVITY_SCHEMA . 'profile-photo';
|
|
|
|
const OBJ_ALBUM = Namespaces::ACTIVITY_SCHEMA . 'photo-album';
|
|
|
|
const OBJ_EVENT = Namespaces::ACTIVITY_SCHEMA . 'event';
|
|
|
|
const OBJ_GROUP = Namespaces::ACTIVITY_SCHEMA . 'group';
|
|
|
|
const OBJ_TAGTERM = Namespaces::DFRN . '/tagterm';
|
|
|
|
const OBJ_PROFILE = Namespaces::DFRN . '/profile';
|
|
|
|
|
|
|
|
const OBJ_QUESTION = 'http://activityschema.org/object/question';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* likes (etc.) can apply to other things besides posts. Check if they are post children,
|
|
|
|
* in which case we handle them specially
|
|
|
|
*
|
|
|
|
* Hidden activities, which doesn't need to be shown
|
|
|
|
*/
|
|
|
|
const HIDDEN_ACTIVITIES = [
|
|
|
|
Activity::LIKE, Activity::DISLIKE,
|
|
|
|
Activity::ATTEND, Activity::ATTENDNO, Activity::ATTENDMAYBE,
|
|
|
|
Activity::FOLLOW,
|
|
|
|
Activity::ANNOUNCE,
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given activity is a hidden activity
|
|
|
|
*
|
|
|
|
* @param string $activity The current activity
|
|
|
|
*
|
|
|
|
* @return bool True, if the activity is hidden
|
|
|
|
*/
|
|
|
|
public function isHidden(string $activity)
|
|
|
|
{
|
|
|
|
foreach (self::HIDDEN_ACTIVITIES as $hiddenActivity) {
|
|
|
|
if ($this->match($activity, $hiddenActivity)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-10-23 00:05:11 +00:00
|
|
|
/**
|
|
|
|
* Compare activity uri. Knows about activity namespace.
|
|
|
|
*
|
|
|
|
* @param string $haystack
|
|
|
|
* @param string $needle
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2019-10-23 22:25:43 +00:00
|
|
|
public function match(string $haystack, string $needle)
|
|
|
|
{
|
2019-10-23 00:05:11 +00:00
|
|
|
return (($haystack === $needle) ||
|
|
|
|
((basename($needle) === $haystack) &&
|
2019-10-23 22:25:43 +00:00
|
|
|
strstr($needle, Namespaces::ACTIVITY_SCHEMA)));
|
2019-10-23 00:05:11 +00:00
|
|
|
}
|
|
|
|
}
|