PluginProbe
ActivityPub / 0.7.3
ActivityPub v0.7.3
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
activitypub / includes / class-activity.php

class-activity.php in ActivityPub 0.7.3, at includes/class-activity.php

96 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Activitypub;
3
4 /**
5 * ActivityPub Post Class
6 *
7 * @author Matthias Pfefferle
8 *
9 * @see https://www.w3.org/TR/activitypub/
10 */
11 class Activity {
12 private $context = array( 'https://www.w3.org/ns/activitystreams' );
13 private $published = '';
14 private $id = '';
15 private $type = 'Create';
16 private $actor = '';
17 private $to = array( 'https://www.w3.org/ns/activitystreams#Public' );
18 private $cc = array( 'https://www.w3.org/ns/activitystreams#Public' );
19 private $object = null;
20
21 const TYPE_SIMPLE = 'simple';
22 const TYPE_FULL = 'full';
23 const TYPE_NONE = 'none';
24
25 public function __construct( $type = 'Create', $context = self::TYPE_SIMPLE ) {
26 if ( 'none' === $context ) {
27 $this->context = null;
28 } elseif ( 'full' === $context ) {
29 $this->context = \Activitypub\get_context();
30 }
31
32 $this->type = ucfirst( $type );
33 $this->published = date( 'Y-m-d\TH:i:s\Z', strtotime( 'now' ) );
34 }
35
36 public function __call( $method, $params ) {
37 $var = strtolower( substr( $method, 4 ) );
38
39 if ( strncasecmp( $method, 'get', 3 ) === 0 ) {
40 return $this->$var;
41 }
42
43 if ( strncasecmp( $method, 'set', 3 ) === 0 ) {
44 $this->$var = $params[0];
45 }
46 }
47
48 public function from_post( $object ) {
49 $this->object = $object;
50 $this->published = $object['published'];
51 $this->actor = $object['attributedTo'];
52 $this->id = $object['id'];
53 }
54
55 public function from_comment( $object ) {
56
57 }
58
59 public function to_array() {
60 $array = get_object_vars( $this );
61
62 if ( $this->context ) {
63 $array = array( '@context' => $this->context ) + $array;
64 }
65
66 unset( $array['context'] );
67
68 return $array;
69 }
70
71 public function to_json() {
72 return wp_json_encode( $this->to_array(), JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_QUOT );
73 }
74
75 public function to_simple_array() {
76 $activity = array(
77 '@context' => $this->context,
78 'type' => $this->type,
79 'actor' => $this->actor,
80 'object' => $this->object,
81 'to' => $this->to,
82 'cc' => $this->cc,
83 );
84
85 if ( $this->id ) {
86 $activity['id'] = $this->id;
87 }
88
89 return $activity;
90 }
91
92 public function to_simple_json() {
93 return wp_json_encode( $this->to_simple_array(), JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_QUOT );
94 }
95 }
96