PluginProbe
ActivityPub / 0.3.2
ActivityPub v0.3.2
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-activitypub-activity.php

class-activitypub-activity.php in ActivityPub 0.3.2, at includes/class-activitypub-activity.php

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