This commit is contained in:
Matthias Pfefferle 2019-03-02 21:10:42 +01:00
parent 2d8fb4f691
commit f10921e554
8 changed files with 103 additions and 55 deletions

View file

@ -55,6 +55,10 @@ To implement:
Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub). Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub).
### 0.5.2 ###
* add tags as hashtags to the end of each activity
### 0.5.1 ### ### 0.5.1 ###
* fixed name-collision that cases an invenate loop * fixed name-collision that cases an invenate loop

View file

@ -19,7 +19,7 @@ namespace Activitypub;
* Initialize plugin * Initialize plugin
*/ */
function init() { function init() {
defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(^|\s|>)#([^\s<>]+)\b' ); defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(^|\s|\/>)#([^\s<>]+)\b' );
require_once dirname( __FILE__ ) . '/includes/class-signature.php'; require_once dirname( __FILE__ ) . '/includes/class-signature.php';
require_once dirname( __FILE__ ) . '/includes/class-activity.php'; require_once dirname( __FILE__ ) . '/includes/class-activity.php';
@ -51,11 +51,9 @@ function init() {
require_once dirname( __FILE__ ) . '/includes/class-admin.php'; require_once dirname( __FILE__ ) . '/includes/class-admin.php';
\Activitypub\Admin::init(); \Activitypub\Admin::init();
if ( '1' === get_option( 'activitypub_use_hashtags', '1' ) ) {
require_once dirname( __FILE__ ) . '/includes/class-hashtag.php'; require_once dirname( __FILE__ ) . '/includes/class-hashtag.php';
\Activitypub\Hashtag::init(); \Activitypub\Hashtag::init();
} }
}
add_action( 'plugins_loaded', '\Activitypub\init' ); add_action( 'plugins_loaded', '\Activitypub\init' );
/** /**

View file

@ -76,7 +76,14 @@ class Admin {
register_setting( register_setting(
'activitypub', 'activitypub_use_hashtags', array( 'activitypub', 'activitypub_use_hashtags', array(
'type' => 'boolean', 'type' => 'boolean',
'description' => __( 'Use the Shortlink instead of the permalink', 'activitypub' ), 'description' => __( 'Add hashtags in the content as native tags and replace the #tag with the tag-link', 'activitypub' ),
'default' => 0,
)
);
register_setting(
'activitypub', 'activitypub_add_tags_as_hashtags', array(
'type' => 'boolean',
'description' => __( 'Add all tags as hashtags at the end of each activity', 'activitypub' ),
'default' => 0, 'default' => 0,
) )
); );

View file

@ -11,9 +11,15 @@ class Hashtag {
* Initialize the class, registering WordPress hooks * Initialize the class, registering WordPress hooks
*/ */
public static function init() { public static function init() {
if ( '1' === get_option( 'activitypub_use_hashtags', '1' ) ) {
add_filter( 'wp_insert_post', array( '\Activitypub\Hashtag', 'insert_post' ), 99, 2 ); add_filter( 'wp_insert_post', array( '\Activitypub\Hashtag', 'insert_post' ), 99, 2 );
add_filter( 'the_content', array( '\Activitypub\Hashtag', 'the_content' ), 99, 2 ); add_filter( 'the_content', array( '\Activitypub\Hashtag', 'the_content' ), 99, 2 );
} }
if ( '1' === get_option( 'activitypub_add_tags_as_hashtags', '1' ) ) {
add_filter( 'activitypub_the_summary', array( '\Activitypub\Hashtag', 'add_hashtags_to_content' ), 10, 2 );
add_filter( 'activitypub_the_content', array( '\Activitypub\Hashtag', 'add_hashtags_to_content' ), 10, 2 );
}
}
/** /**
* Filter to save #tags as real WordPress tags * Filter to save #tags as real WordPress tags
@ -60,4 +66,28 @@ class Hashtag {
return $space . '#' . $tag; return $space . '#' . $tag;
} }
/**
* Adds all tags as hashtags to the post/summary content
*
* @param string $content
* @param WP_Post $post
*
* @return string
*/
public static function add_hashtags_to_content( $content, $post ) {
$tags = get_the_tags( $post->ID );
if ( ! $tags ) {
return $content;
}
$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 );
}
return $content . '<p>' . implode( ' ', $hash_tags ) . '</p>';
}
} }

View file

