diff --git a/.distignore b/.distignore index 782f2e88b..55d2ee93a 100644 --- a/.distignore +++ b/.distignore @@ -36,3 +36,4 @@ phpunit.xml.dist tests node_modules vendor +src diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 000000000..3c72a8601 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,90 @@ +name: Bug Report +description: Helps us improve our product! +labels: "Needs triage, [Type] Bug" +body: + - type: markdown + attributes: + value: | + ### Thanks for contributing! + + Please write a clear title, then fill in the fields below and submit. + + Please **do not** link to image hosting services such as Cloudup, Droplr, Imgur, etc… + Instead, directly embed screenshot(s) or recording(s) in any of the text areas below: click, then drag and drop. + - type: markdown + attributes: + value: | + --- + ## Core Information + - type: textarea + id: summary + attributes: + label: Quick summary + - type: textarea + id: steps + attributes: + label: Steps to reproduce + placeholder: | + 1. Start at `site-domain.com/blog`. + 2. Click on any blog post. + 3. ... + validations: + required: true + - type: textarea + id: expected + attributes: + label: What you expected to happen + placeholder: | + e.g. The post should appear. + validations: + required: true + - type: textarea + id: actual + attributes: + label: What actually happened + placeholder: | + e.g. The post did not appear. + validations: + required: true + - type: dropdown + id: users-affected + attributes: + label: Impact + description: Approximately how many users are impacted? + options: + - One + - Some (< 50%) + - Most (> 50%) + - All + validations: + required: true + - type: dropdown + id: workarounds + attributes: + label: Available workarounds? + options: + - No and the platform is unusable + - No but the platform is still usable + - Yes, difficult to implement + - Yes, easy to implement + - There is no user impact + validations: + required: true + + - type: markdown + attributes: + value: | +
+ + ## Optional Information + + The following section is optional. + - type: textarea + id: logs + attributes: + label: Logs or notes + placeholder: | + Add any information that may be relevant, such as: + - Browser/Platform + - Theme + - Logs/Errors diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 000000000..2fc3601d6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,34 @@ +name: Feature Request +description: Suggest an idea for the ActivityPub plugin! +title: "Feature Request:" +labels: ["[Type] Feature Request"] +body: + - type: markdown + attributes: + value: | + Please, be as descriptive as possible. Issues lacking detail, or for any other reason than to request a feature, may be closed without action. + + - type: textarea + id: what + attributes: + label: What + description: Add a concise description of the feature being requested. + placeholder: eg. I would like a new dropdown at ... + validations: + required: true + + - type: textarea + id: why + attributes: + label: Why + description: Add a description of the problem this feature solves. + placeholder: | + eg. This will solve my accessibility needs. + validations: + required: true + + - type: textarea + id: how + attributes: + label: How + description: If applicable, add screenshots, mockup, animations and/or videos to help illustrate how the feature could be done. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 000000000..49ff40e88 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,22 @@ + + +Fixes # + +## Proposed changes: + +* + +### Other information: + +- [ ] Have you written new tests for your changes, if applicable? + +## Testing instructions: + + + + + + +* Go to '..' +* + diff --git a/.github/workflows/gardening.yml b/.github/workflows/gardening.yml new file mode 100644 index 000000000..2055d66de --- /dev/null +++ b/.github/workflows/gardening.yml @@ -0,0 +1,50 @@ +# Repo gardening. Automate some of the triage tasks in the repo. +name: Repo Gardening + +on: + pull_request_target: # When a PR is opened, edited, updated, closed, or a label is added. + types: [opened, reopened, synchronize, edited, labeled, closed] + issues: # For auto-triage of issues. + types: [opened, labeled, reopened, edited, closed] + issue_comment: # To gather support references in issue comments. + types: [created] +concurrency: + # For pull_request_target, cancel any concurrent jobs with the same type (e.g. "opened", "labeled") and branch. + # Don't cancel any for other events, accomplished by grouping on the unique run_id. + group: gardening-${{ github.event_name }}-${{ github.event.action }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.ref || github.run_id }} + cancel-in-progress: true + +jobs: + repo-gardening: + name: 'Automated repo gardening.' + runs-on: ubuntu-latest + if: github.event_name == 'pull_request_target' || github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name + timeout-minutes: 10 + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: lts/* + + - name: Wait for prior instances of the workflow to finish + uses: softprops/turnstyle@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: 'Automate triage (add labels, clean labels, ...).' + uses: automattic/action-repo-gardening@trunk + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + slack_token: ${{ secrets.SLACK_TOKEN }} + slack_team_channel: ${{ secrets.SLACK_TEAM_CHANNEL }} + slack_he_triage_channel: ${{ secrets.SLACK_HE_TRIAGE_CHANNEL }} + slack_quality_channel: ${{ secrets.SLACK_QUALITY_CHANNEL }} + tasks: 'addLabels,cleanLabels,assignIssues,flagOss,gatherSupportReferences,replyToCustomersReminder' + add_labels: '[ + {"path": "src/followers", "label": "[Block] Followers"}, + {"path": "src/follow-me", "label": "[Block] Follow Me"} + ]' diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 4c70a1e80..9928decba 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -15,10 +15,15 @@ jobs: options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=10s --health-retries=10 strategy: matrix: - php-versions: ['5.6', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] + php-versions: ['5.6', '7.0', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] + include: + - wp-version: latest + - wp-version: '6.2' + php-versions: '5.6' steps: - name: Checkout uses: actions/checkout@v2 + - name: Setup PHP uses: shivammathur/setup-php@v2 with: @@ -26,10 +31,13 @@ jobs: coverage: none tools: composer, phpunit-polyfills extensions: mysql + - name: Install Composer dependencies for PHP uses: "ramsey/composer-install@v1" + - name: Setup Test Environment - run: bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1 latest + run: bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1 ${{ matrix.wp-version }} + - name: Unit Testing run: ./vendor/bin/phpunit env: diff --git a/.php_cs b/.php_cs deleted file mode 100644 index 7f81780c7..000000000 --- a/.php_cs +++ /dev/null @@ -1,15 +0,0 @@ -exclude('vendor') - ->exclude('node_modules') - ->exclude('bin') - ->in(__DIR__) -; - -return PhpCsFixer\Config::create() - ->setRules([ - 'native_function_invocation' => ['include' => ['@all']], - 'native_constant_invocation' => true, - ]) - ->setFinder($finder) -; diff --git a/README.md b/README.md index d1b4461bf..eef27a0bf 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # ActivityPub # -**Contributors:** [pfefferle](https://profiles.wordpress.org/pfefferle/), [mediaformat](https://profiles.wordpress.org/mediaformat/), [akirk](https://profiles.wordpress.org/akirk/), [automattic](https://profiles.wordpress.org/automattic/) +**Contributors:** [automattic](https://profiles.wordpress.org/automattic/), [pfefferle](https://profiles.wordpress.org/pfefferle/), [mediaformat](https://profiles.wordpress.org/mediaformat/), [mattwiebe](https://profiles.wordpress.org/mattwiebe/), [akirk](https://profiles.wordpress.org/akirk/), [jeherve](https://profiles.wordpress.org/jeherve/), [nuriapena](https://profiles.wordpress.org/nuriapena/), [cavalierlife](https://profiles.wordpress.org/cavalierlife/) **Tags:** OStatus, fediverse, activitypub, activitystream **Requires at least:** 4.7 -**Tested up to:** 6.1 -**Stable tag:** 0.17.0 +**Tested up to:** 6.3 +**Stable tag:** 1.0.1 **Requires PHP:** 5.6 **License:** MIT **License URI:** http://opensource.org/licenses/MIT @@ -12,38 +12,39 @@ The ActivityPub protocol is a decentralized social networking protocol based upo ## Description ## -This is BETA software, see the FAQ to see the current feature set or rather what is still planned. +Enter the fediverse with **ActivityPub**, broadcasting your blog to a wider audience! Attract followers, deliver updates, and receive comments from a diverse user base of **ActivityPub**\-compliant platforms. -The plugin implements the ActivityPub protocol for your blog, which means that your readers will be able to follow your blog posts on Mastodon and other federated platforms that support ActivityPub. In addition, replies to your posts on Mastodon and related platforms will automatically become comments on your blog post. +With the ActivityPub plugin installed, your WordPress blog itself function as a federated profile, along with profiles for each author. For instance, if your website is `example.com`, then the blog-wide profile can be found at `@example.com@example.com`, and authors like Jane and Bob would have their individual profiles at `@jane@example.com` and `@bobz@example.com`, respectively. + +An example: I give you my Mastodon profile name: `@pfefferle@mastodon.social`. You search, see my profile, and hit follow. Now, any post I make appears in your Home feed. Similarly, with the ActivityPub plugin, you can find and follow Jane's profile at `@jane@example.com`. + +Once you follow Jane's `@jane@example.com` profile, any blog post she crafts on `example.com` will land in your Home feed. Simultaneously, by following the blog-wide profile `@example.com@example.com`, you'll receive updates from all authors. + +**Note**: if no one follows your author or blog instance, your posts remain unseen. The simplest method to verify the plugin's operation is by following your profile. If you possess a Mastodon profile, initiate by following your new one. The plugin works with the following tested federated platforms, but there may be more that it works with as well: * [Mastodon](https://joinmastodon.org/) -* [Pleroma](https://pleroma.social/) -* [Friendica](https://friendi.ca/) -* [HubZilla](https://hubzilla.org/) +* [Pleroma](https://pleroma.social/)/[Akkoma](https://akkoma.social/) +* [friendica](https://friendi.ca/) +* [Hubzilla](https://hubzilla.org/) * [Pixelfed](https://pixelfed.org/) -* [SocialHome](https://socialhome.network/) +* [Socialhome](https://socialhome.network/) * [Misskey](https://join.misskey.page/) - -Here’s what that means and what you can expect. - -Once the ActivityPub plugin is installed, each author’s page on your WordPress blog will become its own federated instance. In other words, if you have two authors, Jane and Bob, on your website, `example.com`, then your authors would have their own author pages at `example.com/author/jane` and `example.com/author/bob`. Each of those author pages would now be available to Mastodon users (and all other federated platform users) as a profile that can be followed. Let’s break that down further. Let’s say you have a friend on Mastodon who tells you to follow them and they give you their profile name `@janelivesheresomeofthetime@mastodon.social`. You search for her name, see her profile, and click the follow button, right? From then on, everything Jane posts on her profile shows up in your Home feed. Okay, similarly, now that Jane has installed the ActivityPub plugin on her `example.com` site, her friends can also follow her on Mastodon by searching for `@jane@example.com` and clicking the Follow button on that profile. - -From now on, every blog post Jane publishes on example.com will show up on your Home feed because you follow her `@jane@example.com` profile. -Of course, if no one follows your author instance, then no one will ever see the posts - including you! So the easiest way to even know if the plugin is working is to follow your new profile yourself. If you already have a Mastodon profile, just follow your new one from there. +* [Firefish](https://joinfirefish.org/) (rebrand of Calckey) Some things to note: -1. Many single-author blogs have chosen to turn off or redirect their author profile pages, usually via an SEO plugin like Yoast or Rank Math. This is usually done to avoid duplicate content with your blog’s home page. If your author page has been deactivated in this way, then ActivityPub won’t work for you. Instead, you can turn your author profile page back on, and then use the option in your SEO plugin to noindex the author page. This will enable the page to be live and ActivityPub will now work, but the live page won’t cause any duplicate content issues with search engines. -1. Once ActivityPub is installed, only new posts going forward will be available in the fediverse. Likewise, even if you’ve been using ActivityPub for a while, anyone who follows your site, will only see new posts you publish from that moment on. They will never see previously-published posts in their Home feed. This process is very similar to subscribing to a newsletter. If you subscribe to a newsletter, you will only receive future emails, but not the old archived ones. With ActivityPub, if someone follows your site, they will only receive new blog posts you publish from then on. +1. The blog-wide profile is only compatible with sites with rewrite rules enabled. If your site does not have rewrite rules enabled, the author-specific profiles may still work. +1. Many single-author blogs have chosen to turn off or redirect their author profile pages, usually via an SEO plugin like Yoast or Rank Math. This is usually done to avoid duplicate content with your blog’s home page. If your author page has been deactivated in this way, then ActivityPub author profiles won’t work for you. Instead, you can turn your author profile page back on, and then use the option in your SEO plugin to noindex the author page. This will duplicate content issues with search engines and will enable ActivityPub author profiles to work. +1. Once ActivityPub is installed, *only new posts going forward* will be available in the fediverse. Likewise, even if you’ve been using ActivityPub for a while, anyone who follows your site, will only see new posts you publish from that moment on. They will never see previously-published posts in their Home feed. This process is very similar to subscribing to a newsletter. If you subscribe to a newsletter, you will only receive future emails, but not the old archived ones. With ActivityPub, if someone follows your site, they will only receive new blog posts you publish from then on. So what’s the process? 1. Install the ActivityPub plugin. 1. Go to the plugin’s settings page and adjust the settings to your liking. Click the Save button when ready. -1. Make sure your blog’s author profile page is active. -1. Go to Mastodon or any other federated platform, search for your author’s new federated profile, and follow it. Your new profile will be in the form of @yourauthorname@yourwebsite.com, so that is what you’ll search for. +1. Make sure your blog’s author profile page is active if you are using author profiles. +1. Go to Mastodon or any other federated platform, and search for your profile, and follow it. Your new profile will be in the form of either `@your_username@example.com` or `@example.com@example.com`, so that is what you’ll search for. 1. On your blog, publish a new post. 1. From Mastodon, check to see if the new post appears in your Home feed. @@ -53,34 +54,25 @@ Please note that it may take up to 15 minutes or so for the new post to show up ### 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's author pages can be followed by users on these platforms, allowing them to receive your new posts in their feeds. - -Here's how it works: - -1. Install the plugin and adjust settings as needed. -1. Ensure your blog's author profile page is active. -1. On Mastodon or other supported platforms, search for and follow your author's new profile (e.g., `@yourauthorname@yourwebsite.com`). -1. Publish a new post on your blog and check if it appears in your Mastodon feed. - -Please note that it may take up to 15 minutes for a new post to appear in your feed, as messages are sent on a delay to avoid overwhelming your followers. Be patient and give it some time. +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: -* profile pages (JSON representation) +* 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 To implement: -* signature verification -* better WordPress integration -* better configuration possibilities * threaded comments support +* replace shortcodes with blocks for layout ### What is "ActivityPub for WordPress" ### @@ -94,7 +86,7 @@ In order for webfinger to work, it must be mapped to the root directory of the U Add the following to the .htaccess file in the root directory: - RedirectMatch "^\/\.well-known(.*)$" "\/blog\/\.well-known$1" + 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. @@ -111,7 +103,40 @@ Where 'blog' is the path to the subdirectory at which your blog resides. ## Changelog ## -Project maintained on GitHub at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub). +Project maintained on GitHub at [automattic/wordpress-activitypub](https://github.com/automattic/wordpress-activitypub). + +### 1.0.1 ### + +* Update: improve image attachment detection using the block editor +* Update: better error code handling for API responses +* Update: use a tag stack instead of regex for protecting tags for Hashtags and @-Mentions +* Compatibility: better signature support for subpath-installations +* Compatibility: allow deactivating blocks registered by the plugin +* Compatibility: avoid Fatal Errors when using ClassicPress +* Compatibility: improve the Group-Actor to play nicely with existing implementations +* Fixed: truncate long blog titles and handles for the "Follow me" block +* Fixed: ensure that only a valid user can be selected for the "Follow me" block +* Fixed: fix a typo in a hook name +* Fixed: a problem with signatures when running WordPress in a sub-path + +### 1.0.0 ### + +* Add: blog-wide Account (catchall, like `example.com@example.com`) +* Add: a Follow Me block (help visitors to follow your Profile) +* Add: Signature Verification: https://docs.joinmastodon.org/spec/security/ +* Add: a Followers Block (show off your Followers) +* Add: Simple caching +* Add: Collection endpoints for Featured Tags and Featured Posts +* Add: Better handling of Hashtags in mobile apps +* Update: Complete rewrite of the Follower-System based on Custom Post Types +* Update: Improved linter (PHPCS) +* Compatibility: Add a new conditional, `\Activitypub\is_activitypub_request()`, to allow third-party plugins to detect ActivityPub requests +* Compatibility: Add hooks to allow modifying images returned in ActivityPub requests +* Compatibility: Indicate that the plugin is compatible and has been tested with the latest version of WordPress, 6.3 +* Compatibility: Avoid PHP notice on sites using PHP 8.2 +* Fixed: Load the plugin later in the WordPress code lifecycle to avoid errors in some requests +* Fixed: Updating posts +* Fixed: Hashtag now support CamelCase and UTF-8 ### 0.17.0 ### @@ -373,6 +398,12 @@ Project maintained on GitHub at [pfefferle/wordpress-activitypub](https://github * initial +## Upgrade Notice ## + +### 1.0.0 ### + +For version 1.0.0 we have completely rebuilt the followers lists. There is a migration from the old format to the new, but it may take some time until the migration is complete. No data will be lost in the process, please give the migration some time. + ## Installation ## Follow the normal instructions for [installing WordPress plugins](https://wordpress.org/support/article/managing-plugins/). diff --git a/activitypub.php b/activitypub.php index 7320f0c68..03f0743eb 100644 --- a/activitypub.php +++ b/activitypub.php @@ -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: 0.17.0 + * Version: 1.0.1 * Author: Matthias Pfefferle & Automattic * Author URI: https://automattic.com/ * License: MIT @@ -15,85 +15,109 @@ namespace Activitypub; +use function Activitypub\site_supports_blocks; + +\defined( 'ACTIVITYPUB_REST_NAMESPACE' ) || \define( 'ACTIVITYPUB_REST_NAMESPACE', 'activitypub/1.0' ); + /** * Initialize plugin */ function init() { \defined( 'ACTIVITYPUB_EXCERPT_LENGTH' ) || \define( 'ACTIVITYPUB_EXCERPT_LENGTH', 400 ); + \defined( 'ACTIVITYPUB_SHOW_PLUGIN_RECOMMENDATIONS' ) || \define( 'ACTIVITYPUB_SHOW_PLUGIN_RECOMMENDATIONS', true ); \defined( 'ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS' ) || \define( 'ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS', 3 ); \defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || \define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(?:(?<=\s)|(?<=

)|(?<=
)|^)#([A-Za-z0-9_]+)(?:(?=\s|[[:punct:]]|$))' ); \defined( 'ACTIVITYPUB_USERNAME_REGEXP' ) || \define( 'ACTIVITYPUB_USERNAME_REGEXP', '(?:([A-Za-z0-9_-]+)@((?:[A-Za-z0-9_-]+\.)+[A-Za-z]+))' ); - \defined( 'ACTIVITYPUB_ALLOWED_HTML' ) || \define( 'ACTIVITYPUB_ALLOWED_HTML', '