2018-09-30 22:51:22 +02:00
|
|
|
<?php
|
2019-11-18 20:57:00 +01:00
|
|
|
namespace Activitypub\Model;
|
2019-02-24 12:07:41 +01:00
|
|
|
|
2018-09-30 22:51:22 +02:00
|
|
|
/**
|
|
|
|
* ActivityPub Post Class
|
|
|
|
*
|
|
|
|
* @author Matthias Pfefferle
|
|
|
|
*/
|
2019-02-24 12:07:41 +01:00
|
|
|
class Post {
|
2023-01-27 10:21:51 +01:00
|
|
|
/**
|
|
|
|
* The WordPress Post Object.
|
|
|
|
*
|
|
|
|
* @var WP_Post
|
|
|
|
*/
|
2018-09-30 22:51:22 +02:00
|
|
|
private $post;
|
2023-01-27 10:21:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Post Author.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2020-05-14 21:37:59 +02:00
|
|
|
private $post_author;
|
2023-01-27 10:21:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Object ID.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2020-07-21 09:23:35 +02:00
|
|
|
private $id;
|
2023-01-27 10:21:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Object Summary.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2020-05-14 21:37:59 +02:00
|
|
|
private $summary;
|
2023-01-27 10:21:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Object Summary
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2020-05-14 21:37:59 +02:00
|
|
|
private $content;
|
2023-01-27 10:21:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Object Attachments. This is usually a list of Images.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2020-05-14 21:37:59 +02:00
|
|
|
private $attachments;
|
2023-01-27 10:21:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Object Tags. This is usually the list of used Hashtags.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2020-05-14 22:33:09 +02:00
|
|
|
private $tags;
|
2018-09-30 22:51:22 +02:00
|
|
|
|
2023-01-27 10:21:51 +01:00
|
|
|
/**
|
|
|
|
* The Onject Type
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $object_type = 'Note';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Allowed Tags, used in the content.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private $allowed_tags = array(
|
|
|
|
'a' => array(
|
|
|
|
'href' => array(),
|
|
|
|
'title' => array(),
|
|
|
|
'class' => array(),
|
|
|
|
'rel' => array(),
|
|
|
|
),
|
|
|
|
'br' => array(),
|
|
|
|
'p' => array(
|
|
|
|
'class' => array(),
|
|
|
|
),
|
|
|
|
'span' => array(
|
|
|
|
'class' => array(),
|
|
|
|
),
|
|
|
|
'div' => array(
|
|
|
|
'class' => array(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param WP_Post $post
|
|
|
|
*/
|
2023-01-23 20:31:14 +01:00
|
|
|
public function __construct( $post ) {
|
|
|
|
$this->post = \get_post( $post );
|
2018-12-20 11:33:08 +01:00
|
|
|
}
|
2018-09-30 22:51:22 +02:00
|
|
|
|
2023-01-27 10:21:51 +01:00
|
|
|
/**
|
|
|
|
* Magic function to implement getter and setter
|
|
|
|
*
|
|
|
|
* @param string $method
|
|
|
|
* @param string $params
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-05-14 21:37:59 +02:00
|
|
|
public function __call( $method, $params ) {
|
|
|
|
$var = \strtolower( \substr( $method, 4 ) );
|
|
|
|
|
|
|
|
if ( \strncasecmp( $method, 'get', 3 ) === 0 ) {
|
2023-01-27 14:28:56 +01:00
|
|
|
if ( empty( $this->$var ) && ! empty( $this->post->$var ) ) {
|
|
|
|
return $this->post->$var;
|
|
|
|
}
|
2020-05-14 21:37:59 +02:00
|
|
|
return $this->$var;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( \strncasecmp( $method, 'set', 3 ) === 0 ) {
|
|
|
|
$this->$var = $params[0];
|
|
|
|
}
|
2018-12-20 11:33:08 +01:00
|
|
|
}
|
2018-09-30 22:51:22 +02:00
|
|
|
|
2023-01-27 10:21:51 +01:00
|
|
|
/**
|
|
|
|
* Converts this Object into an Array.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2018-12-20 11:33:08 +01:00
|
|
|
public function to_array() {
|
|
|
|
$post = $this->post;
|
2018-09-30 22:51:22 +02:00
|
|
|
|
2018-12-20 11:33:08 +01:00
|
|
|
$array = array(
|
2023-01-27 10:21:51 +01:00
|
|
|
'id' => $this->get_id(),
|
|
|
|
'type' => $this->get_object_type(),
|
2022-01-27 13:09:11 +01:00
|
|
|
'published' => \gmdate( 'Y-m-d\TH:i:s\Z', \strtotime( $post->post_date_gmt ) ),
|
2019-09-27 10:12:59 +02:00
|
|
|
'attributedTo' => \get_author_posts_url( $post->post_author ),
|
2023-01-27 10:21:51 +01:00
|
|
|
'summary' => $this->get_summary(),
|
2018-09-30 22:51:22 +02:00
|
|
|
'inReplyTo' => null,
|
2023-01-27 10:21:51 +01:00
|
|
|
'content' => $this->get_content(),
|
2018-09-30 22:51:22 +02:00
|
|
|
'contentMap' => array(
|
2023-01-27 10:21:51 +01:00
|
|
|
\strstr( \get_locale(), '_', true ) => $this->get_content(),
|
2018-09-30 22:51:22 +02:00
|
|
|
),
|
2018-12-20 11:33:08 +01:00
|
|
|
'to' => array( 'https://www.w3.org/ns/activitystreams#Public' ),
|
|
|
|
'cc' => array( 'https://www.w3.org/ns/activitystreams#Public' ),
|
2023-01-27 10:21:51 +01:00
|
|
|
'attachment' => $this->get_attachments(),
|
|
|
|
'tag' => $this->get_tags(),
|
2018-09-30 22:51:22 +02:00
|
|
|
);
|
|
|
|
|
2023-02-02 08:50:17 +01:00
|
|
|
return \apply_filters( 'activitypub_post', $array, $this->post );
|
2018-12-20 11:33:08 +01:00
|
|
|
}
|
|
|
|
|
2023-01-27 10:21:51 +01:00
|
|
|
/**
|
|
|
|
* Converts this Object into a JSON String
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-12-20 11:33:08 +01:00
|
|
|
public function to_json() {
|
2020-05-12 19:42:09 +02:00
|
|
|
return \wp_json_encode( $this->to_array(), \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_QUOT );
|
2018-12-20 11:33:08 +01:00
|
|
|
}
|
|
|
|
|
2023-01-27 10:21:51 +01:00
|
|
|
/**
|
|
|
|
* Returns the ID of an Activity Object
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_id() {
|
|
|
|
if ( $this->id ) {
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
2022-12-27 15:48:14 +01:00
|
|
|
$post = $this->post;
|
|
|
|
|
|
|
|
if ( 'trash' === get_post_status( $post ) ) {
|
2022-12-27 16:58:49 +01:00
|
|
|
$permalink = \get_post_meta( $post->ID, 'activitypub_canonical_url', true );
|
2022-12-27 15:48:14 +01:00
|
|
|
} else {
|
|
|
|
$permalink = \get_permalink( $post );
|
|
|
|
}
|
2020-05-14 18:02:49 +02:00
|
|
|
|
2023-01-27 10:21:51 +01:00
|
|
|
$this->id = $permalink;
|
|
|
|
|
2022-12-27 15:48:14 +01:00
|
|
|
return $permalink;
|
2020-05-14 18:02:49 +02:00
|
|
|
}
|
|
|
|
|
2023-01-27 10:21:51 +01:00
|
|
|
/**
|
|
|
|
* Returns a list of Image Attachments
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_attachments() {
|
|
|
|
if ( $this->attachments ) {
|
|
|
|
return $this->attachments;
|
|
|
|
}
|
|
|
|
|
2023-01-12 21:29:21 +01:00
|
|
|
$max_images = intval( \apply_filters( 'activitypub_max_image_attachments', \get_option( 'activitypub_max_image_attachments', ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS ) ) );
|
2018-12-20 11:33:08 +01:00
|
|
|
|
|
|
|
$images = array();
|
|
|
|
|
|
|
|
// max images can't be negative or zero
|
|
|
|
if ( $max_images <= 0 ) {
|
2023-01-12 21:55:33 +01:00
|
|
|
return $images;
|
2018-12-20 11:33:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$id = $this->post->ID;
|
|
|
|
|
|
|
|
$image_ids = array();
|
2023-01-12 22:21:48 +01:00
|
|
|
|
2018-12-20 11:33:08 +01:00
|
|
|
// list post thumbnail first if this post has one
|
2019-09-27 10:12:59 +02:00
|
|
|
if ( \function_exists( 'has_post_thumbnail' ) && \has_post_thumbnail( $id ) ) {
|
|
|
|
$image_ids[] = \get_post_thumbnail_id( $id );
|
2018-12-20 11:33:08 +01:00
|
|
|
$max_images--;
|
|
|
|
}
|
2023-01-12 22:21:48 +01:00
|
|
|
|
|
|
|
if ( $max_images > 0 ) {
|
|
|
|
// then list any image attachments
|
|
|
|
$query = new \WP_Query(
|
|
|
|
array(
|
|
|
|
'post_parent' => $id,
|
|
|
|
'post_status' => 'inherit',
|
|
|
|
'post_type' => 'attachment',
|
|
|
|
'post_mime_type' => 'image',
|
|
|
|
'order' => 'ASC',
|
|
|
|
'orderby' => 'menu_order ID',
|
|
|
|
'posts_per_page' => $max_images,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
foreach ( $query->get_posts() as $attachment ) {
|
|
|
|
if ( ! \in_array( $attachment->ID, $image_ids, true ) ) {
|
|
|
|
$image_ids[] = $attachment->ID;
|
|
|
|
}
|
2018-12-20 11:33:08 +01:00
|
|
|
}
|
|
|
|
}
|
2019-09-27 11:37:15 +02:00
|
|
|
|
|
|
|
$image_ids = \array_unique( $image_ids );
|
|
|
|
|
2018-12-20 11:33:08 +01:00
|
|
|
// get URLs for each image
|
|
|
|
foreach ( $image_ids as $id ) {
|
2020-01-18 19:36:46 +01:00
|
|
|
$alt = \get_post_meta( $id, '_wp_attachment_image_alt', true );
|
2019-09-27 10:12:59 +02:00
|
|
|
$thumbnail = \wp_get_attachment_image_src( $id, 'full' );
|
|
|
|
$mimetype = \get_post_mime_type( $id );
|
2018-12-20 11:33:08 +01:00
|
|
|
|
|
|
|
if ( $thumbnail ) {
|
2020-01-18 19:36:46 +01:00
|
|
|
$image = array(
|
2019-02-24 12:07:41 +01:00
|
|
|
'type' => 'Image',
|
2020-01-18 19:36:46 +01:00
|
|
|
'url' => $thumbnail[0],
|
2020-05-14 21:37:59 +02:00
|
|
|
'mediaType' => $mimetype,
|
2018-12-20 11:33:08 +01:00
|
|
|
);
|
2020-01-18 19:36:46 +01:00
|
|
|
if ( $alt ) {
|
|
|
|
$image['name'] = $alt;
|
|
|
|
}
|
|
|
|
$images[] = $image;
|
2018-12-20 11:33:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-27 10:21:51 +01:00
|
|
|
$this->attachments = $images;
|
|
|
|
|
2020-01-18 19:36:46 +01:00
|
|
|
return $images;
|
2018-12-20 11:33:08 +01:00
|
|
|
}
|
|
|
|
|
2023-01-27 10:21:51 +01:00
|
|
|
/**
|
|
|
|
* Returns a list of Tags, used in the Post
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_tags() {
|
|
|
|
if ( $this->tags ) {
|
|
|
|
return $this->tags;
|
|
|
|
}
|
|
|
|
|
2018-12-20 11:33:08 +01:00
|
|
|
$tags = array();
|
|
|
|
|
2019-09-27 10:12:59 +02:00
|
|
|
$post_tags = \get_the_tags( $this->post->ID );
|
2018-12-20 11:33:08 +01:00
|
|
|
if ( $post_tags ) {
|
2019-03-02 21:10:42 +01:00
|
|
|
foreach ( $post_tags as $post_tag ) {
|
2018-12-20 11:33:08 +01:00
|
|
|
$tag = array(
|
2019-02-24 12:07:41 +01:00
|
|
|
'type' => 'Hashtag',
|
2019-09-27 10:12:59 +02:00
|
|
|
'href' => \get_tag_link( $post_tag->term_id ),
|
2019-02-24 12:07:41 +01:00
|
|
|
'name' => '#' . $post_tag->slug,
|
2018-12-20 11:33:08 +01:00
|
|
|
);
|
|
|
|
$tags[] = $tag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 18:41:26 +01:00
|
|
|
$mentions = apply_filters( 'activitypub_extract_mentions', array(), $this->post->post_content, $this );
|
2022-12-09 11:59:24 +01:00
|
|
|
if ( $mentions ) {
|
|
|
|
foreach ( $mentions as $mention => $url ) {
|
|
|
|
$tag = array(
|
|
|
|
'type' => 'Mention',
|
|
|
|
'href' => $url,
|
|
|
|
'name' => $mention,
|
|
|
|
);
|
|
|
|
$tags[] = $tag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-27 10:21:51 +01:00
|
|
|
$this->tags = $tags;
|
|
|
|
|
2018-12-20 11:33:08 +01:00
|
|
|
return $tags;
|
2018-09-30 22:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the as2 object-type for a given post
|
|
|
|
*
|
|
|
|
* @return string the object-type
|
|
|
|
*/
|
2023-01-27 10:21:51 +01:00
|
|
|
public function get_object_type() {
|
|
|
|
if ( $this->object_type ) {
|
|
|
|
return $this->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
|
|
|
}
|
|
|
|
|
2019-09-27 10:12:59 +02:00
|
|
|
$post_type = \get_post_type( $this->post );
|
2018-09-30 22:51:22 +02:00
|
|
|
switch ( $post_type ) {
|
|
|
|
case 'post':
|
2019-09-27 10:12:59 +02:00
|
|
|
$post_format = \get_post_format( $this->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':
|
2019-09-27 10:12:59 +02:00
|
|
|
$mime_type = \get_post_mime_type();
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
2023-01-27 10:21:51 +01:00
|
|
|
$this->object_type = $object_type;
|
|
|
|
|
2018-09-30 22:51:22 +02:00
|
|
|
return $object_type;
|
|
|
|
}
|
2019-01-04 19:57:33 +01:00
|
|
|
|
2023-01-16 16:27:27 +01:00
|
|
|
/**
|
2023-01-27 10:21:51 +01:00
|
|
|
* Returns the content for the ActivityPub Item.
|
2023-01-16 16:27:27 +01:00
|
|
|
*
|
|
|
|
* @return string the content
|
|
|
|
*/
|
2023-01-27 10:21:51 +01:00
|
|
|
public function get_content() {
|
2023-02-02 08:18:10 +01:00
|
|
|
global $post;
|
|
|
|
|
2023-01-27 10:21:51 +01:00
|
|
|
if ( $this->content ) {
|
|
|
|
return $this->content;
|
|
|
|
}
|
|
|
|
|
2023-02-02 08:18:10 +01:00
|
|
|
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
|
|
|
$post = $this->post;
|
2020-07-21 09:23:35 +02:00
|
|
|
$content = $this->get_post_content_template();
|
2019-01-04 19:57:33 +01:00
|
|
|
|
2023-01-13 21:47:13 +01:00
|
|
|
// Fill in the shortcodes.
|
2023-01-23 17:59:13 +01:00
|
|
|
setup_postdata( $post );
|
2023-01-13 21:47:13 +01:00
|
|
|
$content = do_shortcode( $content );
|
2023-01-23 17:59:13 +01:00
|
|
|
wp_reset_postdata();
|
2020-07-21 09:23:35 +02:00
|
|
|
|
2023-01-27 10:21:51 +01:00
|
|
|
$content = \wpautop( \wp_kses( $content, $this->allowed_tags ) );
|
2020-07-21 09:23:35 +02:00
|
|
|
|
2023-01-27 10:21:51 +01:00
|
|
|
$filtered_content = \apply_filters( 'activitypub_the_content', $content, $post );
|
2023-02-20 18:08:10 +01:00
|
|
|
$content = \html_entity_decode( $filtered_content, \ENT_QUOTES, 'UTF-8' );
|
2020-07-21 09:23:35 +02:00
|
|
|
|
2023-01-27 10:21:51 +01:00
|
|
|
$this->content = $content;
|
2020-01-22 15:57:01 +01:00
|
|
|
|
2023-01-27 10:21:51 +01:00
|
|
|
return $content;
|
2019-01-04 19:57:33 +01:00
|
|
|
}
|
|
|
|
|
2023-01-16 16:27:27 +01:00
|
|
|
/**
|
|
|
|
* Gets the template to use to generate the content of the activitypub item.
|
|
|
|
*
|
|
|
|
* @return string the template
|
|
|
|
*/
|
2020-07-21 09:23:35 +02:00
|
|
|
public function get_post_content_template() {
|
|
|
|
if ( 'excerpt' === \get_option( 'activitypub_post_content_type', 'content' ) ) {
|
2023-02-08 10:06:22 +01:00
|
|
|
return "[ap_excerpt]\n\n[ap_permalink type=\"html\"]";
|
2020-07-21 09:23:35 +02:00
|
|
|
}
|
2019-02-20 20:25:19 +01:00
|
|
|
|
2020-07-21 09:23:35 +02:00
|
|
|
if ( 'title' === \get_option( 'activitypub_post_content_type', 'content' ) ) {
|
2023-02-08 10:06:22 +01:00
|
|
|
return "[ap_title]\n\n[ap_permalink type=\"html\"]";
|
2019-02-02 23:56:05 +01:00
|
|
|
}
|
|
|
|
|
2020-07-21 09:23:35 +02:00
|
|
|
if ( 'content' === \get_option( 'activitypub_post_content_type', 'content' ) ) {
|
2023-02-08 10:06:22 +01:00
|
|
|
return "[ap_content]\n\n[ap_hashtags]\n\n[ap_permalink type=\"html\"]";
|
2023-01-13 21:47:13 +01:00
|
|
|
}
|
|
|
|
|
2023-01-16 16:27:27 +01:00
|
|
|
// Upgrade from old template codes to shortcodes.
|
2023-01-23 21:24:54 +01:00
|
|
|
$content = self::upgrade_post_content_template();
|
2023-01-16 16:27:27 +01:00
|
|
|
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the custom template to use shortcodes instead of the deprecated templates.
|
|
|
|
*
|
|
|
|
* @return string the updated template content
|
|
|
|
*/
|
2023-01-23 20:31:14 +01:00
|
|
|
public static function upgrade_post_content_template() {
|
2023-01-13 21:47:13 +01:00
|
|
|
// Get the custom template.
|
2023-01-16 16:27:27 +01:00
|
|
|
$old_content = \get_option( 'activitypub_custom_post_content', ACTIVITYPUB_CUSTOM_POST_CONTENT );
|
|
|
|
|
|
|
|
// If the old content exists but is a blank string, we're going to need a flag to updated it even
|
|
|
|
// after setting it to the default contents.
|
|
|
|
$need_update = false;
|
|
|
|
|
|
|
|
// If the old contents is blank, use the defaults.
|
2023-01-23 20:13:56 +01:00
|
|
|
if ( '' === $old_content ) {
|
2023-01-23 19:43:34 +01:00
|
|
|
$old_content = ACTIVITYPUB_CUSTOM_POST_CONTENT;
|
2023-01-27 10:21:51 +01:00
|
|
|
$need_update = true;
|
|
|
|
}
|
2023-01-16 16:27:27 +01:00
|
|
|
|
|
|
|
// Set the new content to be the old content.
|
|
|
|
$content = $old_content;
|
2023-01-13 21:47:13 +01:00
|
|
|
|
2023-01-16 16:27:27 +01:00
|
|
|
// Convert old templates to shortcodes.
|
2023-01-13 21:47:13 +01:00
|
|
|
$content = \str_replace( '%title%', '[ap_title]', $content );
|
|
|
|
$content = \str_replace( '%excerpt%', '[ap_excerpt]', $content );
|
|
|
|
$content = \str_replace( '%content%', '[ap_content]', $content );
|
2023-01-23 20:59:39 +01:00
|
|
|
$content = \str_replace( '%permalink%', '[ap_permalink type="html"]', $content );
|
|
|
|
$content = \str_replace( '%shortlink%', '[ap_shortlink type="html"]', $content );
|
2023-01-13 21:47:13 +01:00
|
|
|
$content = \str_replace( '%hashtags%', '[ap_hashtags]', $content );
|
|
|
|
$content = \str_replace( '%tags%', '[ap_hashtags]', $content );
|
|
|
|
|
|
|
|
// Store the new template if required.
|
2023-01-23 20:13:56 +01:00
|
|
|
if ( $content !== $old_content || $need_update ) {
|
2023-01-13 21:47:13 +01:00
|
|
|
\update_option( 'activitypub_custom_post_content', $content );
|
2020-07-21 09:23:35 +02:00
|
|
|
}
|
|
|
|
|
2023-01-13 21:47:13 +01:00
|
|
|
return $content;
|
2019-02-02 23:56:05 +01:00
|
|
|
}
|
2018-09-30 22:51:22 +02:00
|
|
|
}
|