nicer profile and customizable backlink
* customizable backlink URL #18 * fixes #12
This commit is contained in:
parent
b9e90829af
commit
e8d2508f5d
5 changed files with 85 additions and 31 deletions
|
@ -64,6 +64,7 @@ function activitypub_init() {
|
|||
require_once dirname( __FILE__ ) . '/includes/class-activitypub-admin.php';
|
||||
add_action( 'admin_menu', array( 'Activitypub_Admin', 'admin_menu' ) );
|
||||
add_action( 'admin_init', array( 'Activitypub_Admin', 'register_settings' ) );
|
||||
add_action( 'show_user_profile', array( 'Activitypub_Admin', 'add_fediverse_profile' ) );
|
||||
}
|
||||
add_action( 'plugins_loaded', 'activitypub_init' );
|
||||
|
||||
|
|
|
@ -31,26 +31,33 @@ class Activitypub_Admin {
|
|||
public static function register_settings() {
|
||||
register_setting(
|
||||
'activitypub', 'activitypub_post_content_type', array(
|
||||
'type' => 'string',
|
||||
'description' => __( 'Use summary or full content', 'activitypub' ),
|
||||
'type' => 'string',
|
||||
'description' => __( 'Use summary or full content', 'activitypub' ),
|
||||
'show_in_rest' => array(
|
||||
'schema' => array(
|
||||
'enum' => array( 'excerpt', 'content' )
|
||||
'enum' => array( 'excerpt', 'content' ),
|
||||
),
|
||||
),
|
||||
'default' => 0,
|
||||
'default' => 'excerpt',
|
||||
)
|
||||
);
|
||||
register_setting(
|
||||
'activitypub', 'activitypub_object_type', array(
|
||||
'type' => 'string',
|
||||
'description' => __( 'The Activity-Object-Type', 'activitypub' ),
|
||||
'type' => 'string',
|
||||
'description' => __( 'The Activity-Object-Type', 'activitypub' ),
|
||||
'show_in_rest' => array(
|
||||
'schema' => array(
|
||||
'enum' => array( 'note', 'article', 'wordpress-post-format' )
|
||||
'enum' => array( 'note', 'article', 'wordpress-post-format' ),
|
||||
),
|
||||
),
|
||||
'default' => 'note',
|
||||
'default' => 'note',
|
||||
)
|
||||
);
|
||||
register_setting(
|
||||
'activitypub', 'activitypub_use_shortlink', array(
|
||||
'type' => 'boolean',
|
||||
'description' => __( 'Use the Shortlink instead of the permalink', 'activitypub' ),
|
||||
'default' => 0,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -74,4 +81,11 @@ class Activitypub_Admin {
|
|||
'<p>' . __( '<a href="https://notiz.blog/donate">Donate</a>', 'activitypub' ) . '</p>'
|
||||
);
|
||||
}
|
||||
|
||||
public static function add_fediverse_profile( $user ) {
|
||||
?>
|
||||
<h2><?php esc_html_e( 'Fediverse', 'activitypub' ); ?></h2>
|
||||
<?php
|
||||
activitypub_get_identifier_settings( $user->ID );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ class Activitypub_Post {
|
|||
'type' => $this->get_object_type(),
|
||||
'published' => date( 'Y-m-d\TH:i:s\Z', strtotime( $post->post_date ) ),
|
||||
'attributedTo' => get_author_posts_url( $post->post_author ),
|
||||
'summary' => null,
|
||||
'summary' => ( $this->get_object_type() == 'Article' ) ? $this->get_the_post_excerpt( 400, false ) : null,
|
||||
'inReplyTo' => null,
|
||||
'content' => $this->get_the_content(),
|
||||
'contentMap' => array(
|
||||
|
@ -209,7 +209,7 @@ class Activitypub_Post {
|
|||
*
|
||||
* @return string The excerpt.
|
||||
*/
|
||||
public function get_the_post_excerpt( $excerpt_length = 400 ) {
|
||||
public function get_the_post_excerpt( $excerpt_length = 400, $with_link = true ) {
|
||||
$post = $this->post;
|
||||
|
||||
$excerpt = get_post_field( 'post_excerpt', $post );
|
||||
|
@ -238,11 +238,21 @@ class Activitypub_Post {
|
|||
|
||||
$filtered_excerpt = apply_filters( 'the_excerpt', $excerpt );
|
||||
|
||||
$excerpt = $filtered_excerpt . "\n\n" . '<a rel="shortlink" href="' . esc_url( wp_get_shortlink( $this->post->ID ) ) . '">' . wp_get_shortlink( $this->post->ID ) . '</a>';
|
||||
if ( $with_link ) {
|
||||
$link = '';
|
||||
|
||||
if ( get_option( 'activitypub_use_shortlink', 0 ) ) {
|
||||
$link = esc_url( wp_get_shortlink( $this->post->ID ) );
|
||||
} else {
|
||||
$link = esc_url( get_permalink( $this->post->ID ) );
|
||||
}
|
||||
|
||||
$filtered_excerpt = $filtered_excerpt . "\n\n" . '<a href="' . $link . '">' . $link . '</a>';
|
||||
}
|
||||
|
||||
$allowed_html = apply_filters( 'activitypub_allowed_html', '<a>' );
|
||||
|
||||
return trim( preg_replace( '/[\r\n]{2,}/', "\n\n", strip_tags( $excerpt, $allowed_html ) ) );
|
||||
return trim( preg_replace( '/[\r\n]{2,}/', "\n\n", strip_tags( $filtered_excerpt, $allowed_html ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -250,13 +260,25 @@ class Activitypub_Post {
|
|||
*
|
||||
* @return string The content.
|
||||
*/
|
||||
public function get_the_post_content() {
|
||||
public function get_the_post_content( $with_link = true ) {
|
||||
$post = $this->post;
|
||||
|
||||
$content = get_post_field( 'post_content', $post );
|
||||
|
||||
$filtered_content = apply_filters( 'the_content', $content );
|
||||
|
||||
if ( $with_link ) {
|
||||
$link = '';
|
||||
|
||||
if ( get_option( 'activitypub_use_shortlink', 0 ) ) {
|
||||
$link = esc_url( wp_get_shortlink( $this->post->ID ) );
|
||||
} else {
|
||||
$link = esc_url( get_permalink( $this->post->ID ) );
|
||||
}
|
||||
|
||||
$filtered_content = $filtered_content . "\n\n" . '<a href="' . $link . '">' . $link . '</a>';
|
||||
}
|
||||
|
||||
$allowed_html = apply_filters( 'activitypub_allowed_html', '<a>' );
|
||||
|
||||
return trim( preg_replace( '/[\r\n]{2,}/', "\n\n", strip_tags( $filtered_content, $allowed_html ) ) );
|
||||
|
|
|
@ -183,3 +183,21 @@ function activitypub_get_follower_inboxes( $user_id, $followers ) {
|
|||
|
||||
return array_unique( $inboxes );
|
||||
}
|
||||
|
||||
function activitypub_get_identifier_settings( $user_id ) {
|
||||
?>
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label><?php esc_html_e( 'Profile identifier', 'activitypub' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<p><code><?php echo activitypub_get_webfinger_resource( $user_id ); ?></code> or <code><?php echo get_author_posts_url( $user_id ); ?></code></p>
|
||||
<p class="description"><?php printf( __( 'Try to follow "@%s" in the mastodon/friendi.ca search field.', 'activitypub' ), activitypub_get_webfinger_resource( $user_id ) ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php
|
||||
}
|
||||
|
|
|
@ -18,10 +18,21 @@
|
|||
</th>
|
||||
<td>
|
||||
<p>
|
||||
<label><input type="radio" name="activitypub_post_content_type" id="activitypub_post_content_type_excerpt" value="excerpt" <?php echo checked( 'excerpt', get_option( 'activitypub_post_content_type', 'excerpt' ) ); ?> /> <?php esc_html_e( 'Excerpt (default)', 'activitypub' ); ?> - <span class="description"><?php esc_html_e( 'A content summary, shortened to 400 characters and without markup.', 'activitypub' ); ?></span>
|
||||
<label><input type="radio" name="activitypub_post_content_type" id="activitypub_post_content_type_excerpt" value="excerpt" <?php echo checked( 'excerpt', get_option( 'activitypub_post_content_type', 'excerpt' ) ); ?> /> <?php esc_html_e( 'Excerpt (default)', 'activitypub' ); ?></label> - <span class="description"><?php esc_html_e( 'A content summary, shortened to 400 characters and without markup.', 'activitypub' ); ?></span>
|
||||
</p>
|
||||
<p>
|
||||
<label><input type="radio" name="activitypub_post_content_type" id="activitypub_post_content_type_content" value="content" <?php echo checked( 'content', get_option( 'activitypub_post_content_type', 'excerpt' ) ); ?> /> <?php esc_html_e( 'Content', 'activitypub' ); ?> - <span class="description"><?php esc_html_e( 'The full content.', 'activitypub' ); ?></span>
|
||||
<label><input type="radio" name="activitypub_post_content_type" id="activitypub_post_content_type_content" value="content" <?php echo checked( 'content', get_option( 'activitypub_post_content_type', 'excerpt' ) ); ?> /> <?php esc_html_e( 'Content', 'activitypub' ); ?></label> - <span class="description"><?php esc_html_e( 'The full content.', 'activitypub' ); ?></span>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<?php esc_html_e( 'Backlink', 'activitypub' ); ?>
|
||||
</th>
|
||||
<td>
|
||||
<p>
|
||||
<label><input type="checkbox" name="activitypub_use_shortlink" id="activitypub_use_shortlink" value="1" <?php echo checked( '1', get_option( 'activitypub_use_shortlink', '0' ) ); ?> /> <?php esc_html_e( 'Use the Shortlink instead of the permalink', 'activitypub' ); ?></label>
|
||||
<p class="description"><?php printf( esc_html( 'I can recommend %sHum%s, to prettify the Shortlinks', 'activitypub' ), '<a href="https://wordpress.org/plugins/hum/" target="_blank">', '</a>' ); ?></p>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -31,13 +42,13 @@
|
|||
</th>
|
||||
<td>
|
||||
<p>
|
||||
<label><input type="radio" name="activitypub_object_type" id="activitypub_object_type_note" value="note" <?php echo checked( 'note', get_option( 'activitypub_object_type', 'note' ) ); ?> /> <?php esc_html_e( 'Note (default)', 'activitypub' ); ?> - <span class="description"><?php esc_html_e( 'Should work with most plattforms.', 'activitypub' ); ?></span>
|
||||
<label><input type="radio" name="activitypub_object_type" id="activitypub_object_type_note" value="note" <?php echo checked( 'note', get_option( 'activitypub_object_type', 'note' ) ); ?> /> <?php esc_html_e( 'Note (default)', 'activitypub' ); ?></label> - <span class="description"><?php esc_html_e( 'Should work with most plattforms.', 'activitypub' ); ?></span>
|
||||
</p>
|
||||
<p>
|
||||
<label><input type="radio" name="activitypub_object_type" id="activitypub_object_type_article" value="article" <?php echo checked( 'article', get_option( 'activitypub_object_type', 'note' ) ); ?> /> <?php esc_html_e( 'Article', 'activitypub' ); ?> - <span class="description"><?php esc_html_e( 'The presentation of the "Article" might change on different plattforms. Mastodon for example shows the "Article" type as a simple link.', 'activitypub' ); ?></span>
|
||||
<label><input type="radio" name="activitypub_object_type" id="activitypub_object_type_article" value="article" <?php echo checked( 'article', get_option( 'activitypub_object_type', 'note' ) ); ?> /> <?php esc_html_e( 'Article', 'activitypub' ); ?></label> - <span class="description"><?php esc_html_e( 'The presentation of the "Article" might change on different plattforms. Mastodon for example shows the "Article" type as a simple link.', 'activitypub' ); ?></span>
|
||||
</p>
|
||||
<p>
|
||||
<label><input type="radio" name="activitypub_object_type" id="activitypub_object_type" value="wordpress-post-format" <?php echo checked( 'wordpress-post-format', get_option( 'activitypub_object_type', 'note' ) ); ?> /> <?php esc_html_e( 'WordPress Post-Format', 'activitypub' ); ?> - <span class="description"><?php esc_html_e( 'Maps the WordPress Post-Format to the ActivityPub Object Type.', 'activitypub' ); ?></span>
|
||||
<label><input type="radio" name="activitypub_object_type" id="activitypub_object_type" value="wordpress-post-format" <?php echo checked( 'wordpress-post-format', get_option( 'activitypub_object_type', 'note' ) ); ?> /> <?php esc_html_e( 'WordPress Post-Format', 'activitypub' ); ?></label> - <span class="description"><?php esc_html_e( 'Maps the WordPress Post-Format to the ActivityPub Object Type.', 'activitypub' ); ?></span>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -50,19 +61,7 @@
|
|||
|
||||
<p><?php esc_html_e( 'All profile related settings.', 'activitypub' ); ?></p>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label><?php esc_html_e( 'Profile identifier', 'activitypub' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<p><code><?php echo activitypub_get_webfinger_resource( get_current_user_id() ); ?></code> or <code><?php echo get_author_posts_url( get_current_user_id() ); ?></code></p>
|
||||
<p class="description"><?php printf( __( 'Try to follow "@%s" in the mastodon/friendi.ca search field.', 'activitypub' ), activitypub_get_webfinger_resource( get_current_user_id() ) ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php activitypub_get_identifier_settings( get_current_user_id() ); ?>
|
||||
|
||||
<?php do_settings_fields( 'activitypub', 'profile' ); ?>
|
||||
|
||||
|
|
Loading…
Reference in a new issue