| 1 |
<?php |
| 2 |
/** |
| 3 |
* Inspired by the PHP ActivityPub Library by @Landrok |
| 4 |
* |
| 5 |
* @link https://github.com/landrok/activitypub |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Activitypub\Activity; |
| 9 |
|
| 10 |
use Activitypub\Activity\Base_Object; |
| 11 |
|
| 12 |
/** |
| 13 |
* \Activitypub\Activity\Activity implements the common |
| 14 |
* attributes of an Activity. |
| 15 |
* |
| 16 |
* @see https://www.w3.org/TR/activitystreams-core/#activities |
| 17 |
* @see https://www.w3.org/TR/activitystreams-core/#intransitiveactivities |
| 18 |
*/ |
| 19 |
class Activity extends Base_Object { |
| 20 |
const CONTEXT = array( |
| 21 |
'https://www.w3.org/ns/activitystreams', |
| 22 |
'https://w3id.org/security/v1', |
| 23 |
array( |
| 24 |
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers', |
| 25 |
'PropertyValue' => 'schema:PropertyValue', |
| 26 |
'schema' => 'http://schema.org#', |
| 27 |
'pt' => 'https://joinpeertube.org/ns#', |
| 28 |
'toot' => 'http://joinmastodon.org/ns#', |
| 29 |
'webfinger' => 'https://webfinger.net/#', |
| 30 |
'litepub' => 'http://litepub.social/ns#', |
| 31 |
'lemmy' => 'https://join-lemmy.org/ns#', |
| 32 |
'value' => 'schema:value', |
| 33 |
'Hashtag' => 'as:Hashtag', |
| 34 |
'featured' => array( |
| 35 |
'@id' => 'toot:featured', |
| 36 |
'@type' => '@id', |
| 37 |
), |
| 38 |
'featuredTags' => array( |
| 39 |
'@id' => 'toot:featuredTags', |
| 40 |
'@type' => '@id', |
| 41 |
), |
| 42 |
'alsoKnownAs' => array( |
| 43 |
'@id' => 'as:alsoKnownAs', |
| 44 |
'@type' => '@id', |
| 45 |
), |
| 46 |
'moderators' => array( |
| 47 |
'@id' => 'lemmy:moderators', |
| 48 |
'@type' => '@id', |
| 49 |
), |
| 50 |
'postingRestrictedToMods' => 'lemmy:postingRestrictedToMods', |
| 51 |
'discoverable' => 'toot:discoverable', |
| 52 |
'indexable' => 'toot:indexable', |
| 53 |
'sensitive' => 'as:sensitive', |
| 54 |
'resource' => 'webfinger:resource', |
| 55 |
), |
| 56 |
); |
| 57 |
|
| 58 |
/** |
| 59 |
* The object's unique global identifier |
| 60 |
* |
| 61 |
* @see https://www.w3.org/TR/activitypub/#obj-id |
| 62 |
* |
| 63 |
* @var string |
| 64 |
*/ |
| 65 |
protected $id; |
| 66 |
|
| 67 |
/** |
| 68 |
* @var string |
| 69 |
*/ |
| 70 |
protected $type = 'Activity'; |
| 71 |
|
| 72 |
/** |
| 73 |
* The context within which the object exists or an activity was |
| 74 |
* performed. |
| 75 |
* The notion of "context" used is intentionally vague. |
| 76 |
* The intended function is to serve as a means of grouping objects |
| 77 |
* and activities that share a common originating context or |
| 78 |
* purpose. An example could be all activities relating to a common |
| 79 |
* project or event. |
| 80 |
* |
| 81 |
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-context |
| 82 |
* |
| 83 |
* @var string |
| 84 |
* | ObjectType |
| 85 |
* | Link |
| 86 |
* | null |
| 87 |
*/ |
| 88 |
protected $context = self::CONTEXT; |
| 89 |
|
| 90 |
/** |
| 91 |
* Describes the direct object of the activity. |
| 92 |
* For instance, in the activity "John added a movie to his |
| 93 |
* wishlist", the object of the activity is the movie added. |
| 94 |
* |
| 95 |
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-object-term |
| 96 |
* |
| 97 |
* @var string |
| 98 |
* | Base_Objectr |
| 99 |
* | Link |
| 100 |
* | null |
| 101 |
*/ |
| 102 |
protected $object; |
| 103 |
|
| 104 |
/** |
| 105 |
* Describes one or more entities that either performed or are |
| 106 |
* expected to perform the activity. |
| 107 |
* Any single activity can have multiple actors. |
| 108 |
* The actor MAY be specified using an indirect Link. |
| 109 |
* |
| 110 |
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-actor |
| 111 |
* |
| 112 |
* @var string |
| 113 |
* | \ActivityPhp\Type\Extended\AbstractActor |
| 114 |
* | array<Actor> |
| 115 |
* | array<Link> |
| 116 |
* | Link |
| 117 |
*/ |
| 118 |
protected $actor; |
| 119 |
|
| 120 |
/** |
| 121 |
* The indirect object, or target, of the activity. |
| 122 |
* The precise meaning of the target is largely dependent on the |
| 123 |
* type of action being described but will often be the object of |
| 124 |
* the English preposition "to". |
| 125 |
* For instance, in the activity "John added a movie to his |
| 126 |
* wishlist", the target of the activity is John's wishlist. |
| 127 |
* An activity can have more than one target. |
| 128 |
* |
| 129 |
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-target |
| 130 |
* |
| 131 |
* @var string |
| 132 |
* | ObjectType |
| 133 |
* | array<ObjectType> |
| 134 |
* | Link |
| 135 |
* | array<Link> |
| 136 |
*/ |
| 137 |
protected $target; |
| 138 |
|
| 139 |
/** |
| 140 |
* Describes the result of the activity. |
| 141 |
* For instance, if a particular action results in the creation of |
| 142 |
* a new resource, the result property can be used to describe |
| 143 |
* that new resource. |
| 144 |
* |
| 145 |
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-result |
| 146 |
* |
| 147 |
* @var string |
| 148 |
* | ObjectType |
| 149 |
* | Link |
| 150 |
* | null |
| 151 |
*/ |
| 152 |
protected $result; |
| 153 |
|
| 154 |
/** |
| 155 |
* An indirect object of the activity from which the |
| 156 |
* activity is directed. |
| 157 |
* The precise meaning of the origin is the object of the English |
| 158 |
* preposition "from". |
| 159 |
* For instance, in the activity "John moved an item to List B |
| 160 |
* from List A", the origin of the activity is "List A". |
| 161 |
* |
| 162 |
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-origin |
| 163 |
* |
| 164 |
* @var string |
| 165 |
* | ObjectType |
| 166 |
* | Link |
| 167 |
* | null |
| 168 |
*/ |
| 169 |
protected $origin; |
| 170 |
|
| 171 |
/** |
| 172 |
* One or more objects used (or to be used) in the completion of an |
| 173 |
* Activity. |
| 174 |
* |
| 175 |
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-instrument |
| 176 |
* |
| 177 |
* @var string |
| 178 |
* | ObjectType |
| 179 |
* | Link |
| 180 |
* | null |
| 181 |
*/ |
| 182 |
protected $instrument; |
| 183 |
|
| 184 |
/** |
| 185 |
* Set the object and copy Object properties to the Activity. |
| 186 |
* |
| 187 |
* Any to, bto, cc, bcc, and audience properties specified on the object |
| 188 |
* MUST be copied over to the new Create activity by the server. |
| 189 |
* |
| 190 |
* @see https://www.w3.org/TR/activitypub/#object-without-create |
| 191 |
* |
| 192 |
* @param string|Base_Objectr|Link|null $object |
| 193 |
* |
| 194 |
* @return void |
| 195 |
*/ |
| 196 |
public function set_object( $object ) { |
| 197 |
// convert array to object |
| 198 |
if ( is_array( $object ) ) { |
| 199 |
$object = Base_Object::init_from_array( $object ); |
| 200 |
} |
| 201 |
|
| 202 |
// set object |
| 203 |
$this->set( 'object', $object ); |
| 204 |
|
| 205 |
if ( ! is_object( $object ) ) { |
| 206 |
return; |
| 207 |
} |
| 208 |
|
| 209 |
foreach ( array( 'to', 'bto', 'cc', 'bcc', 'audience' ) as $i ) { |
| 210 |
$this->set( $i, $object->get( $i ) ); |
| 211 |
} |
| 212 |
|
| 213 |
if ( $object->get_published() && ! $this->get_published() ) { |
| 214 |
$this->set( 'published', $object->get_published() ); |
| 215 |
} |
| 216 |
|
| 217 |
if ( $object->get_updated() && ! $this->get_updated() ) { |
| 218 |
$this->set( 'updated', $object->get_updated() ); |
| 219 |
} |
| 220 |
|
| 221 |
if ( $object->get_attributed_to() && ! $this->get_actor() ) { |
| 222 |
$this->set( 'actor', $object->get_attributed_to() ); |
| 223 |
} |
| 224 |
|
| 225 |
if ( $object->get_id() && ! $this->get_id() ) { |
| 226 |
$this->set( 'id', $object->get_id() . '#activity' ); |
| 227 |
} |
| 228 |
} |
| 229 |
} |
| 230 |
|