diff --git a/activitypub.php b/activitypub.php
index 8bb18cb90..5d516960f 100644
--- a/activitypub.php
+++ b/activitypub.php
@@ -3,7 +3,7 @@
* Plugin Name: ActivityPub
* Plugin URI: https://github.com/pfefferle/wordpress-activitypub/
* Description: The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format.
- * Version: 4.0.2
+ * Version: 4.1.0
* Author: Matthias Pfefferle & Automattic
* Author URI: https://automattic.com/
* License: MIT
@@ -35,7 +35,7 @@
\defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || \define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(?:(?<=\s)|(?<=
)|(?<=
)|^)#([A-Za-z0-9_]+)(?:(?=\s|[[:punct:]]|$))' );
\defined( 'ACTIVITYPUB_USERNAME_REGEXP' ) || \define( 'ACTIVITYPUB_USERNAME_REGEXP', '(?:([A-Za-z0-9\._-]+)@((?:[A-Za-z0-9_-]+\.)+[A-Za-z]+))' );
\defined( 'ACTIVITYPUB_URL_REGEXP' ) || \define( 'ACTIVITYPUB_URL_REGEXP', '(https?:|www\.)\S+[\w\/]' );
-\defined( 'ACTIVITYPUB_CUSTOM_POST_CONTENT' ) || \define( 'ACTIVITYPUB_CUSTOM_POST_CONTENT', "
[ap_title]
\n\n[ap_content]\n\n[ap_hashtags]\n\n[ap_shortlink]" );
+\defined( 'ACTIVITYPUB_CUSTOM_POST_CONTENT' ) || \define( 'ACTIVITYPUB_CUSTOM_POST_CONTENT', "[ap_title type=\"html\"]\n\n[ap_content]\n\n[ap_hashtags]" );
\defined( 'ACTIVITYPUB_AUTHORIZED_FETCH' ) || \define( 'ACTIVITYPUB_AUTHORIZED_FETCH', false );
\defined( 'ACTIVITYPUB_DISABLE_REWRITES' ) || \define( 'ACTIVITYPUB_DISABLE_REWRITES', false );
\defined( 'ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS' ) || \define( 'ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS', false );
@@ -44,7 +44,7 @@
\defined( 'ACTIVITYPUB_DISABLE_OUTGOING_INTERACTIONS' ) || \define( 'ACTIVITYPUB_DISABLE_OUTGOING_INTERACTIONS', false );
\defined( 'ACTIVITYPUB_SHARED_INBOX_FEATURE' ) || \define( 'ACTIVITYPUB_SHARED_INBOX_FEATURE', false );
\defined( 'ACTIVITYPUB_SEND_VARY_HEADER' ) || \define( 'ACTIVITYPUB_SEND_VARY_HEADER', false );
-\defined( 'ACTIVITYPUB_DEFAULT_OBJECT_TYPE' ) || \define( 'ACTIVITYPUB_DEFAULT_OBJECT_TYPE', 'note' );
+\defined( 'ACTIVITYPUB_DEFAULT_OBJECT_TYPE' ) || \define( 'ACTIVITYPUB_DEFAULT_OBJECT_TYPE', 'wordpress-post-format' );
// Define Actor-Modes for the plugin.
\define( 'ACTIVITYPUB_ACTOR_MODE', 'actor' );
diff --git a/includes/class-admin.php b/includes/class-admin.php
index 6fec55eb0..feffc8985 100644
--- a/includes/class-admin.php
+++ b/includes/class-admin.php
@@ -236,7 +236,7 @@ public static function register_settings() {
),
),
),
- 'default' => 'note',
+ 'default' => ACTIVITYPUB_DEFAULT_OBJECT_TYPE,
)
);
\register_setting(
diff --git a/includes/class-migration.php b/includes/class-migration.php
index 72bd683b7..ac64ee323 100644
--- a/includes/class-migration.php
+++ b/includes/class-migration.php
@@ -139,6 +139,9 @@ public static function maybe_migrate() {
if ( \version_compare( $version_from_db, '4.0.0', '<' ) ) {
self::migrate_to_4_0_0();
}
+ if ( \version_compare( $version_from_db, '4.1.0', '<' ) ) {
+ self::migrate_to_4_1_0();
+ }
/**
* Fires when the system has to be migrated.
@@ -321,6 +324,39 @@ private static function migrate_to_4_0_0() {
self::migrate_actor_mode();
}
+ /**
+ * Upate to 4.1.0
+ *
+ * * Migrate the `activitypub_post_content_type` to only use `activitypub_custom_post_content`.
+ */
+ public static function migrate_to_4_1_0() {
+ $content_type = \get_option( 'activitypub_post_content_type' );
+
+ switch ( $content_type ) {
+ case 'excerpt':
+ $template = "[ap_excerpt]\n\n[ap_permalink type=\"html\"]";
+ break;
+ case 'title':
+ $template = "[ap_title type=\"html\"]\n\n[ap_permalink type=\"html\"]";
+ break;
+ case 'content':
+ $template = "[ap_content]\n\n[ap_permalink type=\"html\"]\n\n[ap_hashtags]";
+ break;
+ default:
+ $template = ACTIVITYPUB_CUSTOM_POST_CONTENT;
+ break;
+ }
+
+ \update_option( 'activitypub_custom_post_content', $template );
+
+ \delete_option( 'activitypub_post_content_type' );
+
+ $object_type = \get_option( 'activitypub_object_type', false );
+ if ( ! $object_type ) {
+ \update_option( 'activitypub_object_type', 'note' );
+ }
+ }
+
/**
* Set the defaults needed for the plugin to work.
*
diff --git a/includes/class-shortcodes.php b/includes/class-shortcodes.php
index eb9c5135b..91884a874 100644
--- a/includes/class-shortcodes.php
+++ b/includes/class-shortcodes.php
@@ -67,16 +67,36 @@ public static function hashtags() {
/**
* Generates output for the 'ap_title' Shortcode
*
+ * @param array $atts The Shortcode attributes.
+ * @param string $content The ActivityPub post-content.
+ * @param string $tag The tag/name of the Shortcode.
+ *
* @return string The post title.
*/
- public static function title() {
+ public static function title( $atts, $content, $tag ) {
$item = self::get_item();
if ( ! $item ) {
return '';
}
- return \wp_strip_all_tags( \get_the_title( $item->ID ), true );
+ $title = \wp_strip_all_tags( \get_the_title( $item->ID ), true );
+
+ if ( ! $title ) {
+ return '';
+ }
+
+ $atts = shortcode_atts(
+ array( 'type' => 'plain' ),
+ $atts,
+ $tag
+ );
+
+ if ( 'html' !== $atts['type'] ) {
+ return $title;
+ }
+
+ return sprintf( '%s
', $title );
}
/**
@@ -191,7 +211,7 @@ public static function permalink( $atts, $content, $tag ) {
$tag
);
- if ( 'url' === $atts['type'] ) {
+ if ( 'html' !== $atts['type'] ) {
return \esc_url( \get_permalink( $item->ID ) );
}
@@ -225,7 +245,7 @@ public static function shortlink( $atts, $content, $tag ) {
$tag
);
- if ( 'url' === $atts['type'] ) {
+ if ( 'html' !== $atts['type'] ) {
return \esc_url( \wp_get_shortlink( $item->ID ) );
}
diff --git a/includes/transformer/class-post.php b/includes/transformer/class-post.php
index d0ebaf779..60b829620 100644
--- a/includes/transformer/class-post.php
+++ b/includes/transformer/class-post.php
@@ -898,28 +898,19 @@ protected function get_content() {
* @return string The Template.
*/
protected function get_post_content_template() {
- $type = \get_option( 'activitypub_post_content_type', 'content' );
-
- switch ( $type ) {
- case 'excerpt':
- $template = "[ap_excerpt]\n\n[ap_permalink type=\"html\"]";
- break;
- case 'title':
- $template = "[ap_title]
\n\n[ap_permalink type=\"html\"]";
- break;
- case 'content':
- $template = "[ap_content]\n\n[ap_permalink type=\"html\"]\n\n[ap_hashtags]";
- break;
- default:
- $content = \get_option( 'activitypub_custom_post_content', ACTIVITYPUB_CUSTOM_POST_CONTENT );
- $template = empty( $content ) ? ACTIVITYPUB_CUSTOM_POST_CONTENT : $content;
- break;
- }
+ $content = \get_option( 'activitypub_custom_post_content', ACTIVITYPUB_CUSTOM_POST_CONTENT );
+ $template = $content ?? ACTIVITYPUB_CUSTOM_POST_CONTENT;
$post_format_setting = \get_option( 'activitypub_object_type', ACTIVITYPUB_DEFAULT_OBJECT_TYPE );
if ( 'wordpress-post-format' === $post_format_setting ) {
- $template = '[ap_content]';
+ $template = '';
+
+ if ( 'Note' === $this->get_type() ) {
+ $template .= "[ap_title type=\"html\"]\n\n";
+ }
+
+ $template .= '[ap_content]';
}
return apply_filters( 'activitypub_object_content_template', $template, $this->wp_object );
diff --git a/templates/settings.php b/templates/settings.php
index 2df41f288..c0bb90847 100644
--- a/templates/settings.php
+++ b/templates/settings.php
@@ -75,26 +75,25 @@
-
-
- />
-
+
+ />
+
-
-
+
-
|
>
@@ -103,46 +102,6 @@
-
-
- />
-
- -
-
-
-
-
-
-
-
- />
-
- -
-
-
-
-
-
-
-
- />
-
- -
-
-
-
-
-
-
-
- />
-
- -
-
-
-
-
-
diff --git a/tests/test-class-activitypub-migrate.php b/tests/test-class-activitypub-migrate.php
index 01ead3270..389a41950 100644
--- a/tests/test-class-activitypub-migrate.php
+++ b/tests/test-class-activitypub-migrate.php
@@ -1,6 +1,12 @@
assertEquals( ACTIVITYPUB_ACTOR_MODE, \get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE ) );
}
+
+ public function test_migrate_to_4_1_0() {
+ $template = \get_option( 'activitypub_custom_post_content', ACTIVITYPUB_CUSTOM_POST_CONTENT );
+ $object_type = \get_option( 'activitypub_object_type', ACTIVITYPUB_DEFAULT_OBJECT_TYPE );
+
+ $this->assertEquals( ACTIVITYPUB_CUSTOM_POST_CONTENT, $template );
+ $this->assertEquals( ACTIVITYPUB_DEFAULT_OBJECT_TYPE, $object_type );
+
+ \update_option( 'activitypub_post_content_type', 'title' );
+
+ \Activitypub\Migration::migrate_to_4_1_0();
+
+ $template = \get_option( 'activitypub_custom_post_content' );
+ $content_type = \get_option( 'activitypub_post_content_type' );
+ $object_type = \get_option( 'activitypub_object_type' );
+
+ $this->assertEquals( "[ap_title type=\"html\"]\n\n[ap_permalink type=\"html\"]", $template );
+ $this->assertFalse( $content_type );
+ $this->assertEquals( 'note', $object_type );
+
+ \update_option( 'activitypub_post_content_type', 'content' );
+ \update_option( 'activitypub_custom_post_content', '[ap_content]' );
+
+ \Activitypub\Migration::migrate_to_4_1_0();
+
+ $template = \get_option( 'activitypub_custom_post_content' );
+ $content_type = \get_option( 'activitypub_post_content_type' );
+
+ $this->assertEquals( "[ap_content]\n\n[ap_permalink type=\"html\"]\n\n[ap_hashtags]", $template );
+ $this->assertFalse( $content_type );
+ }
}
|