wordpress-activitypub/includes/transformer/class-post.php

110 lines
2.5 KiB
PHP
Raw Permalink Normal View History

2018-09-30 22:51:22 +02:00
<?php
namespace Activitypub\Transformer;
2023-07-03 17:59:42 +02:00
use WP_Post;
2023-07-03 19:25:49 +02:00
use Activitypub\Collection\Users;
2023-07-10 15:14:37 +02:00
use Activitypub\Model\Blog_User;
2023-07-03 19:25:49 +02:00
use Activitypub\Activity\Base_Object;
use Activitypub\Shortcodes;
use Activitypub\Transformer\Base;
use function Activitypub\esc_hashtag;
2023-07-10 10:57:06 +02:00
use function Activitypub\is_single_user;
2023-05-12 22:31:53 +02:00
use function Activitypub\get_rest_url_by_path;
use function Activitypub\site_supports_blocks;
2023-05-12 22:31:53 +02:00
2018-09-30 22:51:22 +02:00
/**
2023-07-03 17:59:42 +02:00
* WordPress Post Transformer
* The Post Transformer is responsible for transforming a WP_Post object into different othe
* Object-Types.
*
* Currently supported are:
* - Activitypub\Activity\Base_Object
2018-09-30 22:51:22 +02:00
*/
class Post extends Base {
/**
* Getter function for the name of the transformer.
*
* @return string name
*/
public function get_name() {
return 'activitypub/default';
}
/**
* Getter function for the display name (label/title) of the transformer.
*
* @return string name
*/
public function get_label() {
return 'Built-In';
}
/**
2023-07-03 17:59:42 +02:00
* Returns the ActivityStreams 2.0 Object-Type for a Post based on the
* settings and the Post-Type.
*
2023-07-03 17:59:42 +02:00
* @see https://www.w3.org/TR/activitystreams-vocabulary/#activity-types
2018-09-30 22:51:22 +02:00
*
2023-07-03 17:59:42 +02:00
* @return string The Object-Type.
2018-09-30 22:51:22 +02:00
*/
2023-07-03 17:59:42 +02:00
protected function get_object_type() {
2019-09-27 10:12:59 +02:00
if ( 'wordpress-post-format' !== \get_option( 'activitypub_object_type', 'note' ) ) {
return \ucfirst( \get_option( 'activitypub_object_type', 'note' ) );
2018-12-28 22:40:57 +01:00
}
// Default to Article.
$object_type = 'Article';
$post_type = \get_post_type( $this->wp_post );
2018-09-30 22:51:22 +02:00
switch ( $post_type ) {
case 'post':
2023-07-03 17:59:42 +02:00
$post_format = \get_post_format( $this->wp_post );
2018-09-30 22:51:22 +02:00
switch ( $post_format ) {
case 'aside':
case 'status':
case 'quote':
case 'note':
$object_type = 'Note';
break;
case 'gallery':
case 'image':
$object_type = 'Image';
break;
case 'video':
$object_type = 'Video';
break;
case 'audio':
$object_type = 'Audio';
break;
default:
$object_type = 'Article';
break;
}
break;
case 'page':
$object_type = 'Page';
break;
case 'attachment':
$mime_type = \get_post_mime_type();
2019-09-27 10:12:59 +02:00
$media_type = \preg_replace( '/(\/[a-zA-Z]+)/i', '', $mime_type );
2018-09-30 22:51:22 +02:00
switch ( $media_type ) {
case 'audio':
$object_type = 'Audio';
break;
case 'video':
$object_type = 'Video';
break;
case 'image':
$object_type = 'Image';
break;
}
break;
default:
$object_type = 'Article';
break;
}
return $object_type;
}
}