set( 'object', $object ); $this->pre_fill_activity_from_object(); } /** * Fills the Activity with the specified activity object. */ public function pre_fill_activity_from_object() { $object = $this->get_object(); // Check if `$data` is a URL and use it to generate an ID then. if ( is_string( $object ) && filter_var( $object, FILTER_VALIDATE_URL ) && ! $this->get_id() ) { $this->set( 'id', $object . '#activity-' . strtolower( $this->get_type() ) . '-' . time() ); return; } // Check if `$data` is an object and copy some properties otherwise do nothing. if ( ! is_object( $object ) ) { return; } foreach ( array( 'to', 'bto', 'cc', 'bcc', 'audience' ) as $i ) { $value = $object->get( $i ); if ( $value && ! $this->get( $i ) ) { $this->set( $i, $value ); } } if ( $object->get_published() && ! $this->get_published() ) { $this->set( 'published', $object->get_published() ); } if ( $object->get_updated() && ! $this->get_updated() ) { $this->set( 'updated', $object->get_updated() ); } if ( $object->get_attributed_to() && ! $this->get_actor() ) { $this->set( 'actor', $object->get_attributed_to() ); } if ( $this->get_type() !== 'Announce' && $object->get_in_reply_to() && ! $this->get_in_reply_to() ) { $this->set( 'in_reply_to', $object->get_in_reply_to() ); } if ( $object->get_id() && ! $this->get_id() ) { $id = strtok( $object->get_id(), '#' ); if ( $object->get_updated() ) { $updated = $object->get_updated(); } elseif ( $object->get_published() ) { $updated = $object->get_published(); } else { $updated = time(); } $this->set( 'id', $id . '#activity-' . strtolower( $this->get_type() ) . '-' . $updated ); } } /** * The context of an Activity is usually just the context of the object it contains. * * @return array $context A compacted JSON-LD context. */ public function get_json_ld_context() { if ( $this->object instanceof Base_Object ) { $class = get_class( $this->object ); if ( $class && $class::JSON_LD_CONTEXT ) { // Without php 5.6 support this could be just: 'return $this->object::JSON_LD_CONTEXT;'. return $class::JSON_LD_CONTEXT; } } return static::JSON_LD_CONTEXT; } }