mirror of
https://github.com/Automattic/wordpress-activitypub
synced 2024-10-18 12:23:32 +00:00
Merge branch 'trunk' into improve/actor-mode
This commit is contained in:
commit
e33eea667a
7 changed files with 81 additions and 15 deletions
4
.github/workflows/phpunit.yml
vendored
4
.github/workflows/phpunit.yml
vendored
|
@ -23,6 +23,10 @@ jobs:
|
|||
- wp-version: '6.5'
|
||||
php-versions: '7.1'
|
||||
steps:
|
||||
- name: Install svn
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install subversion
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
|
|
|
@ -33,11 +33,11 @@ class Hashtag {
|
|||
*/
|
||||
public static function filter_activity_object( $activity ) {
|
||||
/* phpcs:ignore Squiz.PHP.CommentedOutCode.Found
|
||||
Removed until this is merged: https://github.com/mastodon/mastodon/pull/28629
|
||||
if ( ! empty( $activity['summary'] ) ) {
|
||||
Only changed it for Person and Group as long is not merged: https://github.com/mastodon/mastodon/pull/28629
|
||||
*/
|
||||
if ( ! empty( $activity['summary'] ) && in_array( $activity['type'], array( 'Person', 'Group' ), true ) ) {
|
||||
$activity['summary'] = self::the_content( $activity['summary'] );
|
||||
}
|
||||
*/
|
||||
|
||||
if ( ! empty( $activity['content'] ) ) {
|
||||
$activity['content'] = self::the_content( $activity['content'] );
|
||||
|
|
|
@ -29,11 +29,11 @@ class Link {
|
|||
*/
|
||||
public static function filter_activity_object( $activity ) {
|
||||
/* phpcs:ignore Squiz.PHP.CommentedOutCode.Found
|
||||
Removed until this is merged: https://github.com/mastodon/mastodon/pull/28629
|
||||
if ( ! empty( $activity['summary'] ) ) {
|
||||
Only changed it for Person and Group as long is not merged: https://github.com/mastodon/mastodon/pull/28629
|
||||
*/
|
||||
if ( ! empty( $activity['summary'] ) && in_array( $activity['type'], array( 'Person', 'Group' ), true ) ) {
|
||||
$activity['summary'] = self::the_content( $activity['summary'] );
|
||||
}
|
||||
*/
|
||||
|
||||
if ( ! empty( $activity['content'] ) ) {
|
||||
$activity['content'] = self::the_content( $activity['content'] );
|
||||
|
|
|
@ -1135,16 +1135,44 @@ function normalize_host( $host ) {
|
|||
return \str_replace( 'www.', '', $host );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the reply intent URI as a JavaScript URI.
|
||||
*
|
||||
* @return string The reply intent URI.
|
||||
*/
|
||||
function get_reply_intent_js() {
|
||||
return sprintf(
|
||||
'javascript:(()=>{window.open(\'%s\'+encodeURIComponent(window.location.href));})();',
|
||||
get_reply_intent_url()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the reply intent URI.
|
||||
*
|
||||
* @return string The reply intent URI.
|
||||
*/
|
||||
function get_reply_intent_uri() {
|
||||
return sprintf(
|
||||
'javascript:(()=>{window.open(\'%s\'+encodeURIComponent(window.location.href));})();',
|
||||
esc_url( \admin_url( 'post-new.php?in_reply_to=' ) )
|
||||
);
|
||||
function get_reply_intent_url() {
|
||||
/**
|
||||
* Filters the reply intent parameters.
|
||||
*
|
||||
* @param array $params The reply intent parameters.
|
||||
*/
|
||||
$params = \apply_filters( 'activitypub_reply_intent_params', array() );
|
||||
|
||||
$params += array( 'in_reply_to' => '' );
|
||||
$query = \http_build_query( $params );
|
||||
$path = 'post-new.php?' . $query;
|
||||
$url = \admin_url( $path );
|
||||
|
||||
/**
|
||||
* Filters the reply intent URL.
|
||||
*
|
||||
* @param string $url The reply intent URL.
|
||||
*/
|
||||
$url = \apply_filters( 'activitypub_reply_intent_url', $url );
|
||||
|
||||
return esc_url_raw( $url );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
namespace Activitypub\Rest;
|
||||
|
||||
use WP_Error;
|
||||
use WP_REST_Server;
|
||||
use WP_REST_Response;
|
||||
use Activitypub\Signature;
|
||||
use Activitypub\Model\Application;
|
||||
|
@ -28,6 +29,7 @@ class Server {
|
|||
|
||||
\add_filter( 'rest_request_before_callbacks', array( self::class, 'validate_activitypub_requests' ), 9, 3 );
|
||||
\add_filter( 'rest_request_before_callbacks', array( self::class, 'authorize_activitypub_requests' ), 10, 3 );
|
||||
\add_filter( 'rest_request_parameter_order', array( self::class, 'request_parameter_order' ), 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -181,4 +183,32 @@ class Server {
|
|||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the parameter priority order for a REST API request.
|
||||
*
|
||||
* @param string[] $order Array of types to check, in order of priority.
|
||||
* @param WP_REST_Request $request The request object.
|
||||
*
|
||||
* @return string[] The modified order of types to check.
|
||||
*/
|
||||
public static function request_parameter_order( $order, $request ) {
|
||||
$route = $request->get_route();
|
||||
|
||||
// Check if it is an activitypub request and exclude webfinger and nodeinfo endpoints.
|
||||
if ( ! \str_starts_with( $route, '/' . ACTIVITYPUB_REST_NAMESPACE ) ) {
|
||||
return $order;
|
||||
}
|
||||
|
||||
$type = $request->get_method();
|
||||
|
||||
if ( WP_REST_Server::CREATABLE !== $type ) {
|
||||
return $order;
|
||||
}
|
||||
|
||||
return array(
|
||||
'POST',
|
||||
'defaults',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<h3><?php esc_html_e( 'Install Bookmarklet', 'activitypub' ); ?></h3>
|
||||
<p><?php esc_html_e( 'Drag and drop this button to your browser’s bookmark bar or save this bookmarklet to reply to posts on other websites from your blog! When visiting a post on another site, click the bookmarklet to start a reply.', 'activitypub' ); ?></p>
|
||||
<p class="activitypub-bookmarklet-wrapper">
|
||||
<a class="activitypub-bookmarklet button" onclick="return false;" href="<?php echo esc_url( \Activitypub\get_reply_intent_uri() ); ?>" style="cursor: grab;">
|
||||
<a class="activitypub-bookmarklet button" onclick="return false;" href="<?php echo esc_attr( \Activitypub\get_reply_intent_js() ); ?>" style="cursor: grab;">
|
||||
<?php // translators: The host (domain) of the Blog. ?>
|
||||
<?php printf( esc_html__( 'Reply from %s', 'activitypub' ), esc_attr( \wp_parse_url( \home_url(), PHP_URL_HOST ) ) ); ?>
|
||||
</a>
|
||||
|
@ -26,7 +26,7 @@
|
|||
<?php esc_html_e( 'Or copy the following code and create a new bookmark. Paste the code into the new bookmark’s URL field.', 'activitypub' ); ?>
|
||||
</p>
|
||||
<p>
|
||||
<textarea id="activitypub-bookmarklet-code" class="large-text activitypub-code" rows="5" readonly="readonly" aria-labelledby="activitypub-code-desc"><?php echo esc_textarea( \Activitypub\get_reply_intent_uri() ); ?></textarea>
|
||||
<textarea id="activitypub-bookmarklet-code" class="large-text activitypub-code" rows="5" readonly="readonly" aria-labelledby="activitypub-code-desc"><?php echo esc_textarea( \Activitypub\get_reply_intent_js() ); ?></textarea>
|
||||
</p>
|
||||
<p><span class="dashicons dashicons-clipboard"></span> <a href="javascript:;" class="copy-activitypub-bookmarklet-code" style="cursor: copy;"><?php esc_html_e( 'Copy to clipboard', 'activitypub' ); ?></a></p>
|
||||
</div>
|
||||
|
@ -68,6 +68,10 @@
|
|||
<td>in_reply_to</td>
|
||||
<td><?php esc_html_e( 'The URL of the content you want to reply to.', 'activitypub' ); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>post_type</td>
|
||||
<td><?php esc_html_e( 'The Post-Type you want to use for replies.', 'activitypub' ); ?></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p><?php esc_html_e( 'There might be more query parameters in the future.', 'activitypub' ); ?></p>
|
||||
|
|
|
@ -27,13 +27,13 @@
|
|||
|
||||
<p>
|
||||
<?php
|
||||
$bookmarklet_url = \Activitypub\get_reply_intent_uri();
|
||||
$bookmarklet_js = \Activitypub\get_reply_intent_js();
|
||||
|
||||
/* translators: %s is the domain of this site */
|
||||
$reply_from_template = __( 'Reply from %s', 'activitypub' );
|
||||
$button = sprintf(
|
||||
'<a href="%s" class="button">%s</a>',
|
||||
esc_url( $bookmarklet_url ), // Need to escape quotes for the bookmarklet.
|
||||
esc_attr( $bookmarklet_js ), // Need to escape quotes for the bookmarklet.
|
||||
sprintf( $reply_from_template, \wp_parse_url( \home_url(), PHP_URL_HOST ) )
|
||||
);
|
||||
/* translators: %s is where the button HTML will be rendered. */
|
||||
|
|
Loading…
Reference in a new issue