Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an early return filter for get_upload_dir() #1008

Merged
merged 12 commits into from
Nov 22, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* A `pre_activitypub_get_upload_baseurl` filter
* Fediverse Preview on post-overview page
* GitHub action to enforce Changelog updates.

Expand Down
153 changes: 153 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,159 @@ Enter the fediverse with **ActivityPub**, broadcasting your blog to a wider audi
You can test out the plugin (settings) with [WordPress Playground](https://wordpress.org/plugins/activitypub/?preview=1).

> [!NOTE]
> It may take up to 15 minutes or so for the new post to show up in your federated feed. This is because the messages are sent to the federated platforms using a delayed cron. This avoids breaking the publishing process for those cases where users might have lots of followers. So please don’t assume that just because you didn’t see it show up right away that something is broken. Give it some time. In most cases, it will show up within a few minutes, and you’ll know everything is working as expected.

## Frequently Asked Questions ##

### tl;dr ###

This plugin connects your WordPress blog to popular social platforms like Mastodon, making your posts more accessible to a wider audience. Once installed, your blog can be followed by users on these platforms, allowing them to receive your new posts in their feeds.

### What is the status of this plugin? ###

Implemented:

* blog profile pages (JSON representation)
* author profile pages (JSON representation)
* custom links
* functional inbox/outbox
* follow (accept follows)
* share posts
* receive comments/reactions
* signature verification
* threaded comments support

To implement:

* replace shortcodes with blocks for layout

### What is "ActivityPub for WordPress" ###

*ActivityPub for WordPress* extends WordPress with some Fediverse features, but it does not compete with platforms like Friendica or Mastodon. If you want to run a **decentralized social network**, please use [Mastodon](https://joinmastodon.org/) or [GNU social](https://gnusocial.network/).

### What if you are running your blog in a subdirectory? ###

In order for webfinger to work, it must be mapped to the root directory of the URL on which your blog resides.

**Apache**

Add the following to the .htaccess file in the root directory:

RedirectMatch "^\/\.well-known/(webfinger|nodeinfo|x-nodeinfo2)(.*)$" /blog/.well-known/$1$2

Where 'blog' is the path to the subdirectory at which your blog resides.

**Nginx**

Add the following to the site.conf in sites-available:

location ~* /.well-known {
allow all;
try_files $uri $uri/ /blog/?$args;
}

Where 'blog' is the path to the subdirectory at which your blog resides.

### What if you are running your blog in a subdirectory? ###

If you are running your blog in a subdirectory, but have a different [wp_siteurl](https://wordpress.org/documentation/article/giving-wordpress-its-own-directory/), you don't need the redirect, because the index.php will take care of that.

### What if you are running your blog behind a reverse proxy with Apache? ###

If you are using a reverse proxy with Apache to run your host you may encounter that you are unable to have followers join the blog. This will occur because the proxy system rewrites the host headers to be the internal DNS name of your server, which the plugin then uses to attempt to sign the replies. The remote site attempting to follow your users is expecting the public DNS name on the replies. In these cases you will need to use the 'ProxyPreserveHost On' directive to ensure the external host name is passed to your internal host.

If you are using SSL between the proxy and internal host you may also need to `SSLProxyCheckPeerName off` if your internal host can not answer with the correct SSL name. This may present a security issue in some environments.

### Constants ###

The plugin uses PHP Constants to enable, disable or change its default behaviour. Please use them with caution and only if you know what you are doing.

* `ACTIVITYPUB_REST_NAMESPACE` - Change the default Namespace of the REST endpoint. Default: `activitypub/1.0`.
* `ACTIVITYPUB_EXCERPT_LENGTH` - Change the length of the Excerpt. Default: `400`.
* `ACTIVITYPUB_SHOW_PLUGIN_RECOMMENDATIONS` - show plugin recommendations in the ActivityPub settings. Default: `true`.
* `ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS` - Change the number of attachments, that should be federated. Default: `3`.
* `ACTIVITYPUB_HASHTAGS_REGEXP` - Change the default regex to detect hashtext in a text. Default: `(?:(?<=\s)|(?<=<p>)|(?<=<br>)|^)#([A-Za-z0-9_]+)(?:(?=\s|[[:punct:]]|$))`.
* `ACTIVITYPUB_USERNAME_REGEXP` - Change the default regex to detect @-replies in a text. Default: `(?:([A-Za-z0-9\._-]+)@((?:[A-Za-z0-9_-]+\.)+[A-Za-z]+))`.
* `ACTIVITYPUB_URL_REGEXP` - Change the default regex to detect urls in a text. Default: `(www.|http:|https:)+[^\s]+[\w\/]`.
* `ACTIVITYPUB_CUSTOM_POST_CONTENT` - Change the default template for Activities. Default: `<strong>[ap_title]</strong>\n\n[ap_content]\n\n[ap_hashtags]\n\n[ap_shortlink]`.
* `ACTIVITYPUB_AUTHORIZED_FETCH` - Enable AUTHORIZED_FETCH. Default: `false`.
* `ACTIVITYPUB_DISABLE_REWRITES` - Disable auto generation of `mod_rewrite` rules. Default: `false`.
* `ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS` - Block incoming replies/comments/likes. Default: `false`.
* `ACTIVITYPUB_DISABLE_OUTGOING_INTERACTIONS` - Disable outgoing replies/comments/likes. Default: `false`.
* `ACTIVITYPUB_SHARED_INBOX_FEATURE` - Enable the shared inbox. Default: `false`.
* `ACTIVITYPUB_SEND_VARY_HEADER` - Enable to send the `Vary: Accept` header. Default: `false`.

### Where can you manage your followers? ###

If you have activated the blog user, you will find the list of his followers in the settings under `/wp-admin/options-general.php?page=activitypub&tab=followers`.

The followers of a user can be found in the menu under "Users" -> "Followers" or under `wp-admin/users.php?page=activitypub-followers-list`.

For reasons of data protection, it is not possible to see the followers of other users.

## Screenshots ##

1. The "Follow me"-Block in the Block-Editor
2. The "Followers"-Block in the Block-Editor
3. The "Federated Reply"-Block in the Block-Editor
4. A "Federated Reply" in a Post
5. A Blog-Profile on Mastodon

## Changelog ##

### Dev ###

* Added: A `pre_activitypub_get_upload_baseurl` filter
* Added: GitHub action to enforce Changelog updates.
* Improved: Outsource Constants to a separate file

### 4.2.1 ###

* Added: Mastodon Apps status provider
* Improved: Image-Handling
* Improved: Have better checks if audience should be set or not
* Fixed: Don't overwrite an existing `wp-tests-config.php`
* Fixed: PHPCS for phpunit files

### 4.2.0 ###

* Added: Unit tests for the `ActivityPub\Transformer\Post` class
* Improved: Reuse constants once they're defined
* Improved: "FEP-b2b8: Long-form Text" support
* Improved: Admin notice for plain permalink settings is more user-friendly and actionable
* Improved: Post-Formats support
* Fixed: Do not display ActivityPub's user sub-menus to users who do not have the capabilities of writing posts.
* Fixed: Proper margins for notices and font size for page title in settings screen.
* Fixed: Ensure that `?author=0` resolves to blog user

### 4.1.1 ###

* Fixed: Only revert to URL if there is one
* Fixed: Migration

### 4.1.0 ###

* Added: Add custom Preview for "Fediverse"
* Added: Support `comment_previously_approved` setting
* Fixed: Hide sticky posts that are not public
* Improved: `activity_handle_undo` action
* Improved: Add title to content if post is a `Note`
* Improved: Fallback to blog-user if user is disabled

### 4.0.2 ###

* Fixed: Do not federate "Local" posts
* Improved: Help-text for Content-Warning box

### 4.0.1 ###

* Fixed: Missing URL-Param handling in REST API
* Fixed: Seriously Simple Podcasting integration
* Fixed: Multiple small fixes
* Improved: Provide contextual fallback for dynamic blocks

### 4.0.0 ###
=======
> [WordPress Playground](https://wordpress.org/playground/) is the platform that lets you run WordPress instantly on any device without a host. It’s your place to build, experiment, test, and grow.

## Documentation
Expand Down
4 changes: 2 additions & 2 deletions activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.2.1
* Version: 4.2.2
* Author: Matthias Pfefferle & Automattic
* Author URI: https://automattic.com/
* License: MIT
Expand All @@ -19,7 +19,7 @@

use WP_CLI;

\define( 'ACTIVITYPUB_PLUGIN_VERSION', '4.2.1' );
\define( 'ACTIVITYPUB_PLUGIN_VERSION', '4.2.2' );

// Plugin related constants.
\define( 'ACTIVITYPUB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
Expand Down
10 changes: 10 additions & 0 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,16 @@ function get_attribution_domains() {
* @return string The upload base URL.
*/
function get_upload_baseurl() {
/**
* Early filter to allow plugins to set the upload base URL.
*
* @param string|false $maybe_upload_dir The upload base URL or false if not set.
*/
$maybe_upload_dir = apply_filters( 'pre_activitypub_get_upload_baseurl', false );
pfefferle marked this conversation as resolved.
Show resolved Hide resolved
if ( false !== $maybe_upload_dir ) {
return $maybe_upload_dir;
}

$upload_dir = \wp_get_upload_dir();

/**
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ For reasons of data protection, it is not possible to see the followers of other

= Dev =

* Added: A `pre_activitypub_get_upload_baseurl` filter
* Added: Fediverse Preview on post-overview page
* Added: GitHub action to enforce Changelog updates.
* Improved: Outsource Constants to a separate file
Expand Down
Loading