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 {
|
2018-09-30 22:51:22 +02:00
|
|
|
private $post;
|
2020-05-14 21:37:59 +02:00
|
|
|
private $post_author;
|
2020-07-21 09:23:35 +02:00
|
|
|
private $id;
|
2020-05-14 21:37:59 +02:00
|
|
|
private $summary;
|
|
|
|
private $content;
|
|
|
|
private $attachments;
|
2020-05-14 22:33:09 +02:00
|
|
|
private $tags;
|
2020-05-14 21:37:59 +02:00
|
|
|
private $object_type;
|
2022-04-15 03:04:43 +02:00
|
|
|
private $deleted;
|
|
|
|
private $updated;
|
|
|
|
private $slug;
|
2018-09-30 22:51:22 +02:00
|
|
|
|
|
|
|
public function __construct( $post = null ) {
|
2019-09-27 10:12:59 +02:00
|
|
|
$this->post = \get_post( $post );
|
2018-09-30 22:51:22 +02:00
|
|
|
|
2020-05-14 22:33:09 +02:00
|
|
|
$this->post_author = $this->post->post_author;
|
2020-07-21 09:23:35 +02:00
|
|
|
$this->id = $this->generate_id();
|
2020-05-14 21:37:59 +02:00
|
|
|
$this->summary = $this->generate_the_title();
|
|
|
|
$this->content = $this->generate_the_content();
|
|
|
|
$this->attachments = $this->generate_attachments();
|
|
|
|
$this->tags = $this->generate_tags();
|
|
|
|
$this->object_type = $this->generate_object_type();
|
2022-04-15 03:04:43 +02:00
|
|
|
$this->replies = $this->generate_replies();
|
|
|
|
//$this->updated = $this->generate_updated();
|
|
|
|
$this->slug = \get_permalink( $this->id );
|
|
|
|
$this->updated = null;
|
|
|
|
$this->delete = $this->get_deleted();
|
2018-12-20 11:33:08 +01:00
|
|
|
}
|
2018-09-30 22:51:22 +02:00
|
|
|
|
2020-05-14 21:37:59 +02:00
|
|
|
public function __call( $method, $params ) {
|
|
|
|
$var = \strtolower( \substr( $method, 4 ) );
|
|
|
|
|
|
|
|
if ( \strncasecmp( $method, 'get', 3 ) === 0 ) {
|
|
|
|
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
|
|
|
|
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(
|
2020-07-21 09:23:35 +02:00
|
|
|
'id' => $this->id,
|
2020-05-14 21:37:59 +02:00
|
|
|
'type' => $this->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 ),
|
2020-05-14 21:37:59 +02:00
|
|
|
'summary' => $this->summary,
|
2018-09-30 22:51:22 +02:00
|
|
|
'inReplyTo' => null,
|
2022-04-15 03:04:43 +02:00
|
|
|
'url' => \get_permalink( $post->ID ),
|
2020-05-14 21:37:59 +02:00
|
|
|
'content' => $this->content,
|
2018-09-30 22:51:22 +02:00
|
|
|
'contentMap' => array(
|
2020-05-14 21:37:59 +02:00
|
|
|
\strstr( \get_locale(), '_', true ) => $this->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' ),
|
2020-05-14 21:37:59 +02:00
|
|
|
'attachment' => $this->attachments,
|
|
|
|
'tag' => $this->tags,
|
2018-09-30 22:51:22 +02:00
|
|
|
);
|
2022-04-15 03:04:43 +02:00
|
|
|
if ( $this->replies ) {
|
|
|
|
$array['replies'] = $this->replies;
|
|
|
|
}
|
|
|
|
if ( $this->deleted ) {
|
|
|
|
$array['deleted'] = \date( 'Y-m-d\TH:i:s\Z', \strtotime( $post->post_modified_gmt ) );
|
|
|
|
// TODO if using slugs instead of ids _ap_deleted_slug
|
|
|
|
//$deleted_post_slug = \get_post_meta( $post->ID, '_ap_deleted_slug', true );
|
|
|
|
//$array['id'] = $deleted_post_slug;
|
|
|
|
}
|
|
|
|
if ( $this->updated ) {
|
|
|
|
$array['updated'] = \date( 'Y-m-d\TH:i:s\Z', \strtotime( $post->post_modified_gmt ) );
|
|
|
|
}
|
2019-09-27 10:12:59 +02:00
|
|
|
return \apply_filters( 'activitypub_post', $array );
|
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
|
|
|
}
|
|
|
|
|
2020-07-21 09:23:35 +02:00
|
|
|
public function generate_id() {
|
2020-05-14 22:33:09 +02:00
|
|
|
$post = $this->post;
|
2022-04-15 03:04:43 +02:00
|
|
|
$permalink = \add_query_arg( //
|
|
|
|
array(
|
|
|
|
'p' => $post->ID,
|
|
|
|
),
|
|
|
|
trailingslashit( site_url() )
|
|
|
|
);
|
2020-05-14 18:02:49 +02:00
|
|
|
|
|
|
|
// replace 'trashed' for delete activity
|
|
|
|
return \str_replace( '__trashed', '', $permalink );
|
|
|
|
}
|
|
|
|
|
2020-05-14 21:37:59 +02:00
|
|
|
public function generate_attachments() {
|
2019-09-27 10:12:59 +02:00
|
|
|
$max_images = \apply_filters( 'activitypub_max_images', 3 );
|
2018-12-20 11:33:08 +01:00
|
|
|
|
|
|
|
$images = array();
|
|
|
|
|
|
|
|
// max images can't be negative or zero
|
|
|
|
if ( $max_images <= 0 ) {
|
|
|
|
$max_images = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$id = $this->post->ID;
|
|
|
|
|
|
|
|
$image_ids = array();
|
|
|
|
// 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--;
|
|
|
|
}
|
|
|
|
// then list any image attachments
|
2019-02-24 12:07:41 +01:00
|
|
|
$query = new \WP_Query(
|
2018-12-20 11:33:08 +01:00
|
|
|
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 ) {
|
2019-09-27 10:12:59 +02:00
|
|
|
if ( ! \in_array( $attachment->ID, $image_ids, true ) ) {
|
2018-12-20 11:33:08 +01:00
|
|
|
$image_ids[] = $attachment->ID;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-18 19:36:46 +01:00
|
|
|
return $images;
|
2018-12-20 11:33:08 +01:00
|
|
|
}
|
|
|
|
|
2020-05-14 21:37:59 +02:00
|
|
|
public function generate_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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $tags;
|
2018-09-30 22:51:22 +02:00
|
|
|
}
|
2022-04-15 03:04:43 +02:00
|
|
|
|
|
|
|
public function generate_replies() {
|
|
|
|
$replies = null;
|
|
|
|
//\error_log( 'generate_replies: $post' . print_r( $this->post, true ) );
|
|
|
|
if ( $this->post->comment_count > 0 ) {
|
|
|
|
$args = array(
|
|
|
|
'post_id' => $this->post->ID, // Use post_id, not post_ID
|
|
|
|
'hierarchical' => false,
|
|
|
|
'status' => 'approve',
|
|
|
|
);
|
|
|
|
$comments = \get_comments( $args );
|
|
|
|
$items = [];
|
|
|
|
|
|
|
|
foreach ( $comments as $comment ){
|
|
|
|
// include self replies
|
|
|
|
if ( $this->post->post_author === $comment->user_id ) {
|
|
|
|
//$comment_url = $comment->comment_ID;
|
|
|
|
$comment_url = \add_query_arg( //
|
|
|
|
array(
|
|
|
|
'p' => $this->post->ID,
|
|
|
|
'ap_comment_id' => $comment->comment_ID
|
|
|
|
),
|
|
|
|
trailingslashit( site_url() )
|
|
|
|
);
|
|
|
|
//\error_log( 'generate_replies: $comment' . print_r( $comment, true ) );
|
|
|
|
$items[] = $comment_url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//\error_log( 'generate_replies: $comments' . print_r( $comments, true ) );
|
|
|
|
$replies = (object) [
|
|
|
|
'type' => 'Collection',
|
|
|
|
'id' => \add_query_arg( array( 'replies' => '' ), $this->id ),
|
|
|
|
'first' => (object) [
|
|
|
|
'type' => 'CollectionPage',
|
|
|
|
'partOf'=> \add_query_arg( array( 'replies' => '' ), $this->id ),
|
|
|
|
'next' => \add_query_arg( array( 'replies' => '', 'page' => 1 ), $this->id ),
|
|
|
|
'items' => $items
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
return $replies;
|
|
|
|
}
|
2018-09-30 22:51:22 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the as2 object-type for a given post
|
|
|
|
*
|
|
|
|
* @param string $type the object-type
|
|
|
|
* @param Object $post the post-object
|
|
|
|
*
|
|
|
|
* @return string the object-type
|
|
|
|
*/
|
2020-05-14 21:37:59 +02:00
|
|
|
public function generate_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $object_type;
|
|
|
|
}
|
2019-01-04 19:57:33 +01:00
|
|
|
|
2020-05-14 21:37:59 +02:00
|
|
|
public function generate_the_content() {
|
2020-07-21 09:23:35 +02:00
|
|
|
$post = $this->post;
|
|
|
|
$content = $this->get_post_content_template();
|
2019-01-04 19:57:33 +01:00
|
|
|
|
2020-07-21 09:23:35 +02:00
|
|
|
$content = \str_replace( '%title%', \get_the_title( $post->ID ), $content );
|
|
|
|
$content = \str_replace( '%excerpt%', $this->get_the_post_excerpt(), $content );
|
|
|
|
$content = \str_replace( '%content%', $this->get_the_post_content(), $content );
|
|
|
|
$content = \str_replace( '%permalink%', $this->get_the_post_link( 'permalink' ), $content );
|
|
|
|
$content = \str_replace( '%shortlink%', $this->get_the_post_link( 'shortlink' ), $content );
|
2020-12-17 18:24:30 +01:00
|
|
|
$content = \str_replace( '%hashtags%', $this->get_the_post_hashtags(), $content );
|
2020-12-17 22:21:41 +01:00
|
|
|
// backwards compatibility
|
|
|
|
$content = \str_replace( '%tags%', $this->get_the_post_hashtags(), $content );
|
2020-07-21 09:23:35 +02:00
|
|
|
|
|
|
|
$content = \trim( \preg_replace( '/[\r\n]{2,}/', '', $content ) );
|
|
|
|
|
|
|
|
$filtered_content = \apply_filters( 'activitypub_the_content', $content, $this->post );
|
|
|
|
$decoded_content = \html_entity_decode( $filtered_content, \ENT_QUOTES, 'UTF-8' );
|
|
|
|
|
|
|
|
$allowed_html = \apply_filters( 'activitypub_allowed_html', \get_option( 'activitypub_allowed_html', ACTIVITYPUB_ALLOWED_HTML ) );
|
|
|
|
|
|
|
|
if ( $allowed_html ) {
|
|
|
|
return \strip_tags( $decoded_content, $allowed_html );
|
2020-01-22 15:57:01 +01:00
|
|
|
}
|
|
|
|
|
2020-07-21 09:23:35 +02:00
|
|
|
return $decoded_content;
|
2019-01-04 19:57:33 +01:00
|
|
|
}
|
|
|
|
|
2020-07-21 09:23:35 +02:00
|
|
|
public function get_post_content_template() {
|
|
|
|
if ( 'excerpt' === \get_option( 'activitypub_post_content_type', 'content' ) ) {
|
|
|
|
return "%excerpt%\n\n<p>%permalink%</p>";
|
|
|
|
}
|
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' ) ) {
|
|
|
|
return "<p><strong>%title%</strong></p>\n\n<p>%permalink%</p>";
|
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' ) ) {
|
2020-12-17 22:21:41 +01:00
|
|
|
return "%content%\n\n<p>%hashtags%</p>\n\n<p>%permalink%</p>";
|
2020-07-21 09:23:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return \get_option( 'activitypub_custom_post_content', ACTIVITYPUB_CUSTOM_POST_CONTENT );
|
2019-02-02 23:56:05 +01:00
|
|
|
}
|
|
|
|
|
2019-01-04 19:57:33 +01:00
|
|
|
/**
|
|
|
|
* Get the excerpt for a post for use outside of the loop.
|
|
|
|
*
|
|
|
|
* @param int Optional excerpt length.
|
|
|
|
*
|
|
|
|
* @return string The excerpt.
|
|
|
|
*/
|
2020-07-21 09:23:35 +02:00
|
|
|
public function get_the_post_excerpt( $excerpt_length = 400 ) {
|
2019-01-04 19:57:33 +01:00
|
|
|
$post = $this->post;
|
|
|
|
|
2019-09-27 10:12:59 +02:00
|
|
|
$excerpt = \get_post_field( 'post_excerpt', $post );
|
2019-01-04 19:57:33 +01:00
|
|
|
|
|
|
|
if ( '' === $excerpt ) {
|
|
|
|
|
2019-09-27 10:12:59 +02:00
|
|
|
$content = \get_post_field( 'post_content', $post );
|
2019-01-04 19:57:33 +01:00
|
|
|
|
|
|
|
// An empty string will make wp_trim_excerpt do stuff we do not want.
|
|
|
|
if ( '' !== $content ) {
|
|
|
|
|
2019-09-27 10:12:59 +02:00
|
|
|
$excerpt = \strip_shortcodes( $content );
|
2019-01-04 19:57:33 +01:00
|
|
|
|
|
|
|
/** This filter is documented in wp-includes/post-template.php */
|
2019-09-27 10:12:59 +02:00
|
|
|
$excerpt = \apply_filters( 'the_content', $excerpt );
|
|
|
|
$excerpt = \str_replace( ']]>', ']]>', $excerpt );
|
2019-01-04 19:57:33 +01:00
|
|
|
|
2019-09-27 10:12:59 +02:00
|
|
|
$excerpt_length = \apply_filters( 'excerpt_length', $excerpt_length );
|
2019-01-04 19:57:33 +01:00
|
|
|
|
|
|
|
/** This filter is documented in wp-includes/formatting.php */
|
2019-09-27 10:12:59 +02:00
|
|
|
$excerpt_more = \apply_filters( 'excerpt_more', ' [...]' );
|
2019-01-04 19:57:33 +01:00
|
|
|
|
2019-09-27 10:12:59 +02:00
|
|
|
$excerpt = \wp_trim_words( $excerpt, $excerpt_length, $excerpt_more );
|
2019-01-04 19:57:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-21 09:23:35 +02:00
|
|
|
return \apply_filters( 'the_excerpt', $excerpt );
|
2019-01-04 19:57:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the content for a post for use outside of the loop.
|
|
|
|
*
|
|
|
|
* @return string The content.
|
|
|
|
*/
|
2020-07-21 09:23:35 +02:00
|
|
|
public function get_the_post_content() {
|
2019-01-04 19:57:33 +01:00
|
|
|
$post = $this->post;
|
|
|
|
|
2019-09-27 10:12:59 +02:00
|
|
|
$content = \get_post_field( 'post_content', $post );
|
2019-01-04 19:57:33 +01:00
|
|
|
|
2020-07-21 09:23:35 +02:00
|
|
|
return \apply_filters( 'the_content', $content );
|
2019-02-02 23:56:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-07-21 09:23:35 +02:00
|
|
|
* Adds a backlink to the post/summary content
|
2019-02-02 23:56:05 +01:00
|
|
|
*
|
2020-07-21 09:23:35 +02:00
|
|
|
* @param string $content
|
|
|
|
* @param WP_Post $post
|
2019-02-02 23:56:05 +01:00
|
|
|
*
|
2020-07-21 09:23:35 +02:00
|
|
|
* @return string
|
2019-02-02 23:56:05 +01:00
|
|
|
*/
|
2020-07-21 09:23:35 +02:00
|
|
|
public function get_the_post_link( $type = 'permalink' ) {
|
|
|
|
$post = $this->post;
|
2019-01-16 21:50:45 +01:00
|
|
|
|
2020-07-21 09:23:35 +02:00
|
|
|
if ( 'shortlink' === $type ) {
|
|
|
|
$link = \esc_url( \wp_get_shortlink( $post->ID ) );
|
|
|
|
} elseif ( 'permalink' === $type ) {
|
|
|
|
$link = \esc_url( \get_permalink( $post->ID ) );
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
2019-01-04 19:57:33 +01:00
|
|
|
|
2020-07-21 09:23:35 +02:00
|
|
|
return \sprintf( '<a href="%1$s">%1$s</a>', $link );
|
2019-02-02 23:56:05 +01:00
|
|
|
}
|
|
|
|
|
2019-03-02 21:10:42 +01:00
|
|
|
/**
|
2020-07-21 09:23:35 +02:00
|
|
|
* Adds all tags as hashtags to the post/summary content
|
2019-03-02 21:10:42 +01:00
|
|
|
*
|
|
|
|
* @param string $content
|
|
|
|
* @param WP_Post $post
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2020-07-21 09:23:35 +02:00
|
|
|
public function get_the_post_hashtags() {
|
|
|
|
$post = $this->post;
|
|
|
|
$tags = \get_the_tags( $post->ID );
|
2019-02-02 23:56:05 +01:00
|
|
|
|
2020-07-21 09:23:35 +02:00
|
|
|
if ( ! $tags ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$hash_tags = array();
|
|
|
|
|
|
|
|
foreach ( $tags as $tag ) {
|
|
|
|
$hash_tags[] = \sprintf( '<a rel="tag" class="u-tag u-category" href="%s">#%s</a>', \get_tag_link( $tag ), $tag->slug );
|
2019-02-02 23:56:05 +01:00
|
|
|
}
|
|
|
|
|
2020-07-21 09:23:35 +02:00
|
|
|
return \implode( ' ', $hash_tags );
|
2019-01-04 19:57:33 +01:00
|
|
|
}
|
2022-04-15 03:04:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get deleted datetime
|
|
|
|
*/
|
|
|
|
public function get_deleted() {
|
|
|
|
$post = $this->post;
|
|
|
|
$deleted = null;
|
|
|
|
if ( 'trash' == $post->post_status ) {
|
|
|
|
|
|
|
|
$deleted = \date( 'Y-m-d\TH:i:s\Z', \strtotime( $post->post_modified_gmt ) );
|
|
|
|
\error_log( 'trash: ' . print_r( $deleted, true ) );
|
|
|
|
}
|
|
|
|
return $deleted;
|
|
|
|
}
|
2018-09-30 22:51:22 +02:00
|
|
|
}
|