@ -13,8 +13,8 @@ class Post {
* Initialize the class, registering WordPress hooks * Initialize the class, registering WordPress hooks
*/ */
public static function init() { public static function init() {
add_filter( 'activitypub_the_summary', array( '\Activitypub\Post', 'add_backlink' ), 10, 2 ); add_filter( 'activitypub_the_summary', array( '\Activitypub\Post', 'add_backlink_to_content' ), 15, 2 );
add_filter( 'activitypub_the_content', array( '\Activitypub\Post', 'add_backlink' ), 10, 2 ); add_filter( 'activitypub_the_content', array( '\Activitypub\Post', 'add_backlink_to_content' ), 15, 2 );
} }
public function __construct( $post = null ) { public function __construct( $post = null ) {
@ -299,7 +299,15 @@ class Post {
return trim( preg_replace( '/[\r\n]{2,}/', '', strip_tags( $decoded_summary, $allowed_html ) ) ); return trim( preg_replace( '/[\r\n]{2,}/', '', strip_tags( $decoded_summary, $allowed_html ) ) );
} }
public static function add_backlink( $content, $post ) { /**
* Adds a backlink to the post/summary content
*
* @param string $content
* @param WP_Post $post
*
* @return string
*/
public static function add_backlink_to_content( $content, $post ) {
$link = ''; $link = '';
if ( get_option( 'activitypub_use_shortlink', 0 ) ) { if ( get_option( 'activitypub_use_shortlink', 0 ) ) {

View file

@ -4,7 +4,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: ActivityPub 0.5.1\n" "Project-Id-Version: ActivityPub 0.5.1\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/activitypub\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/activitypub\n"
"POT-Creation-Date: 2019-03-02 19:31:03+00:00\n" "POT-Creation-Date: 2019-03-02 20:10:15+00:00\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n" "Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
@ -21,16 +21,25 @@ msgstr ""
msgid "The Activity-Object-Type" msgid "The Activity-Object-Type"
msgstr "" msgstr ""
#: includes/class-admin.php:72 includes/class-admin.php:79 #: includes/class-admin.php:72 templates/settings-page.php:33
#: templates/settings-page.php:33
msgid "Use the Shortlink instead of the permalink" msgid "Use the Shortlink instead of the permalink"
msgstr "" msgstr ""
#: includes/class-admin.php:89 #: includes/class-admin.php:79
msgid ""
"Add hashtags in the content as native tags and replace the #tag with the "
"tag-link"
msgstr ""
#: includes/class-admin.php:86
msgid "Add all tags as hashtags at the end of each activity"
msgstr ""
#: includes/class-admin.php:96
msgid "Overview" msgid "Overview"
msgstr "" msgstr ""
#: includes/class-admin.php:91 #: includes/class-admin.php:98
msgid "" msgid ""
"ActivityPub is a decentralized social networking protocol based on the " "ActivityPub is a decentralized social networking protocol based on the "
"ActivityStreams 2.0 data format. ActivityPub is an official W3C recommended " "ActivityStreams 2.0 data format. ActivityPub is an official W3C recommended "
@ -40,29 +49,29 @@ msgid ""
"subscribing to content." "subscribing to content."
msgstr "" msgstr ""
#: includes/class-admin.php:96 #: includes/class-admin.php:103
msgid "For more information:" msgid "For more information:"
msgstr "" msgstr ""
#: includes/class-admin.php:97 #: includes/class-admin.php:104
msgid "<a href=\"https://activitypub.rocks/\">Test Suite</a>" msgid "<a href=\"https://activitypub.rocks/\">Test Suite</a>"
msgstr "" msgstr ""
#: includes/class-admin.php:98 #: includes/class-admin.php:105
msgid "<a href=\"https://www.w3.org/TR/activitypub/\">W3C Spec</a>" msgid "<a href=\"https://www.w3.org/TR/activitypub/\">W3C Spec</a>"
msgstr "" msgstr ""
#: includes/class-admin.php:99 #: includes/class-admin.php:106
msgid "" msgid ""
"<a href=\"https://github.com/pfefferle/wordpress-activitypub/issues\">Give " "<a href=\"https://github.com/pfefferle/wordpress-activitypub/issues\">Give "
"us feedback</a>" "us feedback</a>"
msgstr "" msgstr ""
#: includes/class-admin.php:101 #: includes/class-admin.php:108
msgid "<a href=\"https://notiz.blog/donate\">Donate</a>" msgid "<a href=\"https://notiz.blog/donate\">Donate</a>"
msgstr "" msgstr ""
#: includes/class-admin.php:107 #: includes/class-admin.php:114
msgid "Fediverse" msgid "Fediverse"
msgstr "" msgstr ""
@ -125,7 +134,7 @@ msgstr ""
msgid "Blog" msgid "Blog"
msgstr "" msgstr ""
#: templates/json-author.php:59 templates/settings-page.php:79 #: templates/json-author.php:59 templates/settings-page.php:71
msgid "Profile" msgid "Profile"
msgstr "" msgstr ""
@ -206,45 +215,41 @@ msgstr ""
msgid "Maps the WordPress Post-Format to the ActivityPub Object Type." msgid "Maps the WordPress Post-Format to the ActivityPub Object Type."
msgstr "" msgstr ""
#: templates/settings-page.php:58 #: templates/settings-page.php:55
msgid "Hashtag" msgid "Hashtags"
msgstr "" msgstr ""
#: templates/settings-page.php:60 #: templates/settings-page.php:59
msgid "All #tag related settings"
msgstr ""
#: templates/settings-page.php:66
msgid "Support Hashtags"
msgstr ""
#: templates/settings-page.php:70
msgid "" msgid ""
"Add hashtags in the content as native tags and replace the " "Add hashtags in the content as native tags and replace the "
"<code>#tag</code> with the tag-link." "<code>#tag</code> with the tag-link."
msgstr "" msgstr ""
#: templates/settings-page.php:81 #: templates/settings-page.php:62
msgid "Add all tags as hashtags to the end of each activity."
msgstr ""
#: templates/settings-page.php:73
msgid "All profile related settings." msgid "All profile related settings."
msgstr "" msgstr ""
#: templates/settings-page.php:87 #: templates/settings-page.php:79
msgid "Followers" msgid "Followers"
msgstr "" msgstr ""
#: templates/settings-page.php:89 #: templates/settings-page.php:81
msgid "All follower related settings." msgid "All follower related settings."
msgstr "" msgstr ""
#: templates/settings-page.php:95 #: templates/settings-page.php:87
msgid "List of followers" msgid "List of followers"
msgstr "" msgstr ""
#: templates/settings-page.php:105 #: templates/settings-page.php:97
msgid "No followers yet" msgid "No followers yet"
msgstr "" msgstr ""
#: templates/settings-page.php:120 #: templates/settings-page.php:112
msgid "" msgid ""
"If you like this plugin, what about a small <a " "If you like this plugin, what about a small <a "
"href=\"https://notiz.blog/donate\">donation</a>?" "href=\"https://notiz.blog/donate\">donation</a>?"

View file

@ -55,6 +55,10 @@ To implement:
Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub). Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub).
= 0.5.2 =
* add tags as hashtags to the end of each activity
= 0.5.1 = = 0.5.1 =
* fixed name-collision that cases an invenate loop * fixed name-collision that cases an invenate loop

View file

@ -50,31 +50,23 @@
</p> </p>
</td> </td>
</tr> </tr>
</tbody>
</table>
<?php do_settings_fields( 'activitypub', 'activity' ); ?>
<h2><?php esc_html_e( 'Hashtag', 'activitypub' ); ?></h2>
<p><?php esc_html_e( 'All #tag related settings', 'activitypub' ); ?></p>
<table class="form-table">
<tbody>
<tr> <tr>
<th scope="row"> <th scope="row">
<label><?php esc_html_e( 'Support Hashtags', 'activitypub' ); ?></label> <?php esc_html_e( 'Hashtags', 'activitypub' ); ?>
</th> </th>
<td> <td>
<p> <p>
<label><input type="checkbox" name="activitypub_use_hashtags" id="activitypub_use_hashtags" value="1" <?php echo checked( '1', get_option( 'activitypub_use_hashtags', '1' ) ); ?> /> <?php _e( 'Add hashtags in the content as native tags and replace the <code>#tag</code> with the tag-link.', 'activitypub' ); ?></label> <label><input type="checkbox" name="activitypub_use_hashtags" id="activitypub_use_hashtags" value="1" <?php echo checked( '1', get_option( 'activitypub_use_hashtags', '1' ) ); ?> /> <?php _e( 'Add hashtags in the content as native tags and replace the <code>#tag</code> with the tag-link.', 'activitypub' ); ?></label>
</p> </p>
<p>
<label><input type="checkbox" name="activitypub_add_tags_as_hashtags" id="activitypub_add_tags_as_hashtags" value="1" <?php echo checked( '1', get_option( 'activitypub_add_tags_as_hashtags', '0' ) ); ?> /> <?php _e( 'Add all tags as hashtags to the end of each activity.', 'activitypub' ); ?></label>
</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<?php do_settings_fields( 'activitypub', 'hashtag' ); ?> <?php do_settings_fields( 'activitypub', 'activity' ); ?>
<h2><?php esc_html_e( 'Profile', 'activitypub' ); ?></h2> <h2><?php esc_html_e( 'Profile', 'activitypub' ); ?></h2>