smoother build process
Some checks failed
PHP_CodeSniffer / phpcs (push) Failing after 4m10s
Unit Testing / phpunit (5.6, 6.2) (push) Failing after 4m52s
Unit Testing / phpunit (7.0) (push) Failing after 5m10s
Unit Testing / phpunit (7.2) (push) Failing after 4m55s
Unit Testing / phpunit (7.3) (push) Failing after 6m6s
Unit Testing / phpunit (7.4) (push) Failing after 5m48s
Unit Testing / phpunit (8.0) (push) Failing after 5m51s
Unit Testing / phpunit (8.1) (push) Failing after 5m43s
Unit Testing / phpunit (8.2) (push) Failing after 5m59s
Unit Testing / phpunit (latest) (push) Failing after 5m47s

This commit is contained in:
ruru4143 2023-12-09 02:01:13 +01:00
parent 31c09cd329
commit ca940bfc4e
2 changed files with 117 additions and 2 deletions

View file

@ -453,6 +453,10 @@ class Base_Object {
return new WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) ); return new WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
} }
if ( $var === 'skip_next' ) {
return; // skip_next should never be retrieved publicly
}
return $this->$var; return $this->$var;
} }
@ -522,6 +526,11 @@ class Base_Object {
return new WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) ); return new WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
} }
if ( $this->skip_next ) {
$this->skip_next = false;
return $this;
}
$this->$key = $value; $this->$key = $value;
return $this; return $this;
@ -675,4 +684,11 @@ class Base_Object {
return \wp_json_encode( $array, \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_QUOT ); return \wp_json_encode( $array, \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_QUOT );
} }
public function if( bool $b ) {
$this->skip_next = ! $b;
return $this;
}
} }

View file

@ -33,6 +33,13 @@ abstract class Base {
*/ */
protected $wp_post; protected $wp_post;
/**
* Time format string for date or gmdate
*
* @var string
*/
protected $timeformat;
/** /**
* Get the name used for registering the transformer with the ActivityPub plugin. * Get the name used for registering the transformer with the ActivityPub plugin.
* *
@ -68,6 +75,48 @@ abstract class Base {
*/ */
abstract public function transform(); abstract public function transform();
/**
* Retrieves a post meta field for the configured post.
*
* @param string $key Optional. The meta key to retrieve. By default,
* returns data for all keys. Default empty.
* @param bool $single Optional. Whether to return a single value.
* This parameter has no effect if `$key` is not specified.
* Default false.
* @return mixed An array of values if `$single` is false.
* The value of the meta field if `$single` is true.
* False for an invalid `$post_id` (non-numeric, zero, or negative value).
* An empty string if a valid but non-existing post ID is passed.
*/
public function get_post_meta( string $key = '', $single = false, $default = null ) {
// todo test what if not present
// empty string or empty array, then return default
return \get_post_meta( $this->wp_post->ID, $key, $single );
}
/**
* Retrieves a post meta field for the configured post.
*
* @param string $key The meta key of the time value to retrieve.
* @return string formatted time
*/
public function get_post_meta_time( string $key ) {
$time = $this->get_post_meta( $key, true ); // todo what if not exists
$time = \strtotime( $time );
return \gmdate( $this->timeformat, $time );
}
/**
* Retrieves if comments are enabled of the configured post.
*
* @return bool True if the comments are open.
*/
public function get_comments_open() {
return comments_open( $this->wp_post->ID );
}
/** /**
* Getter function for this wp_post. * Getter function for this wp_post.
* *
@ -98,6 +147,56 @@ abstract class Base {
$this->wp_post = $wp_post; $this->wp_post = $wp_post;
} }
/**
* Setter for $timeformat.
*
* This configures a timeformat string for converting timestaps into dates
*
* @param string $timeformat The time format string.
* @return void
*/
public function set_timeformat( string $timeformat ) {
$this->timeformat = $timeformat;
}
/**
* Get published time in configured format
*
* This queries the published time from the wp_object and returns it in the configured format
*
* @return string
*/
public function get_published() {
$published = \strtotime( $this->wp_post->post_date_gmt );
return \gmdate( 'Y-m-d\TH:i:s\Z', $published );
}
/**
* Get updated time in configured format
*
* This queries the update time from the wp_object and returns it in the configured format
*
* @return string
*/
public function get_updated() {
$updated = \strtotime( $this->wp_post->post_modified_gmt );
return \gmdate( 'Y-m-d\TH:i:s\Z', $updated );
}
/**
* TODO review and write description
*
* @return array
*/
public function get_followers_stream() {
$path = sprintf( 'users/%d/followers', intval( $this->wp_post->post_author ) );
return array(
'https://www.w3.org/ns/activitystreams#Public',
get_rest_url_by_path( $path ),
);
}
/** /**
* Get the supported WP post types that the transformer can use as an input. * Get the supported WP post types that the transformer can use as an input.
* *
@ -242,7 +341,7 @@ abstract class Base {
* @return string The User-URL. * @return string The User-URL.
*/ */
protected function get_attributed_to() { protected function get_attributed_to() {
if ( is_single_user() ) { if ( is_single_user() ) { // todo what is if this setting gets changed
$user = new Blog_User(); $user = new Blog_User();
return $user->get_url(); return $user->get_url();
} }
@ -590,7 +689,7 @@ abstract class Base {
* *
* @return array the contenmap * @return array the contenmap
*/ */
protected function get_content_map() { protected function get_basic_content_map() {
return array( return array(
$this->get_locale() => $this->get_content(), $this->get_locale() => $this->get_content(),
); );