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).
### 0.5.2 ###
* add tags as hashtags to the end of each activity
### 0.5.1 ###
* fixed name-collision that cases an invenate loop

View file

@ -19,7 +19,7 @@ namespace Activitypub;
* Initialize plugin
*/
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-activity.php';
@ -51,10 +51,8 @@ function init() {
require_once dirname( __FILE__ ) . '/includes/class-admin.php';
\Activitypub\Admin::init();
if ( '1' === get_option( 'activitypub_use_hashtags', '1' ) ) {
require_once dirname( __FILE__ ) . '/includes/class-hashtag.php';
\Activitypub\Hashtag::init();
}
require_once dirname( __FILE__ ) . '/includes/class-hashtag.php';
\Activitypub\Hashtag::init();
}
add_action( 'plugins_loaded', '\Activitypub\init' );

View file

@ -76,7 +76,14 @@ class Admin {
register_setting(
'activitypub', 'activitypub_use_hashtags', array(
'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,
)
);

View file

@ -11,8 +11,14 @@ class Hashtag {
* Initialize the class, registering WordPress hooks
*/
public static function init() {
add_filter( 'wp_insert_post', array( '\Activitypub\Hashtag', 'insert_post' ), 99, 2 );
add_filter( 'the_content', array( '\Activitypub\Hashtag', 'the_content' ), 99, 2 );
if ( '1' === get_option( 'activitypub_use_hashtags', '1' ) ) {
add_filter( 'wp_insert_post', array( '\Activitypub\Hashtag', 'insert_post' ), 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 );
}
}
/**
@ -60,4 +66,28 @@ class Hashtag {
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
*/
public static function init() {
add_filter( 'activitypub_the_summary', array( '\Activitypub\Post', 'add_backlink' ), 10, 2 );
add_filter( 'activitypub_the_content', 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_to_content' ), 15, 2 );
}
public function __construct( $post = null ) {
@ -126,7 +126,7 @@ class Post {
$post_tags = get_the_tags( $this->post->ID );
if ( $post_tags ) {
foreach( $post_tags as $post_tag ) {
foreach ( $post_tags as $post_tag ) {
$tag = array(
'type' => 'Hashtag',
'href' => get_tag_link( $post_tag->term_id ),
@ -299,7 +299,15 @@ class Post {
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 = '';
if ( get_option( 'activitypub_use_shortlink', 0 ) ) {

View file

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

View file

@ -50,31 +50,23 @@
</p>
</td>
</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>
<th scope="row">
<label><?php esc_html_e( 'Support Hashtags', 'activitypub' ); ?></label>
<?php esc_html_e( 'Hashtags', 'activitypub' ); ?>
</th>
<td>
<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>
</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>
</tr>
</tbody>
</table>
<?php do_settings_fields( 'activitypub', 'hashtag' ); ?>
<?php do_settings_fields( 'activitypub', 'activity' ); ?>
<h2><?php esc_html_e( 'Profile', 'activitypub' ); ?></h2>
@ -97,7 +89,7 @@
<td>
<?php if ( \Activitypub\Db\Followers::get_followers( get_current_user_id() ) ) { ?>
<ul>
<?php foreach( \Activitypub\Db\Followers::get_followers( get_current_user_id() ) as $follower ) { ?>
<?php foreach ( \Activitypub\Db\Followers::get_followers( get_current_user_id() ) as $follower ) { ?>
<li><?php echo esc_attr( $follower ); ?></li>
<?php } ?>
</ul>