PluginProbe
ActivityPub / 0.14.1
ActivityPub v0.14.1
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 / model / class-activity.php

class-activity.php in ActivityPub 0.14.1, at includes/model/class-activity.php

119 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Activitypub\Model;
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 = \gmdate( '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 if ( isset( $object['published'] ) ) {
51 $this->published = $object['published'];
52 }
53
54 if ( isset( $object['attributedTo'] ) ) {
55 $this->actor = $object['attributedTo'];
56 }
57
58 $type = \strtolower( $this->type );
59
60 if ( isset( $object['id'] ) ) {
61 $this->id = add_query_arg( 'activity', $type, $object['id'] );
62 }
63 }
64
65 public function from_comment( $object ) {
66
67 }
68
69 public function to_comment() {
70
71 }
72
73 public function from_remote_array( $array ) {
74
75 }
76
77 public function to_array() {
78 $array = array_filter( \get_object_vars( $this ) );
79
80 if ( $this->context ) {
81 $array = array( '@context' => $this->context ) + $array;
82 }
83
84 unset( $array['context'] );
85
86 return $array;
87 }
88
89 /**
90 * Convert to JSON
91 *
92 * @return void
93 */
94 public function to_json() {
95 return \wp_json_encode( $this->to_array(), \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_QUOT );
96 }
97
98 public function to_simple_array() {
99 $activity = array(
100 '@context' => $this->context,
101 'type' => $this->type,
102 'actor' => $this->actor,
103 'object' => $this->object,
104 'to' => $this->to,
105 'cc' => $this->cc,
106 );
107
108 if ( $this->id ) {
109 $activity['id'] = $this->id;
110 }
111
112 return $activity;
113 }
114
115 public function to_simple_json() {
116 return \wp_json_encode( $this->to_simple_array(), \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_QUOT );
117 }
118 }
119