Compare commits
2 commits
main
...
add/saniti
Author | SHA1 | Date | |
---|---|---|---|
|
8f897f5578 | ||
|
1397d864bb |
|
@ -15,8 +15,6 @@ Makefile
|
||||||
README.md
|
README.md
|
||||||
readme.md
|
readme.md
|
||||||
CODE_OF_CONDUCT.md
|
CODE_OF_CONDUCT.md
|
||||||
FEDERATION.md
|
|
||||||
SECURITY.md
|
|
||||||
LICENSE.md
|
LICENSE.md
|
||||||
_site
|
_site
|
||||||
_config.yml
|
_config.yml
|
||||||
|
|
90
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
|
@ -1,90 +0,0 @@
|
||||||
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: |
|
|
||||||
<br>
|
|
||||||
|
|
||||||
## 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
|
|
34
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
|
@ -1,34 +0,0 @@
|
||||||
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 <xyz>...
|
|
||||||
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.
|
|
17
.github/stale.yml
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
# Number of days of inactivity before an issue becomes stale
|
||||||
|
daysUntilStale: 120
|
||||||
|
# Number of days of inactivity before a stale issue is closed
|
||||||
|
daysUntilClose: 7
|
||||||
|
# Issues with these labels will never be considered stale
|
||||||
|
exemptLabels:
|
||||||
|
- pinned
|
||||||
|
- security
|
||||||
|
# Label to use when marking an issue as stale
|
||||||
|
staleLabel: wontfix
|
||||||
|
# Comment to post when marking an issue as stale. Set to `false` to disable
|
||||||
|
markComment: >
|
||||||
|
This issue has been automatically marked as stale because it has not had
|
||||||
|
recent activity. It will be closed if no further activity occurs. Thank you
|
||||||
|
for your contributions.
|
||||||
|
# Comment to post when closing a stale issue. Set to `false` to disable
|
||||||
|
closeComment: false
|
50
.github/workflows/gardening.yml
vendored
|
@ -1,50 +0,0 @@
|
||||||
# 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"}
|
|
||||||
]'
|
|
10
.github/workflows/phpunit.yml
vendored
|
@ -16,14 +16,9 @@ jobs:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
php-versions: ['5.6', '7.0', '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:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Setup PHP
|
- name: Setup PHP
|
||||||
uses: shivammathur/setup-php@v2
|
uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
|
@ -31,13 +26,10 @@ jobs:
|
||||||
coverage: none
|
coverage: none
|
||||||
tools: composer, phpunit-polyfills
|
tools: composer, phpunit-polyfills
|
||||||
extensions: mysql
|
extensions: mysql
|
||||||
|
|
||||||
- name: Install Composer dependencies for PHP
|
- name: Install Composer dependencies for PHP
|
||||||
uses: "ramsey/composer-install@v1"
|
uses: "ramsey/composer-install@v1"
|
||||||
|
|
||||||
- name: Setup Test Environment
|
- name: Setup Test Environment
|
||||||
run: bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1 ${{ matrix.wp-version }}
|
run: bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1 latest
|
||||||
|
|
||||||
- name: Unit Testing
|
- name: Unit Testing
|
||||||
run: ./vendor/bin/phpunit
|
run: ./vendor/bin/phpunit
|
||||||
env:
|
env:
|
||||||
|
|
19
.github/workflows/stale.yml
vendored
|
@ -1,19 +0,0 @@
|
||||||
name: 'Close stale issues and PRs'
|
|
||||||
on:
|
|
||||||
schedule:
|
|
||||||
- cron: '30 1 * * *'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
stale:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/stale@v8
|
|
||||||
with:
|
|
||||||
stale-issue-message: 'This issue is stale because it has been open 120 days with no activity. Remove stale label or comment or this will be closed in 5 days.'
|
|
||||||
days-before-stale: 120
|
|
||||||
days-before-close: 7
|
|
||||||
exempt-all-pr-assignees: true
|
|
||||||
exempt-all-assignees: true
|
|
||||||
exempt-all-pr-milestones: true
|
|
||||||
exempt-all-issue-milestones: true
|
|
||||||
start-date: '2019-02-01T00:00:00Z'
|
|
15
.php_cs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
$finder = PhpCsFixer\Finder::create()
|
||||||
|
->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)
|
||||||
|
;
|
Before Width: | Height: | Size: 1.1 MiB |
BIN
.wordpress-org/banner-772x250-v1.png
Normal file
After Width: | Height: | Size: 41 KiB |
Before Width: | Height: | Size: 272 KiB After Width: | Height: | Size: 79 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 29 KiB |
|
@ -1,128 +0,0 @@
|
||||||
# Contributor Covenant Code of Conduct
|
|
||||||
|
|
||||||
## Our Pledge
|
|
||||||
|
|
||||||
We as members, contributors, and leaders pledge to make participation in our
|
|
||||||
community a harassment-free experience for everyone, regardless of age, body
|
|
||||||
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
||||||
identity and expression, level of experience, education, socio-economic status,
|
|
||||||
nationality, personal appearance, race, religion, or sexual identity
|
|
||||||
and orientation.
|
|
||||||
|
|
||||||
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
||||||
diverse, inclusive, and healthy community.
|
|
||||||
|
|
||||||
## Our Standards
|
|
||||||
|
|
||||||
Examples of behavior that contributes to a positive environment for our
|
|
||||||
community include:
|
|
||||||
|
|
||||||
* Demonstrating empathy and kindness toward other people
|
|
||||||
* Being respectful of differing opinions, viewpoints, and experiences
|
|
||||||
* Giving and gracefully accepting constructive feedback
|
|
||||||
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
||||||
and learning from the experience
|
|
||||||
* Focusing on what is best not just for us as individuals, but for the
|
|
||||||
overall community
|
|
||||||
|
|
||||||
Examples of unacceptable behavior include:
|
|
||||||
|
|
||||||
* The use of sexualized language or imagery, and sexual attention or
|
|
||||||
advances of any kind
|
|
||||||
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
||||||
* Public or private harassment
|
|
||||||
* Publishing others' private information, such as a physical or email
|
|
||||||
address, without their explicit permission
|
|
||||||
* Other conduct which could reasonably be considered inappropriate in a
|
|
||||||
professional setting
|
|
||||||
|
|
||||||
## Enforcement Responsibilities
|
|
||||||
|
|
||||||
Community leaders are responsible for clarifying and enforcing our standards of
|
|
||||||
acceptable behavior and will take appropriate and fair corrective action in
|
|
||||||
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
||||||
or harmful.
|
|
||||||
|
|
||||||
Community leaders have the right and responsibility to remove, edit, or reject
|
|
||||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
||||||
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
||||||
decisions when appropriate.
|
|
||||||
|
|
||||||
## Scope
|
|
||||||
|
|
||||||
This Code of Conduct applies within all community spaces, and also applies when
|
|
||||||
an individual is officially representing the community in public spaces.
|
|
||||||
Examples of representing our community include using an official e-mail address,
|
|
||||||
posting via an official social media account, or acting as an appointed
|
|
||||||
representative at an online or offline event.
|
|
||||||
|
|
||||||
## Enforcement
|
|
||||||
|
|
||||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
||||||
reported to the community leaders responsible for enforcement at
|
|
||||||
https://developer.wordpress.com/contact/?g21-subject=Code%20of%20Conduct.
|
|
||||||
All complaints will be reviewed and investigated promptly and fairly.
|
|
||||||
|
|
||||||
All community leaders are obligated to respect the privacy and security of the
|
|
||||||
reporter of any incident.
|
|
||||||
|
|
||||||
## Enforcement Guidelines
|
|
||||||
|
|
||||||
Community leaders will follow these Community Impact Guidelines in determining
|
|
||||||
the consequences for any action they deem in violation of this Code of Conduct:
|
|
||||||
|
|
||||||
### 1. Correction
|
|
||||||
|
|
||||||
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
||||||
unprofessional or unwelcome in the community.
|
|
||||||
|
|
||||||
**Consequence**: A private, written warning from community leaders, providing
|
|
||||||
clarity around the nature of the violation and an explanation of why the
|
|
||||||
behavior was inappropriate. A public apology may be requested.
|
|
||||||
|
|
||||||
### 2. Warning
|
|
||||||
|
|
||||||
**Community Impact**: A violation through a single incident or series
|
|
||||||
of actions.
|
|
||||||
|
|
||||||
**Consequence**: A warning with consequences for continued behavior. No
|
|
||||||
interaction with the people involved, including unsolicited interaction with
|
|
||||||
those enforcing the Code of Conduct, for a specified period of time. This
|
|
||||||
includes avoiding interactions in community spaces as well as external channels
|
|
||||||
like social media. Violating these terms may lead to a temporary or
|
|
||||||
permanent ban.
|
|
||||||
|
|
||||||
### 3. Temporary Ban
|
|
||||||
|
|
||||||
**Community Impact**: A serious violation of community standards, including
|
|
||||||
sustained inappropriate behavior.
|
|
||||||
|
|
||||||
**Consequence**: A temporary ban from any sort of interaction or public
|
|
||||||
communication with the community for a specified period of time. No public or
|
|
||||||
private interaction with the people involved, including unsolicited interaction
|
|
||||||
with those enforcing the Code of Conduct, is allowed during this period.
|
|
||||||
Violating these terms may lead to a permanent ban.
|
|
||||||
|
|
||||||
### 4. Permanent Ban
|
|
||||||
|
|
||||||
**Community Impact**: Demonstrating a pattern of violation of community
|
|
||||||
standards, including sustained inappropriate behavior, harassment of an
|
|
||||||
individual, or aggression toward or disparagement of classes of individuals.
|
|
||||||
|
|
||||||
**Consequence**: A permanent ban from any sort of public interaction within
|
|
||||||
the community.
|
|
||||||
|
|
||||||
## Attribution
|
|
||||||
|
|
||||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
||||||
version 2.0, available at
|
|
||||||
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
|
||||||
|
|
||||||
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
|
||||||
enforcement ladder](https://github.com/mozilla/diversity).
|
|
||||||
|
|
||||||
[homepage]: https://www.contributor-covenant.org
|
|
||||||
|
|
||||||
For answers to common questions about this code of conduct, see the FAQ at
|
|
||||||
https://www.contributor-covenant.org/faq. Translations are available at
|
|
||||||
https://www.contributor-covenant.org/translations.
|
|
|
@ -1,38 +0,0 @@
|
||||||
# Federation in WordPress
|
|
||||||
|
|
||||||
The WordPress plugin largely follows ActivityPub's server-to-server specification, but makes use of some non-standard extensions, some of which are required to interact with the plugin. Most of these extensions are for the purpose of compatibility with other, sometimes very restrictive networks, such as Mastodon.
|
|
||||||
|
|
||||||
## Supported federation protocols and standards
|
|
||||||
|
|
||||||
- [ActivityPub](https://www.w3.org/TR/activitypub/) (Server-to-Server)
|
|
||||||
- [WebFinger](https://webfinger.net/)
|
|
||||||
- [HTTP Signatures](https://datatracker.ietf.org/doc/html/draft-cavage-http-signatures)
|
|
||||||
- [NodeInfo](https://nodeinfo.diaspora.software/)
|
|
||||||
|
|
||||||
## Supported FEPs
|
|
||||||
|
|
||||||
- [FEP-f1d5: NodeInfo in Fediverse Software](https://codeberg.org/fediverse/fep/src/branch/main/fep/f1d5/fep-f1d5.md)
|
|
||||||
- [FEP-67ff: FEDERATION.md](https://codeberg.org/fediverse/fep/src/branch/main/fep/67ff/fep-67ff.md)
|
|
||||||
- [FEP-5feb: Search indexing consent for actors](https://codeberg.org/fediverse/fep/src/branch/main/fep/5feb/fep-5feb.md)
|
|
||||||
|
|
||||||
Partially supported FEPs
|
|
||||||
|
|
||||||
- [FEP-1b12: Group federation](https://codeberg.org/fediverse/fep/src/branch/main/fep/1b12/fep-1b12.md)
|
|
||||||
|
|
||||||
## ActivityPub
|
|
||||||
|
|
||||||
### HTTP Signatures
|
|
||||||
|
|
||||||
In order to authenticate activities, Mastodon relies on HTTP Signatures, signing every `POST` and `GET` request to other ActivityPub implementations on behalf of the user authoring an activity (for `POST` requests) or an actor representing the Mastodon server itself (for most `GET` requests).
|
|
||||||
|
|
||||||
Mastodon requires all `POST` requests to be signed, and MAY require `GET` requests to be signed, depending on the configuration of the Mastodon server.
|
|
||||||
|
|
||||||
More information on HTTP Signatures, as well as examples, can be found here: https://docs.joinmastodon.org/spec/security/#http
|
|
||||||
|
|
||||||
## Additional documentation
|
|
||||||
|
|
||||||
- Plugin Description: https://github.com/Automattic/wordpress-activitypub?tab=readme-ov-file#description
|
|
||||||
- Frequently Asked Questions: https://github.com/Automattic/wordpress-activitypub?tab=readme-ov-file#frequently-asked-questions
|
|
||||||
- Installation Instructions: https://github.com/Automattic/wordpress-activitypub?tab=readme-ov-file#installation
|
|
||||||
- Upgrade Notice: https://github.com/Automattic/wordpress-activitypub?tab=readme-ov-file#upgrade-notice
|
|
||||||
- Changelog: https://github.com/Automattic/wordpress-activitypub?tab=readme-ov-file#changelog
|
|
1
LICENSE
|
@ -1,7 +1,6 @@
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2019 Matthias Pfefferle
|
Copyright (c) 2019 Matthias Pfefferle
|
||||||
Copyright (c) 2023 Automattic
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
171
README.md
|
@ -1,9 +1,9 @@
|
||||||
# ActivityPub #
|
# ActivityPub #
|
||||||
**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/)
|
**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/)
|
||||||
**Tags:** OStatus, fediverse, activitypub, activitystream
|
**Tags:** OStatus, fediverse, activitypub, activitystream
|
||||||
**Requires at least:** 4.7
|
**Requires at least:** 4.7
|
||||||
**Tested up to:** 6.4
|
**Tested up to:** 6.3
|
||||||
**Stable tag:** 1.2.0
|
**Stable tag:** 1.0.0
|
||||||
**Requires PHP:** 5.6
|
**Requires PHP:** 5.6
|
||||||
**License:** MIT
|
**License:** MIT
|
||||||
**License URI:** http://opensource.org/licenses/MIT
|
**License URI:** http://opensource.org/licenses/MIT
|
||||||
|
@ -12,39 +12,39 @@ The ActivityPub protocol is a decentralized social networking protocol based upo
|
||||||
|
|
||||||
## Description ##
|
## Description ##
|
||||||
|
|
||||||
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.
|
This is BETA software, see the FAQ to see the current feature set or rather what is still planned.
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
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:
|
The plugin works with the following tested federated platforms, but there may be more that it works with as well:
|
||||||
|
|
||||||
* [Mastodon](https://joinmastodon.org/)
|
* [Mastodon](https://joinmastodon.org/)
|
||||||
* [Pleroma](https://pleroma.social/)/[Akkoma](https://akkoma.social/)
|
* [Pleroma](https://pleroma.social/)
|
||||||
* [friendica](https://friendi.ca/)
|
* [friendica](https://friendi.ca/)
|
||||||
* [Hubzilla](https://hubzilla.org/)
|
* [Hubzilla](https://hubzilla.org/)
|
||||||
* [Pixelfed](https://pixelfed.org/)
|
* [Pixelfed](https://pixelfed.org/)
|
||||||
* [Socialhome](https://socialhome.network/)
|
* [Socialhome](https://socialhome.network/)
|
||||||
* [Misskey](https://join.misskey.page/)
|
* [Misskey](https://join.misskey.page/)
|
||||||
* [Firefish](https://joinfirefish.org/) (rebrand of Calckey)
|
* [Calckey](https://calckey.org/)
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
Some things to note:
|
Some things to note:
|
||||||
|
|
||||||
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 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. 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 still resolve 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.
|
||||||
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?
|
So what’s the process?
|
||||||
|
|
||||||
1. Install the ActivityPub plugin.
|
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. 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 if you are using author profiles.
|
1. Make sure your blog’s author profile page is active.
|
||||||
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. 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. On your blog, publish a new post.
|
1. On your blog, publish a new post.
|
||||||
1. From Mastodon, check to see if the new post appears in your Home feed.
|
1. From Mastodon, check to see if the new post appears in your Home feed.
|
||||||
|
|
||||||
|
@ -54,25 +54,34 @@ Please note that it may take up to 15 minutes or so for the new post to show up
|
||||||
|
|
||||||
### tl;dr ###
|
### 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.
|
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.
|
||||||
|
|
||||||
### What is the status of this plugin? ###
|
### What is the status of this plugin? ###
|
||||||
|
|
||||||
Implemented:
|
Implemented:
|
||||||
|
|
||||||
* blog profile pages (JSON representation)
|
* profile pages (JSON representation)
|
||||||
* author profile pages (JSON representation)
|
|
||||||
* custom links
|
* custom links
|
||||||
* functional inbox/outbox
|
* functional inbox/outbox
|
||||||
* follow (accept follows)
|
* follow (accept follows)
|
||||||
* share posts
|
* share posts
|
||||||
* receive comments/reactions
|
* receive comments/reactions
|
||||||
* signature verification
|
|
||||||
|
|
||||||
To implement:
|
To implement:
|
||||||
|
|
||||||
|
* signature verification
|
||||||
|
* better WordPress integration
|
||||||
|
* better configuration possibilities
|
||||||
* threaded comments support
|
* threaded comments support
|
||||||
* replace shortcodes with blocks for layout
|
|
||||||
|
|
||||||
### What is "ActivityPub for WordPress" ###
|
### What is "ActivityPub for WordPress" ###
|
||||||
|
|
||||||
|
@ -86,7 +95,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:
|
Add the following to the .htaccess file in the root directory:
|
||||||
|
|
||||||
RedirectMatch "^\/\.well-known/(webfinger|nodeinfo|x-nodeinfo2)(.*)$" /blog/.well-known/$1$2
|
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.
|
Where 'blog' is the path to the subdirectory at which your blog resides.
|
||||||
|
|
||||||
|
@ -105,115 +114,19 @@ Where 'blog' is the path to the subdirectory at which your blog resides.
|
||||||
|
|
||||||
Project maintained on GitHub at [automattic/wordpress-activitypub](https://github.com/automattic/wordpress-activitypub).
|
Project maintained on GitHub at [automattic/wordpress-activitypub](https://github.com/automattic/wordpress-activitypub).
|
||||||
|
|
||||||
### 1.2.0 ###
|
|
||||||
|
|
||||||
* Add: Search and order followerer lists
|
|
||||||
* Add: Have a filter to defer signature verification
|
|
||||||
* Improved: "Follow Me" styles for dark themes
|
|
||||||
* Improved: Allow `p` and `br` tags only for AP comments
|
|
||||||
* Fixed: Deduplicate attachments earlier to prevent incorrect max_media
|
|
||||||
|
|
||||||
|
|
||||||
### 1.1.0 ###
|
|
||||||
|
|
||||||
* Improved: audio and video attachments are now supported!
|
|
||||||
* Improved: better error messages if remote profile is not accessible
|
|
||||||
* Improved: PHP 8.1 compatibility
|
|
||||||
* Fixed: don't try to parse mentions or hashtags for very large (>1MB) posts to prevent timeouts
|
|
||||||
* Fixed: better handling of ISO-639-1 locale codes
|
|
||||||
* Improved: more reliable [ap_author], props @uk3
|
|
||||||
* Improved: NodeInfo statistics
|
|
||||||
|
|
||||||
### 1.0.10 ###
|
|
||||||
|
|
||||||
* Improved: better error messages if remote profile is not accessible
|
|
||||||
|
|
||||||
### 1.0.9 ###
|
|
||||||
|
|
||||||
* Fixed: broken following endpoint
|
|
||||||
|
|
||||||
### 1.0.8 ###
|
|
||||||
|
|
||||||
* Fixed: blocking of HEAD requests
|
|
||||||
* Fixed: PHP fatal error
|
|
||||||
* Fixed: several typos
|
|
||||||
* Fixed: error codes
|
|
||||||
* Improved: loading of shortcodes
|
|
||||||
* Updated: caching of followers
|
|
||||||
* Updated: Application-User is no longer "indexable"
|
|
||||||
* Updated: more consistent usage of the `application/activity+json` Content-Type
|
|
||||||
* Removed: featured tags endpoint
|
|
||||||
|
|
||||||
### 1.0.7 ###
|
|
||||||
|
|
||||||
* Fixed: broken function call
|
|
||||||
* Add: filter to hook into "is blog public" check
|
|
||||||
|
|
||||||
### 1.0.6 ###
|
|
||||||
|
|
||||||
* Fixed: more restrictive request verification
|
|
||||||
|
|
||||||
### 1.0.5 ###
|
|
||||||
|
|
||||||
* Fixed: compatibility with WebFinger and NodeInfo plugin
|
|
||||||
|
|
||||||
### 1.0.4 ###
|
|
||||||
|
|
||||||
* Fixed: Constants were not loaded early enough, resulting in a race condition
|
|
||||||
* Fixed: Featured image was ignored when using the block editor
|
|
||||||
|
|
||||||
### 1.0.3 ###
|
|
||||||
|
|
||||||
* Fixed: compatibility with older WordPress/PHP versions
|
|
||||||
* Update: refactoring of the Plugin init process
|
|
||||||
* Update: better frontend UX and improved theme compat for blocks
|
|
||||||
* Compatibility: add a ACTIVITYPUB_DISABLE_REWRITES constant
|
|
||||||
* Compatibility: add pre-fetch hook to allow plugins to hang filters on
|
|
||||||
|
|
||||||
### 1.0.2 ###
|
|
||||||
|
|
||||||
* Updated: improved hashtag visibility in default template
|
|
||||||
* Updated: reduced number of followers to be checked/updated via Cron, when System Cron is not set up
|
|
||||||
* Updated: check if username of Blog-User collides with an Authors name
|
|
||||||
* Compatibility: improved Group meta informations
|
|
||||||
* Fixed: detection of single user mode
|
|
||||||
* Fixed: remote delete
|
|
||||||
* Fixed: styles in Follow-Me block
|
|
||||||
* Fixed: various encoding and formatting issues
|
|
||||||
* Fixed: (health) check Author URLs only if Authors are enabled
|
|
||||||
|
|
||||||
### 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 ###
|
### 1.0.0 ###
|
||||||
|
|
||||||
* Add: blog-wide Account (catchall, like `example.com@example.com`)
|
* Add: blog-wide Account (catchall, like `mydomain.com@mydomain.com`)
|
||||||
* Add: a Follow Me block (help visitors to follow your Profile)
|
* Add: Signature Verification: https://docs.joinmastodon.org/spec/security/ .
|
||||||
* Add: Signature Verification: https://docs.joinmastodon.org/spec/security/
|
* Add: a Followers Block.
|
||||||
* Add: a Followers Block (show off your Followers)
|
|
||||||
* Add: Simple caching
|
* Add: Simple caching
|
||||||
* Add: Collection endpoints for Featured Tags and Featured Posts
|
* Update: Complete rewrite of the Follower-System based on Custom Post Types.
|
||||||
* Add: Better handling of Hashtags in mobile apps
|
|
||||||
* Update: Complete rewrite of the Follower-System based on Custom Post Types
|
|
||||||
* Update: Improved linter (PHPCS)
|
* Update: Improved linter (PHPCS)
|
||||||
* Compatibility: Add a new conditional, `\Activitypub\is_activitypub_request()`, to allow third-party plugins to detect ActivityPub requests
|
* 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: 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: 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
|
* 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: 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 ###
|
### 0.17.0 ###
|
||||||
|
|
||||||
|
|
36
SECURITY.md
|
@ -1,36 +0,0 @@
|
||||||
# Security Policy
|
|
||||||
|
|
||||||
Full details of the Automattic Security Policy can be found on [automattic.com](https://automattic.com/security/).
|
|
||||||
|
|
||||||
## Supported Versions
|
|
||||||
|
|
||||||
Generally, only the latest version of the ActivityPub plugin has continued support. If a critical vulnerability is found in the current version of the ActivityPub plugin, we may opt to backport any patches to previous versions.
|
|
||||||
|
|
||||||
## Reporting a Vulnerability
|
|
||||||
|
|
||||||
[ActivityPub](https://wordpress.org/plugins/activitypub/) is an open-source plugin for WordPress. Our HackerOne program covers the plugin software, as well as a variety of related projects and infrastructure.
|
|
||||||
|
|
||||||
**For responsible disclosure of security issues and to be eligible for our bug bounty program, please submit your report via the [HackerOne](https://hackerone.com/automattic) portal.**
|
|
||||||
|
|
||||||
Our most critical targets are:
|
|
||||||
|
|
||||||
* ActivityPub plugin (all within this repo)
|
|
||||||
* wordpress.com -- hosted ActivityPub offering on WordPress.com.
|
|
||||||
|
|
||||||
For more targets, see the `In Scope` section on [HackerOne](https://hackerone.com/automattic).
|
|
||||||
|
|
||||||
_Please note that the **WordPress software is a separate entity** from Automattic. Please report vulnerabilities for WordPress through [the WordPress Foundation's HackerOne page](https://hackerone.com/wordpress)._
|
|
||||||
|
|
||||||
## Guidelines
|
|
||||||
|
|
||||||
We're committed to working with security researchers to resolve the vulnerabilities they discover. You can help us by following these guidelines:
|
|
||||||
|
|
||||||
* Follow [HackerOne's disclosure guidelines](https://www.hackerone.com/disclosure-guidelines).
|
|
||||||
* Pen-testing Production:
|
|
||||||
* Please **setup a local environment** instead whenever possible. Most of our code is open source (see above).
|
|
||||||
* If that's not possible, **limit any data access/modification** to the bare minimum necessary to reproduce a PoC.
|
|
||||||
* **_Don't_ automate form submissions!** That's very annoying for us, because it adds extra work for the volunteers who manage those systems, and reduces the signal/noise ratio in our communication channels.
|
|
||||||
* To be eligible for a bounty, all of these guidelines must be followed.
|
|
||||||
* Be Patient - Give us a reasonable time to correct the issue before you disclose the vulnerability.
|
|
||||||
|
|
||||||
We also expect you to comply with all applicable laws. You're responsible to pay any taxes associated with your bounties.
|
|
|
@ -3,7 +3,7 @@
|
||||||
* Plugin Name: ActivityPub
|
* Plugin Name: ActivityPub
|
||||||
* Plugin URI: https://github.com/pfefferle/wordpress-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.
|
* Description: The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format.
|
||||||
* Version: 1.2.0
|
* Version: 1.0.0
|
||||||
* Author: Matthias Pfefferle & Automattic
|
* Author: Matthias Pfefferle & Automattic
|
||||||
* Author URI: https://automattic.com/
|
* Author URI: https://automattic.com/
|
||||||
* License: MIT
|
* License: MIT
|
||||||
|
@ -15,37 +15,31 @@
|
||||||
|
|
||||||
namespace Activitypub;
|
namespace Activitypub;
|
||||||
|
|
||||||
use function Activitypub\is_blog_public;
|
\defined( 'ACTIVITYPUB_REST_NAMESPACE' ) || \define( 'ACTIVITYPUB_REST_NAMESPACE', 'activitypub/1.0' );
|
||||||
use function Activitypub\site_supports_blocks;
|
|
||||||
|
|
||||||
require_once __DIR__ . '/includes/compat.php';
|
|
||||||
require_once __DIR__ . '/includes/functions.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the plugin constants.
|
* Initialize plugin
|
||||||
*/
|
*/
|
||||||
\defined( 'ACTIVITYPUB_REST_NAMESPACE' ) || \define( 'ACTIVITYPUB_REST_NAMESPACE', 'activitypub/1.0' );
|
function init() {
|
||||||
\defined( 'ACTIVITYPUB_EXCERPT_LENGTH' ) || \define( 'ACTIVITYPUB_EXCERPT_LENGTH', 400 );
|
\defined( 'ACTIVITYPUB_EXCERPT_LENGTH' ) || \define( 'ACTIVITYPUB_EXCERPT_LENGTH', 400 );
|
||||||
\defined( 'ACTIVITYPUB_SHOW_PLUGIN_RECOMMENDATIONS' ) || \define( 'ACTIVITYPUB_SHOW_PLUGIN_RECOMMENDATIONS', true );
|
\defined( 'ACTIVITYPUB_SHOW_PLUGIN_RECOMMENDATIONS' ) || \define( 'ACTIVITYPUB_SHOW_PLUGIN_RECOMMENDATIONS', true );
|
||||||
\defined( 'ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS' ) || \define( 'ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS', 3 );
|
\defined( 'ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS' ) || \define( 'ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS', 3 );
|
||||||
\defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || \define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(?:(?<=\s)|(?<=<p>)|(?<=<br>)|^)#([A-Za-z0-9_]+)(?:(?=\s|[[:punct:]]|$))' );
|
\defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || \define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(?:(?<=\s)|(?<=<p>)|(?<=<br>)|^)#([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_USERNAME_REGEXP' ) || \define( 'ACTIVITYPUB_USERNAME_REGEXP', '(?:([A-Za-z0-9_-]+)@((?:[A-Za-z0-9_-]+\.)+[A-Za-z]+))' );
|
||||||
\defined( 'ACTIVITYPUB_CUSTOM_POST_CONTENT' ) || \define( 'ACTIVITYPUB_CUSTOM_POST_CONTENT', "<strong>[ap_title]</strong>\n\n[ap_content]\n\n[ap_hashtags]\n\n[ap_shortlink]" );
|
\defined( 'ACTIVITYPUB_CUSTOM_POST_CONTENT' ) || \define( 'ACTIVITYPUB_CUSTOM_POST_CONTENT', "<strong>[ap_title]</strong>\n\n[ap_content]\n\n[ap_hashtags]\n\n[ap_shortlink]" );
|
||||||
\defined( 'ACTIVITYPUB_AUTHORIZED_FETCH' ) || \define( 'ACTIVITYPUB_AUTHORIZED_FETCH', false );
|
\defined( 'ACTIVITYPUB_SECURE_MODE' ) || \define( 'ACTIVITYPUB_SECURE_MODE', apply_filters( 'activitypub_secure_mode', $value = false ) );
|
||||||
\defined( 'ACTIVITYPUB_DISABLE_REWRITES' ) || \define( 'ACTIVITYPUB_DISABLE_REWRITES', false );
|
|
||||||
\defined( 'ACTIVITYPUB_DEFAULT_TRANSFORMER' ) || \define( 'ACTIVITYPUB_DEFAULT_TRANSFORMER', 'activitypub/default' );
|
|
||||||
|
|
||||||
|
|
||||||
\define( 'ACTIVITYPUB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
\define( 'ACTIVITYPUB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
||||||
\define( 'ACTIVITYPUB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
|
\define( 'ACTIVITYPUB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
|
||||||
\define( 'ACTIVITYPUB_PLUGIN_FILE', plugin_dir_path( __FILE__ ) . '/' . basename( __FILE__ ) );
|
\define( 'ACTIVITYPUB_PLUGIN_FILE', plugin_dir_path( __FILE__ ) . '/' . basename( __FILE__ ) );
|
||||||
\define( 'ACTIVITYPUB_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
\define( 'ACTIVITYPUB_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
||||||
|
|
||||||
|
Migration::init();
|
||||||
|
Activitypub::init();
|
||||||
|
Activity_Dispatcher::init();
|
||||||
|
Collection\Followers::init();
|
||||||
|
|
||||||
/**
|
// Configure the REST API route
|
||||||
* Initialize REST routes.
|
|
||||||
*/
|
|
||||||
function rest_init() {
|
|
||||||
Rest\Users::init();
|
Rest\Users::init();
|
||||||
Rest\Outbox::init();
|
Rest\Outbox::init();
|
||||||
Rest\Inbox::init();
|
Rest\Inbox::init();
|
||||||
|
@ -53,51 +47,21 @@ function rest_init() {
|
||||||
Rest\Following::init();
|
Rest\Following::init();
|
||||||
Rest\Webfinger::init();
|
Rest\Webfinger::init();
|
||||||
Rest\Server::init();
|
Rest\Server::init();
|
||||||
Rest\Collection::init();
|
|
||||||
|
|
||||||
// load NodeInfo endpoints only if blog is public
|
Admin::init();
|
||||||
if ( is_blog_public() ) {
|
Hashtag::init();
|
||||||
Rest\NodeInfo::init();
|
Shortcodes::init();
|
||||||
|
Blocks::init();
|
||||||
|
Mention::init();
|
||||||
|
Health_Check::init();
|
||||||
|
Scheduler::init();
|
||||||
}
|
}
|
||||||
}
|
\add_action( 'init', __NAMESPACE__ . '\init' );
|
||||||
\add_action( 'rest_api_init', __NAMESPACE__ . '\rest_init' );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize plugin.
|
|
||||||
*/
|
|
||||||
function plugin_init() {
|
|
||||||
\add_action( 'init', array( __NAMESPACE__ . '\Migration', 'init' ) );
|
|
||||||
\add_action( 'init', array( __NAMESPACE__ . '\Activitypub', 'init' ) );
|
|
||||||
\add_action( 'init', array( __NAMESPACE__ . '\Activity_Dispatcher', 'init' ) );
|
|
||||||
\add_action( 'init', array( __NAMESPACE__ . '\Collection\Followers', 'init' ) );
|
|
||||||
\add_action( 'init', array( __NAMESPACE__ . '\Admin', 'init' ) );
|
|
||||||
\add_action( 'init', array( __NAMESPACE__ . '\Hashtag', 'init' ) );
|
|
||||||
\add_action( 'init', array( __NAMESPACE__ . '\Mention', 'init' ) );
|
|
||||||
\add_action( 'init', array( __NAMESPACE__ . '\Health_Check', 'init' ) );
|
|
||||||
\add_action( 'init', array( __NAMESPACE__ . '\Scheduler', 'init' ) );
|
|
||||||
|
|
||||||
if ( site_supports_blocks() ) {
|
|
||||||
\add_action( 'init', array( __NAMESPACE__ . '\Blocks', 'init' ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
$debug_file = __DIR__ . '/includes/debug.php';
|
|
||||||
if ( \WP_DEBUG && file_exists( $debug_file ) && is_readable( $debug_file ) ) {
|
|
||||||
require_once $debug_file;
|
|
||||||
Debug::init();
|
|
||||||
}
|
|
||||||
|
|
||||||
require_once __DIR__ . '/integration/class-webfinger.php';
|
|
||||||
Integration\Webfinger::init();
|
|
||||||
|
|
||||||
require_once __DIR__ . '/integration/class-nodeinfo.php';
|
|
||||||
Integration\Nodeinfo::init();
|
|
||||||
}
|
|
||||||
\add_action( 'plugins_loaded', __NAMESPACE__ . '\plugin_init' );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Autoloader
|
* Class Autoloader
|
||||||
*/
|
*/
|
||||||
\spl_autoload_register(
|
spl_autoload_register(
|
||||||
function ( $full_class ) {
|
function ( $full_class ) {
|
||||||
$base_dir = __DIR__ . '/includes/';
|
$base_dir = __DIR__ . '/includes/';
|
||||||
$base = 'Activitypub\\';
|
$base = 'Activitypub\\';
|
||||||
|
@ -130,6 +94,19 @@ function plugin_init() {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
require_once __DIR__ . '/includes/functions.php';
|
||||||
|
|
||||||
|
// load NodeInfo endpoints only if blog is public
|
||||||
|
if ( \get_option( 'blog_public', 1 ) ) {
|
||||||
|
Rest\NodeInfo::init();
|
||||||
|
}
|
||||||
|
|
||||||
|
$debug_file = __DIR__ . '/includes/debug.php';
|
||||||
|
if ( \WP_DEBUG && file_exists( $debug_file ) && is_readable( $debug_file ) ) {
|
||||||
|
require_once $debug_file;
|
||||||
|
Debug::init();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add plugin settings link
|
* Add plugin settings link
|
||||||
*/
|
*/
|
||||||
|
|
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 12 KiB |
|
@ -1,47 +0,0 @@
|
||||||
{
|
|
||||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
|
||||||
"name": "activitypub/follow-me",
|
|
||||||
"apiVersion": 3,
|
|
||||||
"version": "1.0.0",
|
|
||||||
"title": "Follow me on the Fediverse",
|
|
||||||
"category": "widgets",
|
|
||||||
"description": "Display your Fediverse profile so that visitors can follow you.",
|
|
||||||
"textdomain": "activitypub",
|
|
||||||
"icon": "groups",
|
|
||||||
"supports": {
|
|
||||||
"html": false,
|
|
||||||
"color": {
|
|
||||||
"gradients": true,
|
|
||||||
"link": true,
|
|
||||||
"__experimentalDefaultControls": {
|
|
||||||
"background": true,
|
|
||||||
"text": true,
|
|
||||||
"link": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"__experimentalBorder": {
|
|
||||||
"radius": true,
|
|
||||||
"width": true,
|
|
||||||
"color": true,
|
|
||||||
"style": true
|
|
||||||
},
|
|
||||||
"typography": {
|
|
||||||
"fontSize": true,
|
|
||||||
"__experimentalDefaultControls": {
|
|
||||||
"fontSize": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"attributes": {
|
|
||||||
"selectedUser": {
|
|
||||||
"type": "string",
|
|
||||||
"default": "site"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"editorScript": "file:./index.js",
|
|
||||||
"viewScript": "file:./view.js",
|
|
||||||
"style": [
|
|
||||||
"file:./style-index.css",
|
|
||||||
"wp-components"
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
<?php return array('dependencies' => array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '2a185b1c488886051601');
|
|
|
@ -1 +0,0 @@
|
||||||
.activitypub-follow-me-block-wrapper{width:100%}.activitypub-follow-me-block-wrapper.has-background .activitypub-profile,.activitypub-follow-me-block-wrapper.has-border-color .activitypub-profile{padding-left:1rem;padding-right:1rem}.activitypub-follow-me-block-wrapper .activitypub-profile{align-items:center;display:flex;padding:1rem 0}.activitypub-follow-me-block-wrapper .activitypub-profile .activitypub-profile__avatar{border-radius:50%;height:75px;margin-right:1rem;width:75px}.activitypub-follow-me-block-wrapper .activitypub-profile .activitypub-profile__content{flex:1;min-width:0}.activitypub-follow-me-block-wrapper .activitypub-profile .activitypub-profile__handle,.activitypub-follow-me-block-wrapper .activitypub-profile .activitypub-profile__name{line-height:1.2;margin:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.activitypub-follow-me-block-wrapper .activitypub-profile .activitypub-profile__name{font-size:1.25em}.activitypub-follow-me-block-wrapper .activitypub-profile .activitypub-profile__follow{align-self:center;background-color:var(--wp--preset--color--black);color:var(--wp--preset--color--white);margin-left:1rem}.activitypub-profile__confirm.components-modal__frame{background-color:#f7f7f7;color:#333}.activitypub-profile__confirm.components-modal__frame .components-modal__header-heading,.activitypub-profile__confirm.components-modal__frame h4{color:#333;letter-spacing:inherit;word-spacing:inherit}.activitypub-follow-me__dialog{max-width:30em}.activitypub-follow-me__dialog h4{line-height:1;margin:0}.activitypub-follow-me__dialog .apmfd__section{margin-bottom:2em}.activitypub-follow-me__dialog .apfmd-description{font-size:var(--wp--preset--font-size--normal,.75rem);margin:.33em 0 1em}.activitypub-follow-me__dialog .apfmd__button-group{align-items:flex-end;display:flex;justify-content:flex-end}.activitypub-follow-me__dialog .apfmd__button-group svg{height:21px;margin-right:.5em;width:21px}.activitypub-follow-me__dialog .apfmd__button-group input{background-color:var(--wp--preset--color--white);border:1px solid var(--wp--preset--color--black);color:var(--wp--preset--color--black);flex:1;padding:6px 12px}
|
|
|
@ -1 +0,0 @@
|
||||||
<?php return array('dependencies' => array('wp-api-fetch', 'wp-components', 'wp-compose', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '17a158ceced1355cc8ea');
|
|
|
@ -1 +1 @@
|
||||||
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-url'), 'version' => '1cbd9cbfcbd7fc813429');
|
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-url'), 'version' => '284dffd27ea0242085be');
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
(()=>{var e={184:(e,t)=>{var a;!function(){"use strict";var n={}.hasOwnProperty;function l(){for(var e=[],t=0;t<arguments.length;t++){var a=arguments[t];if(a){var r=typeof a;if("string"===r||"number"===r)e.push(a);else if(Array.isArray(a)){if(a.length){var o=l.apply(null,a);o&&e.push(o)}}else if("object"===r){if(a.toString!==Object.prototype.toString&&!a.toString.toString().includes("[native code]")){e.push(a.toString());continue}for(var i in a)n.call(a,i)&&a[i]&&e.push(i)}}}return e.join(" ")}e.exports?(l.default=l,e.exports=l):void 0===(a=function(){return l}.apply(t,[]))||(e.exports=a)}()}},t={};function a(n){var l=t[n];if(void 0!==l)return l.exports;var r=t[n]={exports:{}};return e[n](r,r.exports,a),r.exports}a.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return a.d(t,{a:t}),t},a.d=(e,t)=>{for(var n in t)a.o(t,n)&&!a.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";const e=window.wp.blocks,t=window.wp.element,n=window.wp.primitives,l=(0,t.createElement)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,t.createElement)(n.Path,{d:"M15.5 9.5a1 1 0 100-2 1 1 0 000 2zm0 1.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5zm-2.25 6v-2a2.75 2.75 0 00-2.75-2.75h-4A2.75 2.75 0 003.75 15v2h1.5v-2c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v2h1.5zm7-2v2h-1.5v-2c0-.69-.56-1.25-1.25-1.25H15v-1.5h2.5A2.75 2.75 0 0120.25 15zM9.5 8.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z",fillRule:"evenodd"}));function r(){return r=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(e[n]=a[n])}return e},r.apply(this,arguments)}const o=window.wp.components,i=window.wp.blockEditor,c=window.wp.i18n,s=window.React,p=window.wp.apiFetch;var u=a.n(p);const v=window.wp.url;var m=a(184),b=a.n(m);function w(e){let{active:a,children:n,page:l,pageClick:r,className:o}=e;const i=b()("wp-block activitypub-pager",o,{current:a});return(0,t.createElement)("a",{className:i,onClick:e=>{e.preventDefault(),!a&&r(l)}},n)}const d={outlined:"outlined",minimal:"minimal"};function f(e){let{compact:a,nextLabel:n,page:l,pageClick:r,perPage:o,prevLabel:i,total:c,variant:s=d.outlined}=e;const p=((e,t)=>{let a=[1,e-2,e-1,e,e+1,e+2,t];a.sort(((e,t)=>e-t)),a=a.filter(((e,a,n)=>e>=1&&e<=t&&n.lastIndexOf(e)===a));for(let e=a.length-2;e>=0;e--)a[e]===a[e+1]&&a.splice(e+1,1);return a})(l,Math.ceil(c/o)),u=b()("alignwide wp-block-query-pagination is-content-justification-space-between is-layout-flex wp-block-query-pagination-is-layout-flex",`is-${s}`,{"is-compact":a});return(0,t.createElement)("nav",{className:u},i&&(0,t.createElement)(w,{key:"prev",page:l-1,pageClick:r,active:1===l,"aria-label":i,className:"wp-block-query-pagination-previous block-editor-block-list__block"},i),!a&&(0,t.createElement)("div",{className:"block-editor-block-list__block wp-block wp-block-query-pagination-numbers"},p.map((e=>(0,t.createElement)(w,{key:e,page:e,pageClick:r,active:e===l,className:"page-numbers"},e)))),n&&(0,t.createElement)(w,{key:"next",page:l+1,pageClick:r,active:l===Math.ceil(c/o),"aria-label":n,className:"wp-block-query-pagination-next block-editor-block-list__block"},n))}const{namespace:g}=window._activityPubOptions;function y(e){let{selectedUser:a,per_page:n,order:l,title:o,page:i,setPage:p,className:m="",followLinks:b=!0,followerData:w=!1}=e;const d="site"===a?0:a,[y,k]=(0,s.useState)([]),[E,_]=(0,s.useState)(0),[x,C]=(0,s.useState)(0),[S,O]=function(){const[e,t]=(0,s.useState)(1);return[e,t]}(),N=i||S,P=p||O,L=(0,t.createInterpolateElement)(/* translators: arrow for previous followers link */
|
(()=>{var e={184:(e,t)=>{var a;!function(){"use strict";var n={}.hasOwnProperty;function l(){for(var e=[],t=0;t<arguments.length;t++){var a=arguments[t];if(a){var r=typeof a;if("string"===r||"number"===r)e.push(a);else if(Array.isArray(a)){if(a.length){var o=l.apply(null,a);o&&e.push(o)}}else if("object"===r){if(a.toString!==Object.prototype.toString&&!a.toString.toString().includes("[native code]")){e.push(a.toString());continue}for(var i in a)n.call(a,i)&&a[i]&&e.push(i)}}}return e.join(" ")}e.exports?(l.default=l,e.exports=l):void 0===(a=function(){return l}.apply(t,[]))||(e.exports=a)}()}},t={};function a(n){var l=t[n];if(void 0!==l)return l.exports;var r=t[n]={exports:{}};return e[n](r,r.exports,a),r.exports}a.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return a.d(t,{a:t}),t},a.d=(e,t)=>{for(var n in t)a.o(t,n)&&!a.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";const e=window.wp.blocks,t=window.wp.element,n=window.wp.primitives,l=(0,t.createElement)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,t.createElement)(n.Path,{d:"M15.5 9.5a1 1 0 100-2 1 1 0 000 2zm0 1.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5zm-2.25 6v-2a2.75 2.75 0 00-2.75-2.75h-4A2.75 2.75 0 003.75 15v2h1.5v-2c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v2h1.5zm7-2v2h-1.5v-2c0-.69-.56-1.25-1.25-1.25H15v-1.5h2.5A2.75 2.75 0 0120.25 15zM9.5 8.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z",fillRule:"evenodd"}));function r(){return r=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(e[n]=a[n])}return e},r.apply(this,arguments)}const o=window.wp.components,i=window.wp.data,c=window.wp.blockEditor,s=window.wp.i18n,p=window.React,u=window.wp.apiFetch;var v=a.n(u);const m=window.wp.url;var b=a(184),w=a.n(b);function d(e){let{active:a,children:n,page:l,pageClick:r,className:o}=e;const i=w()("wp-block activitypub-pager",o,{current:a});return(0,t.createElement)("a",{className:i,onClick:e=>{e.preventDefault(),!a&&r(l)}},n)}const g={outlined:"outlined",minimal:"minimal"};function f(e){let{compact:a,nextLabel:n,page:l,pageClick:r,perPage:o,prevLabel:i,total:c,variant:s=g.outlined}=e;const p=((e,t)=>{let a=[1,e-2,e-1,e,e+1,e+2,t];a.sort(((e,t)=>e-t)),a=a.filter(((e,a,n)=>e>=1&&e<=t&&n.lastIndexOf(e)===a));for(let e=a.length-2;e>=0;e--)a[e]===a[e+1]&&a.splice(e+1,1);return a})(l,Math.ceil(c/o)),u=w()("alignwide wp-block-query-pagination is-content-justification-space-between is-layout-flex wp-block-query-pagination-is-layout-flex",`is-${s}`,{"is-compact":a});return(0,t.createElement)("nav",{className:u},i&&(0,t.createElement)(d,{key:"prev",page:l-1,pageClick:r,active:1===l,"aria-label":i,className:"wp-block-query-pagination-previous block-editor-block-list__block"},i),!a&&(0,t.createElement)("div",{className:"block-editor-block-list__block wp-block wp-block-query-pagination-numbers"},p.map((e=>(0,t.createElement)(d,{key:e,page:e,pageClick:r,active:e===l,className:"page-numbers"},e)))),n&&(0,t.createElement)(d,{key:"next",page:l+1,pageClick:r,active:l===Math.ceil(c/o),"aria-label":n,className:"wp-block-query-pagination-next block-editor-block-list__block"},n))}const{namespace:y}=window._activityPubOptions;function h(e){let{selectedUser:a,per_page:n,order:l,title:o,page:i,setPage:c,className:u="",followLinks:b=!0}=e;const w="site"===a?0:a,[d,g]=(0,p.useState)([]),[h,_]=(0,p.useState)(0),[E,x]=(0,p.useState)(0),[C,S]=function(){const[e,t]=(0,p.useState)(1);return[e,t]}(),O=i||C,N=c||S,P=(0,t.createInterpolateElement)(/* translators: arrow for previous followers link */
|
||||||
(0,c.__)("<span>←</span> Less","activitypub"),{span:(0,t.createElement)("span",{class:"wp-block-query-pagination-previous-arrow is-arrow-arrow","aria-hidden":"true"})}),j=(0,t.createInterpolateElement)(/* translators: arrow for next followers link */
|
(0,s.__)("<span>←</span> Less","activitypub"),{span:(0,t.createElement)("span",{class:"wp-block-query-pagination-previous-arrow is-arrow-arrow","aria-hidden":"true"})}),L=(0,t.createInterpolateElement)(/* translators: arrow for next followers link */
|
||||||
(0,c.__)("More <span>→</span>","activitypub"),{span:(0,t.createElement)("span",{class:"wp-block-query-pagination-next-arrow is-arrow-arrow","aria-hidden":"true"})}),M=(e,t)=>{k(e),C(t),_(Math.ceil(t/n))};return(0,s.useEffect)((()=>{if(w&&1===N)return M(w.followers,w.total);const e=function(e,t,a,n){const l=`/${g}/users/${e}/followers`,r={per_page:t,order:a,page:n,context:"full"};return(0,v.addQueryArgs)(l,r)}(d,n,l,N);u()({path:e}).then((e=>M(e.orderedItems,e.totalItems))).catch((()=>{}))}),[d,n,l,N,w]),(0,t.createElement)("div",{className:"activitypub-follower-block "+m},(0,t.createElement)("h3",null,o),(0,t.createElement)("ul",null,y&&y.map((e=>(0,t.createElement)("li",{key:e.url},(0,t.createElement)(h,r({},e,{followLinks:b})))))),E>1&&(0,t.createElement)(f,{page:N,perPage:n,total:x,pageClick:P,nextLabel:j,prevLabel:L,compact:"is-style-compact"===m}))}function h(e){let{name:a,icon:n,url:l,preferredUsername:i,followLinks:c=!0}=e;const s=`@${i}`,p={};return c||(p.onClick=e=>e.preventDefault()),(0,t.createElement)(o.ExternalLink,r({className:"activitypub-link",href:l,title:s},p),(0,t.createElement)("img",{width:"40",height:"40",src:n.url,class:"avatar activitypub-avatar"}),(0,t.createElement)("span",{class:"activitypub-actor"},(0,t.createElement)("strong",{className:"activitypub-name"},a),(0,t.createElement)("span",{class:"sep"},"/"),(0,t.createElement)("span",{class:"activitypub-handle"},s)))}const k=window.wp.data,E=window._activityPubOptions?.enabled;(0,e.registerBlockType)("activitypub/followers",{edit:function(e){let{attributes:a,setAttributes:n}=e;const{order:l,per_page:s,selectedUser:p,title:u}=a,v=(0,i.useBlockProps)(),[m,b]=(0,t.useState)(1),w=[{label:(0,c.__)("New to old","activitypub"),value:"desc"},{label:(0,c.__)("Old to new","activitypub"),value:"asc"}],d=function(){const e=E?.users?(0,k.useSelect)((e=>e("core").getUsers({who:"authors"}))):[];return(0,t.useMemo)((()=>{if(!e)return[];const t=E?.site?[{label:(0,c.__)("Whole Site","activitypub"),value:"site"}]:[];return e.reduce(((e,t)=>(e.push({label:t.name,value:`${t.id}`}),e)),t)}),[e])}(),f=e=>t=>{b(1),n({[e]:t})};return(0,t.useEffect)((()=>{d.length&&(d.find((e=>{let{value:t}=e;return t===p}))||n({selectedUser:d[0].value}))}),[p,d]),(0,t.createElement)("div",v,(0,t.createElement)(i.InspectorControls,{key:"setting"},(0,t.createElement)(o.PanelBody,{title:(0,c.__)("Followers Options","activitypub")},(0,t.createElement)(o.TextControl,{label:(0,c.__)("Title","activitypub"),help:(0,c.__)("Title to display above the list of followers. Blank for none.","activitypub"),value:u,onChange:e=>n({title:e})}),d.length>1&&(0,t.createElement)(o.SelectControl,{label:(0,c.__)("Select User","activitypub"),value:p,options:d,onChange:f("selectedUser")}),(0,t.createElement)(o.SelectControl,{label:(0,c.__)("Sort","activitypub"),value:l,options:w,onChange:f("order")}),(0,t.createElement)(o.RangeControl,{label:(0,c.__)("Number of Followers","activitypub"),value:s,onChange:f("per_page"),min:1,max:10}))),(0,t.createElement)(y,r({},a,{page:m,setPage:b,followLinks:!1})))},save:()=>null,icon:l})})()})();
|
(0,s.__)("More <span>→</span>","activitypub"),{span:(0,t.createElement)("span",{class:"wp-block-query-pagination-next-arrow is-arrow-arrow","aria-hidden":"true"})});return(0,p.useEffect)((()=>{const e=function(e,t,a,n){const l=`/${y}/users/${e}/followers`,r={per_page:t,order:a,page:n,context:"full"};return(0,m.addQueryArgs)(l,r)}(w,n,l,O);v()({path:e}).then((e=>{_(Math.ceil(e.totalItems/n)),x(e.totalItems),g(e.orderedItems)})).catch((e=>console.error(e)))}),[w,n,l,O]),(0,t.createElement)("div",{className:"activitypub-follower-block "+u},(0,t.createElement)("h3",null,o),(0,t.createElement)("ul",null,d&&d.map((e=>(0,t.createElement)("li",{key:e.url},(0,t.createElement)(k,r({},e,{followLinks:b})))))),h>1&&(0,t.createElement)(f,{page:O,perPage:n,total:E,pageClick:N,nextLabel:L,prevLabel:P,compact:"is-style-compact"===u}))}function k(e){let{name:a,icon:n,url:l,preferredUsername:i,followLinks:c=!0}=e;const s=`@${i}`,p={};return c||(p.onClick=e=>e.preventDefault()),(0,t.createElement)(o.ExternalLink,r({className:"activitypub-link",href:l,title:s},p),(0,t.createElement)("img",{width:"40",height:"40",src:n.url,class:"avatar activitypub-avatar"}),(0,t.createElement)("span",{class:"activitypub-actor"},(0,t.createElement)("strong",{className:"activitypub-name"},a),(0,t.createElement)("span",{class:"sep"},"/"),(0,t.createElement)("span",{class:"activitypub-handle"},s)))}const _=window._activityPubOptions?.enabled;(0,e.registerBlockType)("activitypub/followers",{edit:function(e){let{attributes:a,setAttributes:n}=e;const{order:l,per_page:p,selectedUser:u,title:v}=a,m=(0,c.useBlockProps)(),[b,w]=(0,t.useState)(1),d=[{label:(0,s.__)("New to old","activitypub"),value:"desc"},{label:(0,s.__)("Old to new","activitypub"),value:"asc"}],g=function(){const e=_?.users?(0,i.useSelect)((e=>e("core").getUsers({who:"authors"}))):[];return(0,t.useMemo)((()=>{if(!e)return[];const t=_?.site?[{label:(0,s.__)("Whole Site","activitypub"),value:"site"}]:[];return e.reduce(((e,t)=>(e.push({label:t.name,value:t.id}),e)),t)}),[e])}(),f=e=>t=>{w(1),n({[e]:t})};return(0,t.createElement)("div",m,(0,t.createElement)(c.InspectorControls,{key:"setting"},(0,t.createElement)(o.PanelBody,{title:(0,s.__)("Followers Options","activitypub")},(0,t.createElement)(o.TextControl,{label:(0,s.__)("Title","activitypub"),help:(0,s.__)("Title to display above the list of followers. Blank for none.","activitypub"),value:v,onChange:e=>n({title:e})}),(0,t.createElement)(o.SelectControl,{label:(0,s.__)("Select User","activitypub"),value:u,options:g,onChange:f("selectedUser")}),(0,t.createElement)(o.SelectControl,{label:(0,s.__)("Sort","activitypub"),value:l,options:d,onChange:f("order")}),(0,t.createElement)(o.RangeControl,{label:(0,s.__)("Number of Followers","activitypub"),value:p,onChange:f("per_page"),min:1,max:10}))),(0,t.createElement)(h,r({},a,{page:b,setPage:w,followLinks:!1})))},save:()=>null,icon:l})})()})();
|
|
@ -1 +1 @@
|
||||||
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => 'f0e21057f7ec615290d6');
|
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => 'd645fd4aa610b479e8f4');
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
(()=>{var e,t={189:(e,t,a)=>{"use strict";const r=window.wp.element;function n(){return n=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(e[r]=a[r])}return e},n.apply(this,arguments)}const l=window.React,o=window.wp.apiFetch;var i=a.n(o);const c=window.wp.url,s=window.wp.i18n;var p=a(184),u=a.n(p);function m(e){let{active:t,children:a,page:n,pageClick:l,className:o}=e;const i=u()("wp-block activitypub-pager",o,{current:t});return(0,r.createElement)("a",{className:i,onClick:e=>{e.preventDefault(),!t&&l(n)}},a)}const v={outlined:"outlined",minimal:"minimal"};function f(e){let{compact:t,nextLabel:a,page:n,pageClick:l,perPage:o,prevLabel:i,total:c,variant:s=v.outlined}=e;const p=((e,t)=>{let a=[1,e-2,e-1,e,e+1,e+2,t];a.sort(((e,t)=>e-t)),a=a.filter(((e,a,r)=>e>=1&&e<=t&&r.lastIndexOf(e)===a));for(let e=a.length-2;e>=0;e--)a[e]===a[e+1]&&a.splice(e+1,1);return a})(n,Math.ceil(c/o)),f=u()("alignwide wp-block-query-pagination is-content-justification-space-between is-layout-flex wp-block-query-pagination-is-layout-flex",`is-${s}`,{"is-compact":t});return(0,r.createElement)("nav",{className:f},i&&(0,r.createElement)(m,{key:"prev",page:n-1,pageClick:l,active:1===n,"aria-label":i,className:"wp-block-query-pagination-previous block-editor-block-list__block"},i),!t&&(0,r.createElement)("div",{className:"block-editor-block-list__block wp-block wp-block-query-pagination-numbers"},p.map((e=>(0,r.createElement)(m,{key:e,page:e,pageClick:l,active:e===n,className:"page-numbers"},e)))),a&&(0,r.createElement)(m,{key:"next",page:n+1,pageClick:l,active:n===Math.ceil(c/o),"aria-label":a,className:"wp-block-query-pagination-next block-editor-block-list__block"},a))}const b=window.wp.components,{namespace:d}=window._activityPubOptions;function w(e){let{selectedUser:t,per_page:a,order:o,title:p,page:u,setPage:m,className:v="",followLinks:b=!0,followerData:w=!1}=e;const y="site"===t?0:t,[k,h]=(0,l.useState)([]),[E,O]=(0,l.useState)(0),[x,_]=(0,l.useState)(0),[N,j]=function(){const[e,t]=(0,l.useState)(1);return[e,t]}(),S=u||N,C=m||j,L=(0,r.createInterpolateElement)(/* translators: arrow for previous followers link */
|
(()=>{var e,t={189:(e,t,a)=>{"use strict";const r=window.wp.element;function n(){return n=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(e[r]=a[r])}return e},n.apply(this,arguments)}const l=window.React,o=window.wp.apiFetch;var i=a.n(o);const c=window.wp.url,s=window.wp.i18n;var p=a(184),u=a.n(p);function m(e){let{active:t,children:a,page:n,pageClick:l,className:o}=e;const i=u()("wp-block activitypub-pager",o,{current:t});return(0,r.createElement)("a",{className:i,onClick:e=>{e.preventDefault(),!t&&l(n)}},a)}const v={outlined:"outlined",minimal:"minimal"};function b(e){let{compact:t,nextLabel:a,page:n,pageClick:l,perPage:o,prevLabel:i,total:c,variant:s=v.outlined}=e;const p=((e,t)=>{let a=[1,e-2,e-1,e,e+1,e+2,t];a.sort(((e,t)=>e-t)),a=a.filter(((e,a,r)=>e>=1&&e<=t&&r.lastIndexOf(e)===a));for(let e=a.length-2;e>=0;e--)a[e]===a[e+1]&&a.splice(e+1,1);return a})(n,Math.ceil(c/o)),b=u()("alignwide wp-block-query-pagination is-content-justification-space-between is-layout-flex wp-block-query-pagination-is-layout-flex",`is-${s}`,{"is-compact":t});return(0,r.createElement)("nav",{className:b},i&&(0,r.createElement)(m,{key:"prev",page:n-1,pageClick:l,active:1===n,"aria-label":i,className:"wp-block-query-pagination-previous block-editor-block-list__block"},i),!t&&(0,r.createElement)("div",{className:"block-editor-block-list__block wp-block wp-block-query-pagination-numbers"},p.map((e=>(0,r.createElement)(m,{key:e,page:e,pageClick:l,active:e===n,className:"page-numbers"},e)))),a&&(0,r.createElement)(m,{key:"next",page:n+1,pageClick:l,active:n===Math.ceil(c/o),"aria-label":a,className:"wp-block-query-pagination-next block-editor-block-list__block"},a))}const f=window.wp.components,{namespace:d}=window._activityPubOptions;function w(e){let{selectedUser:t,per_page:a,order:o,title:p,page:u,setPage:m,className:v="",followLinks:f=!0}=e;const w="site"===t?0:t,[y,k]=(0,l.useState)([]),[h,E]=(0,l.useState)(0),[O,x]=(0,l.useState)(0),[_,N]=function(){const[e,t]=(0,l.useState)(1);return[e,t]}(),j=u||_,S=m||N,C=(0,r.createInterpolateElement)(/* translators: arrow for previous followers link */
|
||||||
(0,s.__)("<span>←</span> Less","activitypub"),{span:(0,r.createElement)("span",{class:"wp-block-query-pagination-previous-arrow is-arrow-arrow","aria-hidden":"true"})}),q=(0,r.createInterpolateElement)(/* translators: arrow for next followers link */
|
(0,s.__)("<span>←</span> Less","activitypub"),{span:(0,r.createElement)("span",{class:"wp-block-query-pagination-previous-arrow is-arrow-arrow","aria-hidden":"true"})}),L=(0,r.createInterpolateElement)(/* translators: arrow for next followers link */
|
||||||
(0,s.__)("More <span>→</span>","activitypub"),{span:(0,r.createElement)("span",{class:"wp-block-query-pagination-next-arrow is-arrow-arrow","aria-hidden":"true"})}),P=(e,t)=>{h(e),_(t),O(Math.ceil(t/a))};return(0,l.useEffect)((()=>{if(w&&1===S)return P(w.followers,w.total);const e=function(e,t,a,r){const n=`/${d}/users/${e}/followers`,l={per_page:t,order:a,page:r,context:"full"};return(0,c.addQueryArgs)(n,l)}(y,a,o,S);i()({path:e}).then((e=>P(e.orderedItems,e.totalItems))).catch((()=>{}))}),[y,a,o,S,w]),(0,r.createElement)("div",{className:"activitypub-follower-block "+v},(0,r.createElement)("h3",null,p),(0,r.createElement)("ul",null,k&&k.map((e=>(0,r.createElement)("li",{key:e.url},(0,r.createElement)(g,n({},e,{followLinks:b})))))),E>1&&(0,r.createElement)(f,{page:S,perPage:a,total:x,pageClick:C,nextLabel:q,prevLabel:L,compact:"is-style-compact"===v}))}function g(e){let{name:t,icon:a,url:l,preferredUsername:o,followLinks:i=!0}=e;const c=`@${o}`,s={};return i||(s.onClick=e=>e.preventDefault()),(0,r.createElement)(b.ExternalLink,n({className:"activitypub-link",href:l,title:c},s),(0,r.createElement)("img",{width:"40",height:"40",src:a.url,class:"avatar activitypub-avatar"}),(0,r.createElement)("span",{class:"activitypub-actor"},(0,r.createElement)("strong",{className:"activitypub-name"},t),(0,r.createElement)("span",{class:"sep"},"/"),(0,r.createElement)("span",{class:"activitypub-handle"},c)))}const y=window.wp.domReady;a.n(y)()((()=>{[].forEach.call(document.querySelectorAll(".activitypub-follower-block"),(e=>{const t=JSON.parse(e.dataset.attrs);(0,r.render)((0,r.createElement)(w,t),e)}))}))},184:(e,t)=>{var a;!function(){"use strict";var r={}.hasOwnProperty;function n(){for(var e=[],t=0;t<arguments.length;t++){var a=arguments[t];if(a){var l=typeof a;if("string"===l||"number"===l)e.push(a);else if(Array.isArray(a)){if(a.length){var o=n.apply(null,a);o&&e.push(o)}}else if("object"===l){if(a.toString!==Object.prototype.toString&&!a.toString.toString().includes("[native code]")){e.push(a.toString());continue}for(var i in a)r.call(a,i)&&a[i]&&e.push(i)}}}return e.join(" ")}e.exports?(n.default=n,e.exports=n):void 0===(a=function(){return n}.apply(t,[]))||(e.exports=a)}()}},a={};function r(e){var n=a[e];if(void 0!==n)return n.exports;var l=a[e]={exports:{}};return t[e](l,l.exports,r),l.exports}r.m=t,e=[],r.O=(t,a,n,l)=>{if(!a){var o=1/0;for(p=0;p<e.length;p++){for(var[a,n,l]=e[p],i=!0,c=0;c<a.length;c++)(!1&l||o>=l)&&Object.keys(r.O).every((e=>r.O[e](a[c])))?a.splice(c--,1):(i=!1,l<o&&(o=l));if(i){e.splice(p--,1);var s=n();void 0!==s&&(t=s)}}return t}l=l||0;for(var p=e.length;p>0&&e[p-1][2]>l;p--)e[p]=e[p-1];e[p]=[a,n,l]},r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var a in t)r.o(t,a)&&!r.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={638:0,962:0};r.O.j=t=>0===e[t];var t=(t,a)=>{var n,l,[o,i,c]=a,s=0;if(o.some((t=>0!==e[t]))){for(n in i)r.o(i,n)&&(r.m[n]=i[n]);if(c)var p=c(r)}for(t&&t(a);s<o.length;s++)l=o[s],r.o(e,l)&&e[l]&&e[l][0](),e[l]=0;return r.O(p)},a=globalThis.webpackChunkwordpress_activitypub=globalThis.webpackChunkwordpress_activitypub||[];a.forEach(t.bind(null,0)),a.push=t.bind(null,a.push.bind(a))})();var n=r.O(void 0,[962],(()=>r(189)));n=r.O(n)})();
|
(0,s.__)("More <span>→</span>","activitypub"),{span:(0,r.createElement)("span",{class:"wp-block-query-pagination-next-arrow is-arrow-arrow","aria-hidden":"true"})});return(0,l.useEffect)((()=>{const e=function(e,t,a,r){const n=`/${d}/users/${e}/followers`,l={per_page:t,order:a,page:r,context:"full"};return(0,c.addQueryArgs)(n,l)}(w,a,o,j);i()({path:e}).then((e=>{E(Math.ceil(e.totalItems/a)),x(e.totalItems),k(e.orderedItems)})).catch((e=>console.error(e)))}),[w,a,o,j]),(0,r.createElement)("div",{className:"activitypub-follower-block "+v},(0,r.createElement)("h3",null,p),(0,r.createElement)("ul",null,y&&y.map((e=>(0,r.createElement)("li",{key:e.url},(0,r.createElement)(g,n({},e,{followLinks:f})))))),h>1&&(0,r.createElement)(b,{page:j,perPage:a,total:O,pageClick:S,nextLabel:L,prevLabel:C,compact:"is-style-compact"===v}))}function g(e){let{name:t,icon:a,url:l,preferredUsername:o,followLinks:i=!0}=e;const c=`@${o}`,s={};return i||(s.onClick=e=>e.preventDefault()),(0,r.createElement)(f.ExternalLink,n({className:"activitypub-link",href:l,title:c},s),(0,r.createElement)("img",{width:"40",height:"40",src:a.url,class:"avatar activitypub-avatar"}),(0,r.createElement)("span",{class:"activitypub-actor"},(0,r.createElement)("strong",{className:"activitypub-name"},t),(0,r.createElement)("span",{class:"sep"},"/"),(0,r.createElement)("span",{class:"activitypub-handle"},c)))}const y=window.wp.domReady;a.n(y)()((()=>{[].forEach.call(document.querySelectorAll(".activitypub-follower-block"),(e=>{const t=JSON.parse(e.dataset.attrs);(0,r.render)((0,r.createElement)(w,t),e)}))}))},184:(e,t)=>{var a;!function(){"use strict";var r={}.hasOwnProperty;function n(){for(var e=[],t=0;t<arguments.length;t++){var a=arguments[t];if(a){var l=typeof a;if("string"===l||"number"===l)e.push(a);else if(Array.isArray(a)){if(a.length){var o=n.apply(null,a);o&&e.push(o)}}else if("object"===l){if(a.toString!==Object.prototype.toString&&!a.toString.toString().includes("[native code]")){e.push(a.toString());continue}for(var i in a)r.call(a,i)&&a[i]&&e.push(i)}}}return e.join(" ")}e.exports?(n.default=n,e.exports=n):void 0===(a=function(){return n}.apply(t,[]))||(e.exports=a)}()}},a={};function r(e){var n=a[e];if(void 0!==n)return n.exports;var l=a[e]={exports:{}};return t[e](l,l.exports,r),l.exports}r.m=t,e=[],r.O=(t,a,n,l)=>{if(!a){var o=1/0;for(p=0;p<e.length;p++){for(var[a,n,l]=e[p],i=!0,c=0;c<a.length;c++)(!1&l||o>=l)&&Object.keys(r.O).every((e=>r.O[e](a[c])))?a.splice(c--,1):(i=!1,l<o&&(o=l));if(i){e.splice(p--,1);var s=n();void 0!==s&&(t=s)}}return t}l=l||0;for(var p=e.length;p>0&&e[p-1][2]>l;p--)e[p]=e[p-1];e[p]=[a,n,l]},r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var a in t)r.o(t,a)&&!r.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={638:0,962:0};r.O.j=t=>0===e[t];var t=(t,a)=>{var n,l,[o,i,c]=a,s=0;if(o.some((t=>0!==e[t]))){for(n in i)r.o(i,n)&&(r.m[n]=i[n]);if(c)var p=c(r)}for(t&&t(a);s<o.length;s++)l=o[s],r.o(e,l)&&e[l]&&e[l][0](),e[l]=0;return r.O(p)},a=globalThis.webpackChunkwordpress_activitypub=globalThis.webpackChunkwordpress_activitypub||[];a.forEach(t.bind(null,0)),a.push=t.bind(null,a.push.bind(a))})();var n=r.O(void 0,[962],(()=>r(189)));n=r.O(n)})();
|
|
@ -41,9 +41,6 @@
|
||||||
],
|
],
|
||||||
"lint": [
|
"lint": [
|
||||||
"vendor/bin/phpcs -n -q"
|
"vendor/bin/phpcs -n -q"
|
||||||
],
|
|
||||||
"lint:fix": [
|
|
||||||
"vendor/bin/phpcbf"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,7 @@ class Activity extends Base_Object {
|
||||||
'schema' => 'http://schema.org#',
|
'schema' => 'http://schema.org#',
|
||||||
'pt' => 'https://joinpeertube.org/ns#',
|
'pt' => 'https://joinpeertube.org/ns#',
|
||||||
'toot' => 'http://joinmastodon.org/ns#',
|
'toot' => 'http://joinmastodon.org/ns#',
|
||||||
'webfinger' => 'https://webfinger.net/#',
|
|
||||||
'litepub' => 'http://litepub.social/ns#',
|
'litepub' => 'http://litepub.social/ns#',
|
||||||
'lemmy' => 'https://join-lemmy.org/ns#',
|
|
||||||
'value' => 'schema:value',
|
'value' => 'schema:value',
|
||||||
'Hashtag' => 'as:Hashtag',
|
'Hashtag' => 'as:Hashtag',
|
||||||
'featured' => array(
|
'featured' => array(
|
||||||
|
@ -39,19 +37,8 @@ class Activity extends Base_Object {
|
||||||
'@id' => 'toot:featuredTags',
|
'@id' => 'toot:featuredTags',
|
||||||
'@type' => '@id',
|
'@type' => '@id',
|
||||||
),
|
),
|
||||||
'alsoKnownAs' => array(
|
|
||||||
'@id' => 'as:alsoKnownAs',
|
|
||||||
'@type' => '@id',
|
|
||||||
),
|
|
||||||
'moderators' => array(
|
|
||||||
'@id' => 'lemmy:moderators',
|
|
||||||
'@type' => '@id',
|
|
||||||
),
|
|
||||||
'postingRestrictedToMods' => 'lemmy:postingRestrictedToMods',
|
|
||||||
'discoverable' => 'toot:discoverable',
|
'discoverable' => 'toot:discoverable',
|
||||||
'indexable' => 'toot:indexable',
|
|
||||||
'sensitive' => 'as:sensitive',
|
'sensitive' => 'as:sensitive',
|
||||||
'resource' => 'webfinger:resource',
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -81,7 +68,7 @@ class Activity extends Base_Object {
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-context
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-context
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* | ObjectType
|
* | Base_Object
|
||||||
* | Link
|
* | Link
|
||||||
* | null
|
* | null
|
||||||
*/
|
*/
|
||||||
|
@ -95,7 +82,7 @@ class Activity extends Base_Object {
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-object-term
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-object-term
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* | Base_Objectr
|
* | Base_Object
|
||||||
* | Link
|
* | Link
|
||||||
* | null
|
* | null
|
||||||
*/
|
*/
|
||||||
|
@ -110,7 +97,7 @@ class Activity extends Base_Object {
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-actor
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-actor
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* | \ActivityPhp\Type\Extended\AbstractActor
|
* | Actor
|
||||||
* | array<Actor>
|
* | array<Actor>
|
||||||
* | array<Link>
|
* | array<Link>
|
||||||
* | Link
|
* | Link
|
||||||
|
@ -129,8 +116,8 @@ class Activity extends Base_Object {
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-target
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-target
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* | ObjectType
|
* | Base_Object
|
||||||
* | array<ObjectType>
|
* | array<Base_Object>
|
||||||
* | Link
|
* | Link
|
||||||
* | array<Link>
|
* | array<Link>
|
||||||
*/
|
*/
|
||||||
|
@ -145,7 +132,7 @@ class Activity extends Base_Object {
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-result
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-result
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* | ObjectType
|
* | Base_Object
|
||||||
* | Link
|
* | Link
|
||||||
* | null
|
* | null
|
||||||
*/
|
*/
|
||||||
|
@ -162,7 +149,7 @@ class Activity extends Base_Object {
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-origin
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-origin
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* | ObjectType
|
* | Base_Object
|
||||||
* | Link
|
* | Link
|
||||||
* | null
|
* | null
|
||||||
*/
|
*/
|
||||||
|
@ -175,7 +162,7 @@ class Activity extends Base_Object {
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-instrument
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-instrument
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* | ObjectType
|
* | Base_Object
|
||||||
* | Link
|
* | Link
|
||||||
* | null
|
* | null
|
||||||
*/
|
*/
|
||||||
|
@ -189,7 +176,7 @@ class Activity extends Base_Object {
|
||||||
*
|
*
|
||||||
* @see https://www.w3.org/TR/activitypub/#object-without-create
|
* @see https://www.w3.org/TR/activitypub/#object-without-create
|
||||||
*
|
*
|
||||||
* @param string|Base_Objectr|Link|null $object
|
* @param string|Base_Object|Link|null $object
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -49,9 +49,9 @@ class Base_Object {
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-attachment
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-attachment
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* | ObjectType
|
* | Base_Object
|
||||||
* | Link
|
* | Link
|
||||||
* | array<ObjectType>
|
* | array<Base_Object>
|
||||||
* | array<Link>
|
* | array<Link>
|
||||||
* | null
|
* | null
|
||||||
*/
|
*/
|
||||||
|
@ -65,9 +65,9 @@ class Base_Object {
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-attributedto
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-attributedto
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* | ObjectType
|
* | Base_Object
|
||||||
* | Link
|
* | Link
|
||||||
* | array<ObjectType>
|
* | array<Base_Object>
|
||||||
* | array<Link>
|
* | array<Link>
|
||||||
* | null
|
* | null
|
||||||
*/
|
*/
|
||||||
|
@ -80,9 +80,9 @@ class Base_Object {
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-audience
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-audience
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* | ObjectType
|
* | Base_Object
|
||||||
* | Link
|
* | Link
|
||||||
* | array<ObjectType>
|
* | array<Base_Object>
|
||||||
* | array<Link>
|
* | array<Link>
|
||||||
* | null
|
* | null
|
||||||
*/
|
*/
|
||||||
|
@ -115,7 +115,7 @@ class Base_Object {
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-context
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-context
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* | ObjectType
|
* | Base_Object
|
||||||
* | Link
|
* | Link
|
||||||
* | null
|
* | null
|
||||||
*/
|
*/
|
||||||
|
@ -210,9 +210,9 @@ class Base_Object {
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-inreplyto
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-inreplyto
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* | ObjectType
|
* | Base_Object
|
||||||
* | Link
|
* | Link
|
||||||
* | array<ObjectType>
|
* | array<Base_Object>
|
||||||
* | array<Link>
|
* | array<Link>
|
||||||
* | null
|
* | null
|
||||||
*/
|
*/
|
||||||
|
@ -225,9 +225,9 @@ class Base_Object {
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-location
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-location
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* | ObjectType
|
* | Base_Object
|
||||||
* | Link
|
* | Link
|
||||||
* | array<ObjectType>
|
* | array<Base_Object>
|
||||||
* | array<Link>
|
* | array<Link>
|
||||||
* | null
|
* | null
|
||||||
*/
|
*/
|
||||||
|
@ -239,7 +239,7 @@ class Base_Object {
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-preview
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-preview
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* | ObjectType
|
* | Base_Object
|
||||||
* | Link
|
* | Link
|
||||||
* | null
|
* | null
|
||||||
*/
|
*/
|
||||||
|
@ -287,7 +287,7 @@ class Base_Object {
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-summary
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-summary
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* | ObjectType
|
* | Base_Object
|
||||||
* | Link
|
* | Link
|
||||||
* | null
|
* | null
|
||||||
*/
|
*/
|
||||||
|
@ -313,9 +313,9 @@ class Base_Object {
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-tag
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-tag
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* | ObjectType
|
* | Base_Object
|
||||||
* | Link
|
* | Link
|
||||||
* | array<ObjectType>
|
* | array<Base_Object>
|
||||||
* | array<Link>
|
* | array<Link>
|
||||||
* | null
|
* | null
|
||||||
*/
|
*/
|
||||||
|
@ -348,9 +348,9 @@ class Base_Object {
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-to
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-to
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* | ObjectType
|
* | Base_Object
|
||||||
* | Link
|
* | Link
|
||||||
* | array<ObjectType>
|
* | array<Base_Object>
|
||||||
* | array<Link>
|
* | array<Link>
|
||||||
* | null
|
* | null
|
||||||
*/
|
*/
|
||||||
|
@ -363,9 +363,9 @@ class Base_Object {
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-bto
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-bto
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* | ObjectType
|
* | Base_Object
|
||||||
* | Link
|
* | Link
|
||||||
* | array<ObjectType>
|
* | array<Base_Object>
|
||||||
* | array<Link>
|
* | array<Link>
|
||||||
* | null
|
* | null
|
||||||
*/
|
*/
|
||||||
|
@ -378,9 +378,9 @@ class Base_Object {
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-cc
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-cc
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* | ObjectType
|
* | Base_Object
|
||||||
* | Link
|
* | Link
|
||||||
* | array<ObjectType>
|
* | array<Base_Object>
|
||||||
* | array<Link>
|
* | array<Link>
|
||||||
* | null
|
* | null
|
||||||
*/
|
*/
|
||||||
|
@ -393,9 +393,9 @@ class Base_Object {
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-bcc
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-bcc
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* | ObjectType
|
* | Base_Object
|
||||||
* | Link
|
* | Link
|
||||||
* | array<ObjectType>
|
* | array<Base_Object>
|
||||||
* | array<Link>
|
* | array<Link>
|
||||||
* | null
|
* | null
|
||||||
*/
|
*/
|
||||||
|
@ -433,7 +433,7 @@ class Base_Object {
|
||||||
*
|
*
|
||||||
* @see https://www.w3.org/TR/activitypub/#source-property
|
* @see https://www.w3.org/TR/activitypub/#source-property
|
||||||
*
|
*
|
||||||
* @var ObjectType
|
* @var Base_Object
|
||||||
*/
|
*/
|
||||||
protected $source;
|
protected $source;
|
||||||
|
|
||||||
|
@ -450,7 +450,7 @@ class Base_Object {
|
||||||
|
|
||||||
if ( \strncasecmp( $method, 'get', 3 ) === 0 ) {
|
if ( \strncasecmp( $method, 'get', 3 ) === 0 ) {
|
||||||
if ( ! $this->has( $var ) ) {
|
if ( ! $this->has( $var ) ) {
|
||||||
return new WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
|
return new WP_Error( 'invalid_key', 'Invalid key' );
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->$var;
|
return $this->$var;
|
||||||
|
@ -492,7 +492,7 @@ class Base_Object {
|
||||||
*/
|
*/
|
||||||
public function get( $key ) {
|
public function get( $key ) {
|
||||||
if ( ! $this->has( $key ) ) {
|
if ( ! $this->has( $key ) ) {
|
||||||
return new WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
|
return new WP_Error( 'invalid_key', 'Invalid key' );
|
||||||
}
|
}
|
||||||
|
|
||||||
return call_user_func( array( $this, 'get_' . $key ) );
|
return call_user_func( array( $this, 'get_' . $key ) );
|
||||||
|
@ -519,7 +519,7 @@ class Base_Object {
|
||||||
*/
|
*/
|
||||||
public function set( $key, $value ) {
|
public function set( $key, $value ) {
|
||||||
if ( ! $this->has( $key ) ) {
|
if ( ! $this->has( $key ) ) {
|
||||||
return new WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
|
return new WP_Error( 'invalid_key', 'Invalid key' );
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->$key = $value;
|
$this->$key = $value;
|
||||||
|
@ -537,7 +537,7 @@ class Base_Object {
|
||||||
*/
|
*/
|
||||||
public function add( $key, $value ) {
|
public function add( $key, $value ) {
|
||||||
if ( ! $this->has( $key ) ) {
|
if ( ! $this->has( $key ) ) {
|
||||||
return new WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
|
return new WP_Error( 'invalid_key', 'Invalid key' );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! isset( $this->$key ) ) {
|
if ( ! isset( $this->$key ) ) {
|
||||||
|
@ -562,10 +562,6 @@ class Base_Object {
|
||||||
public static function init_from_json( $json ) {
|
public static function init_from_json( $json ) {
|
||||||
$array = \json_decode( $json, true );
|
$array = \json_decode( $json, true );
|
||||||
|
|
||||||
if ( ! is_array( $array ) ) {
|
|
||||||
$array = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::init_from_array( $array );
|
return self::init_from_array( $array );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -577,10 +573,6 @@ class Base_Object {
|
||||||
* @return \Activitypub\Activity\Base_Object An Object built from the JSON string.
|
* @return \Activitypub\Activity\Base_Object An Object built from the JSON string.
|
||||||
*/
|
*/
|
||||||
public static function init_from_array( $array ) {
|
public static function init_from_array( $array ) {
|
||||||
if ( ! is_array( $array ) ) {
|
|
||||||
return new WP_Error( 'invalid_array', __( 'Invalid array', 'activitypub' ), array( 'status' => 404 ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
$object = new static();
|
$object = new static();
|
||||||
|
|
||||||
foreach ( $array as $key => $value ) {
|
foreach ( $array as $key => $value ) {
|
||||||
|
@ -644,7 +636,7 @@ class Base_Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
// if value is still empty, ignore it for the array and continue.
|
// if value is still empty, ignore it for the array and continue.
|
||||||
if ( isset( $value ) ) {
|
if ( $value ) {
|
||||||
$array[ snake_to_camel_case( $key ) ] = $value;
|
$array[ snake_to_camel_case( $key ) ] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Inspired by the PHP ActivityPub Library by @Landrok
|
|
||||||
*
|
|
||||||
* @link https://github.com/landrok/activitypub
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Activitypub\Activity;
|
|
||||||
|
|
||||||
use Activitypub\Activity\Base_Object;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Event is an implementation of one of the
|
|
||||||
* Activity Streams Event object type
|
|
||||||
*
|
|
||||||
* The Object is the primary base type for the Activity Streams
|
|
||||||
* vocabulary.
|
|
||||||
*
|
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event
|
|
||||||
*/
|
|
||||||
class Note extends Base_Object {
|
|
||||||
protected $type = 'Event';
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Inspired by the PHP ActivityPub Library by @Landrok
|
|
||||||
*
|
|
||||||
* @link https://github.com/landrok/activitypub
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Activitypub\Activity;
|
|
||||||
|
|
||||||
use Activitypub\Activity\Base_Object;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Note is an implementation of one of the
|
|
||||||
* Activity Streams Note object type
|
|
||||||
*
|
|
||||||
* The Object is the primary base type for the Activity Streams
|
|
||||||
* vocabulary.
|
|
||||||
*
|
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-note
|
|
||||||
*/
|
|
||||||
class Note extends Base_Object {
|
|
||||||
protected $type = 'Note';
|
|
||||||
}
|
|
|
@ -5,7 +5,7 @@ use WP_Post;
|
||||||
use Activitypub\Activity\Activity;
|
use Activitypub\Activity\Activity;
|
||||||
use Activitypub\Collection\Users;
|
use Activitypub\Collection\Users;
|
||||||
use Activitypub\Collection\Followers;
|
use Activitypub\Collection\Followers;
|
||||||
use Activitypub\Transformer\Transformers_Manager;
|
use Activitypub\Transformer\Post;
|
||||||
|
|
||||||
use function Activitypub\is_single_user;
|
use function Activitypub\is_single_user;
|
||||||
use function Activitypub\is_user_disabled;
|
use function Activitypub\is_user_disabled;
|
||||||
|
@ -65,8 +65,7 @@ class Activity_Dispatcher {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$transformer = Transformers_Manager::instance()->get_transformer( $wp_post );
|
$object = Post::transform( $wp_post )->to_object();
|
||||||
$object = $transformer->to_object();
|
|
||||||
|
|
||||||
$activity = new Activity();
|
$activity = new Activity();
|
||||||
$activity->set_type( $type );
|
$activity->set_type( $type );
|
||||||
|
@ -102,8 +101,7 @@ class Activity_Dispatcher {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$transformer = Transformers_Manager::instance()->get_transformer( $wp_post );
|
$object = Post::transform( $wp_post )->to_object();
|
||||||
$object = $transformer->to_object();
|
|
||||||
|
|
||||||
$activity = new Activity();
|
$activity = new Activity();
|
||||||
$activity->set_type( 'Announce' );
|
$activity->set_type( 'Announce' );
|
||||||
|
|
|
@ -17,12 +17,11 @@ class Activitypub {
|
||||||
\add_filter( 'template_include', array( self::class, 'render_json_template' ), 99 );
|
\add_filter( 'template_include', array( self::class, 'render_json_template' ), 99 );
|
||||||
\add_filter( 'query_vars', array( self::class, 'add_query_vars' ) );
|
\add_filter( 'query_vars', array( self::class, 'add_query_vars' ) );
|
||||||
\add_filter( 'pre_get_avatar_data', array( self::class, 'pre_get_avatar_data' ), 11, 2 );
|
\add_filter( 'pre_get_avatar_data', array( self::class, 'pre_get_avatar_data' ), 11, 2 );
|
||||||
\add_filter( 'get_comment_link', array( self::class, 'remote_comment_link' ), 11, 3 );
|
|
||||||
|
|
||||||
// Add support for ActivityPub to custom post types
|
// Add support for ActivityPub to custom post types
|
||||||
$transformer_mapping = \get_option( 'activitypub_transformer_mapping', array( 'post' => 'activitypub/default', 'page' => 'activitypub/default' ) ) ? \get_option( 'activitypub_transformer_mapping', array( 'post' => 'activitypub/default', 'page' => 'activitypub/default' ) ) : array();
|
$post_types = \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) ) ? \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) ) : array();
|
||||||
|
|
||||||
foreach ( array_keys( $transformer_mapping ) as $post_type ) {
|
foreach ( $post_types as $post_type ) {
|
||||||
\add_post_type_support( $post_type, 'activitypub' );
|
\add_post_type_support( $post_type, 'activitypub' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +97,7 @@ class Activitypub {
|
||||||
$json_template = ACTIVITYPUB_PLUGIN_DIR . '/templates/blog-json.php';
|
$json_template = ACTIVITYPUB_PLUGIN_DIR . '/templates/blog-json.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ACTIVITYPUB_AUTHORIZED_FETCH ) {
|
if ( ACTIVITYPUB_SECURE_MODE ) {
|
||||||
$verification = Signature::verify_http_signature( $_SERVER );
|
$verification = Signature::verify_http_signature( $_SERVER );
|
||||||
if ( \is_wp_error( $verification ) ) {
|
if ( \is_wp_error( $verification ) ) {
|
||||||
// fallback as template_loader can't return http headers
|
// fallback as template_loader can't return http headers
|
||||||
|
@ -180,22 +179,6 @@ class Activitypub {
|
||||||
return \get_comment_meta( $comment->comment_ID, 'avatar_url', true );
|
return \get_comment_meta( $comment->comment_ID, 'avatar_url', true );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Link remote comments to source url.
|
|
||||||
*
|
|
||||||
* @param string $comment_link
|
|
||||||
* @param object|WP_Comment $comment
|
|
||||||
*
|
|
||||||
* @return string $url
|
|
||||||
*/
|
|
||||||
public static function remote_comment_link( $comment_link, $comment ) {
|
|
||||||
$remote_comment_link = get_comment_meta( $comment->comment_ID, 'source_url', true );
|
|
||||||
if ( $remote_comment_link ) {
|
|
||||||
$comment_link = esc_url( $remote_comment_link );
|
|
||||||
}
|
|
||||||
return $comment_link;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store permalink in meta, to send delete Activity.
|
* Store permalink in meta, to send delete Activity.
|
||||||
*
|
*
|
||||||
|
@ -227,12 +210,6 @@ class Activitypub {
|
||||||
* Add rewrite rules
|
* Add rewrite rules
|
||||||
*/
|
*/
|
||||||
public static function add_rewrite_rules() {
|
public static function add_rewrite_rules() {
|
||||||
// If another system needs to take precedence over the ActivityPub rewrite rules,
|
|
||||||
// they can define their own and will manually call the appropriate functions as required.
|
|
||||||
if ( ACTIVITYPUB_DISABLE_REWRITES ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! \class_exists( 'Webfinger' ) ) {
|
if ( ! \class_exists( 'Webfinger' ) ) {
|
||||||
\add_rewrite_rule(
|
\add_rewrite_rule(
|
||||||
'^.well-known/webfinger',
|
'^.well-known/webfinger',
|
||||||
|
@ -252,13 +229,12 @@ class Activitypub {
|
||||||
'index.php?rest_route=/' . ACTIVITYPUB_REST_NAMESPACE . '/nodeinfo2',
|
'index.php?rest_route=/' . ACTIVITYPUB_REST_NAMESPACE . '/nodeinfo2',
|
||||||
'top'
|
'top'
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
\add_rewrite_rule(
|
\add_rewrite_rule(
|
||||||
'^@([\w\-\.]+)',
|
'^@([\w\-\.]+)',
|
||||||
'index.php?rest_route=/' . ACTIVITYPUB_REST_NAMESPACE . '/users/$matches[1]',
|
'index.php?rest_route=/' . ACTIVITYPUB_REST_NAMESPACE . '/users/$matches[1]',
|
||||||
'top'
|
'top'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
\add_rewrite_endpoint( 'activitypub', EP_AUTHORS | EP_PERMALINK | EP_PAGES );
|
\add_rewrite_endpoint( 'activitypub', EP_AUTHORS | EP_PERMALINK | EP_PAGES );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Activitypub;
|
namespace Activitypub;
|
||||||
|
|
||||||
use WP_User_Query;
|
|
||||||
use Activitypub\Model\Blog_User;
|
|
||||||
use Activitypub\Base\Transformer\Base as Transformer_Base;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub Admin Class
|
* ActivityPub Admin Class
|
||||||
*
|
*
|
||||||
|
@ -23,15 +19,6 @@ class Admin {
|
||||||
if ( ! is_user_disabled( get_current_user_id() ) ) {
|
if ( ! is_user_disabled( get_current_user_id() ) ) {
|
||||||
\add_action( 'show_user_profile', array( self::class, 'add_profile' ) );
|
\add_action( 'show_user_profile', array( self::class, 'add_profile' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
add_filter(
|
|
||||||
'activitypub/transformers/is_transformer_enabled',
|
|
||||||
function( $should_register, Transformer_Base $transformer_instance ) {
|
|
||||||
return ! Options::is_transformer_disabled( $transformer_instance->get_name() );
|
|
||||||
},
|
|
||||||
10,
|
|
||||||
2
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -164,47 +151,14 @@ class Admin {
|
||||||
'default' => '0',
|
'default' => '0',
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
\register_setting(
|
||||||
/**
|
|
||||||
* Flexible activation of post_types together with mapping ActivityPub transformers.
|
|
||||||
*
|
|
||||||
* If a post-type is not mapped to any ActivtiyPub transformer it means it is not activated
|
|
||||||
* for ActivityPub federation.
|
|
||||||
*
|
|
||||||
* @since version_number_transformer_management_placeholder
|
|
||||||
*/
|
|
||||||
register_setting(
|
|
||||||
'activitypub',
|
'activitypub',
|
||||||
'activitypub_transformer_mapping',
|
'activitypub_support_post_types',
|
||||||
array(
|
array(
|
||||||
'type' => 'array',
|
|
||||||
'default' => array(
|
|
||||||
'post' => 'note',
|
|
||||||
),
|
|
||||||
'show_in_rest' => array(
|
|
||||||
'schema' => array(
|
|
||||||
'type' => 'array',
|
|
||||||
'items' => array(
|
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
),
|
'description' => \esc_html__( 'Enable ActivityPub support for post types', 'activitypub' ),
|
||||||
),
|
'show_in_rest' => true,
|
||||||
),
|
'default' => array( 'post', 'pages' ),
|
||||||
'sanitize_callback' => function ( $value ) {
|
|
||||||
// Check if $value is an array
|
|
||||||
if ( ! is_array( $value ) ) {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
$value_keys = array_keys( $value );
|
|
||||||
|
|
||||||
$all_public_post_types = \get_post_types( array( 'public' => true ), 'names' );
|
|
||||||
|
|
||||||
// Unset the keys that are missing in $keysToCheck
|
|
||||||
foreach ( array_diff( $value_keys, $all_public_post_types ) as $missing_key ) {
|
|
||||||
unset( $value[ $missing_key ] );
|
|
||||||
}
|
|
||||||
// var_dump($value);
|
|
||||||
return $value;
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
\register_setting(
|
\register_setting(
|
||||||
|
@ -214,7 +168,7 @@ class Admin {
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'description' => \esc_html__( 'The Identifier of the Blog-User', 'activitypub' ),
|
'description' => \esc_html__( 'The Identifier of the Blog-User', 'activitypub' ),
|
||||||
'show_in_rest' => true,
|
'show_in_rest' => true,
|
||||||
'default' => Blog_User::get_default_username(),
|
'default' => \Activitypub\Model\Blog_User::get_default_username(),
|
||||||
'sanitize_callback' => function( $value ) {
|
'sanitize_callback' => function( $value ) {
|
||||||
// hack to allow dots in the username
|
// hack to allow dots in the username
|
||||||
$parts = explode( '.', $value );
|
$parts = explode( '.', $value );
|
||||||
|
@ -224,31 +178,7 @@ class Admin {
|
||||||
$sanitized[] = \sanitize_title( $part );
|
$sanitized[] = \sanitize_title( $part );
|
||||||
}
|
}
|
||||||
|
|
||||||
$sanitized = implode( '.', $sanitized );
|
return implode( '.', $sanitized );
|
||||||
|
|
||||||
// check for login or nicename.
|
|
||||||
$user = new WP_User_Query(
|
|
||||||
array(
|
|
||||||
'search' => $sanitized,
|
|
||||||
'search_columns' => array( 'user_login', 'user_nicename' ),
|
|
||||||
'number' => 1,
|
|
||||||
'hide_empty' => true,
|
|
||||||
'fields' => 'ID',
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( $user->results ) {
|
|
||||||
add_settings_error(
|
|
||||||
'activitypub_blog_user_identifier',
|
|
||||||
'activitypub_blog_user_identifier',
|
|
||||||
\esc_html__( 'You cannot use an existing author\'s name for the blog profile ID.', 'activitypub' ),
|
|
||||||
'error'
|
|
||||||
);
|
|
||||||
|
|
||||||
return Blog_User::get_default_username();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $sanitized;
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
namespace Activitypub;
|
namespace Activitypub;
|
||||||
|
|
||||||
use Activitypub\Collection\Followers;
|
use Activitypub\Collection\Followers;
|
||||||
use Activitypub\Collection\Users as User_Collection;
|
|
||||||
use Activitypub\is_user_type_disabled;
|
use Activitypub\is_user_type_disabled;
|
||||||
|
|
||||||
class Blocks {
|
class Blocks {
|
||||||
|
@ -14,9 +13,7 @@ class Blocks {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function add_data() {
|
public static function add_data() {
|
||||||
$context = is_admin() ? 'editor' : 'view';
|
$handle = is_admin() ? 'activitypub-followers-editor-script' : 'activitypub-followers-view-script';
|
||||||
$followers_handle = 'activitypub-followers-' . $context . '-script';
|
|
||||||
$follow_me_handle = 'activitypub-follow-me-' . $context . '-script';
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'namespace' => ACTIVITYPUB_REST_NAMESPACE,
|
'namespace' => ACTIVITYPUB_REST_NAMESPACE,
|
||||||
'enabled' => array(
|
'enabled' => array(
|
||||||
|
@ -25,8 +22,7 @@ class Blocks {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
$js = sprintf( 'var _activityPubOptions = %s;', wp_json_encode( $data ) );
|
$js = sprintf( 'var _activityPubOptions = %s;', wp_json_encode( $data ) );
|
||||||
\wp_add_inline_script( $followers_handle, $js, 'before' );
|
\wp_add_inline_script( $handle, $js, 'before' );
|
||||||
\wp_add_inline_script( $follow_me_handle, $js, 'before' );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function register_blocks() {
|
public static function register_blocks() {
|
||||||
|
@ -36,12 +32,6 @@ class Blocks {
|
||||||
'render_callback' => array( self::class, 'render_follower_block' ),
|
'render_callback' => array( self::class, 'render_follower_block' ),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
\register_block_type_from_metadata(
|
|
||||||
ACTIVITYPUB_PLUGIN_DIR . '/build/follow-me',
|
|
||||||
array(
|
|
||||||
'render_callback' => array( self::class, 'render_follow_me_block' ),
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function get_user_id( $user_string ) {
|
private static function get_user_id( $user_string ) {
|
||||||
|
@ -52,56 +42,11 @@ class Blocks {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static function render_follower_block( $attrs, $content, $block ) {
|
||||||
* Filter an array by a list of keys.
|
|
||||||
* @param array $array The array to filter.
|
|
||||||
* @param array $keys The keys to keep.
|
|
||||||
* @return array The filtered array.
|
|
||||||
*/
|
|
||||||
protected static function filter_array_by_keys( $array, $keys ) {
|
|
||||||
return array_intersect_key( $array, array_flip( $keys ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render the follow me block.
|
|
||||||
* @param array $attrs The block attributes.
|
|
||||||
* @return string The HTML to render.
|
|
||||||
*/
|
|
||||||
public static function render_follow_me_block( $attrs ) {
|
|
||||||
$user_id = self::get_user_id( $attrs['selectedUser'] );
|
|
||||||
$user = User_Collection::get_by_id( $user_id );
|
|
||||||
if ( ! is_wp_error( $user ) ) {
|
|
||||||
$attrs['profileData'] = self::filter_array_by_keys(
|
|
||||||
$user->to_array(),
|
|
||||||
array( 'icon', 'name', 'resource' )
|
|
||||||
);
|
|
||||||
}
|
|
||||||
$wrapper_attributes = get_block_wrapper_attributes(
|
|
||||||
array(
|
|
||||||
'aria-label' => __( 'Follow me on the Fediverse', 'activitypub' ),
|
|
||||||
'class' => 'activitypub-follow-me-block-wrapper',
|
|
||||||
'data-attrs' => wp_json_encode( $attrs ),
|
|
||||||
)
|
|
||||||
);
|
|
||||||
// todo: render more than an empty div?
|
|
||||||
return '<div ' . $wrapper_attributes . '></div>';
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function render_follower_block( $attrs ) {
|
|
||||||
$followee_user_id = self::get_user_id( $attrs['selectedUser'] );
|
$followee_user_id = self::get_user_id( $attrs['selectedUser'] );
|
||||||
$per_page = absint( $attrs['per_page'] );
|
$per_page = absint( $attrs['per_page'] );
|
||||||
$follower_data = Followers::get_followers_with_count( $followee_user_id, $per_page );
|
$followers = Followers::get_followers( $followee_user_id, $per_page );
|
||||||
|
$title = $attrs['title'];
|
||||||
$attrs['followerData']['total'] = $follower_data['total'];
|
|
||||||
$attrs['followerData']['followers'] = array_map(
|
|
||||||
function( $follower ) {
|
|
||||||
return self::filter_array_by_keys(
|
|
||||||
$follower->to_array(),
|
|
||||||
array( 'icon', 'name', 'preferredUsername', 'url' )
|
|
||||||
);
|
|
||||||
},
|
|
||||||
$follower_data['followers']
|
|
||||||
);
|
|
||||||
$wrapper_attributes = get_block_wrapper_attributes(
|
$wrapper_attributes = get_block_wrapper_attributes(
|
||||||
array(
|
array(
|
||||||
'aria-label' => __( 'Fediverse Followers', 'activitypub' ),
|
'aria-label' => __( 'Fediverse Followers', 'activitypub' ),
|
||||||
|
@ -110,12 +55,12 @@ class Blocks {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$html = '<div ' . $wrapper_attributes . '>';
|
$html = '<div class="activitypub-follower-block" ' . $wrapper_attributes . '>';
|
||||||
if ( $attrs['title'] ) {
|
if ( $title ) {
|
||||||
$html .= '<h3>' . esc_html( $attrs['title'] ) . '</h3>';
|
$html .= '<h3>' . $title . '</h3>';
|
||||||
}
|
}
|
||||||
$html .= '<ul>';
|
$html .= '<ul>';
|
||||||
foreach ( $follower_data['followers'] as $follower ) {
|
foreach ( $followers as $follower ) {
|
||||||
$html .= '<li>' . self::render_follower( $follower ) . '</li>';
|
$html .= '<li>' . self::render_follower( $follower ) . '</li>';
|
||||||
}
|
}
|
||||||
// We are only pagination on the JS side. Could be revisited but we gotta ship!
|
// We are only pagination on the JS side. Could be revisited but we gotta ship!
|
||||||
|
|
|
@ -43,60 +43,38 @@ class Hashtag {
|
||||||
* @return string the filtered post-content
|
* @return string the filtered post-content
|
||||||
*/
|
*/
|
||||||
public static function the_content( $the_content ) {
|
public static function the_content( $the_content ) {
|
||||||
// small protection against execution timeouts: limit to 1 MB
|
$protected_tags = array();
|
||||||
if ( mb_strlen( $the_content ) > MB_IN_BYTES ) {
|
$protect = function( $m ) use ( &$protected_tags ) {
|
||||||
return $the_content;
|
$c = \wp_rand( 100000, 999999 );
|
||||||
|
$protect = '!#!#PROTECT' . $c . '#!#!';
|
||||||
|
while ( isset( $protected_tags[ $protect ] ) ) {
|
||||||
|
$c = \wp_rand( 100000, 999999 );
|
||||||
|
$protect = '!#!#PROTECT' . $c . '#!#!';
|
||||||
}
|
}
|
||||||
$tag_stack = array();
|
$protected_tags[ $protect ] = $m[0];
|
||||||
$protected_tags = array(
|
return $protect;
|
||||||
'pre',
|
};
|
||||||
'code',
|
$the_content = preg_replace_callback(
|
||||||
'textarea',
|
'#<!\[CDATA\[.*?\]\]>#is',
|
||||||
'style',
|
$protect,
|
||||||
'a',
|
$the_content
|
||||||
|
);
|
||||||
|
$the_content = preg_replace_callback(
|
||||||
|
'#<(pre|code|textarea|style)\b[^>]*>.*?</\1[^>]*>#is',
|
||||||
|
$protect,
|
||||||
|
$the_content
|
||||||
|
);
|
||||||
|
$the_content = preg_replace_callback(
|
||||||
|
'#<[^>]+>#i',
|
||||||
|
$protect,
|
||||||
|
$the_content
|
||||||
);
|
);
|
||||||
$content_with_links = '';
|
|
||||||
$in_protected_tag = false;
|
|
||||||
foreach ( wp_html_split( $the_content ) as $chunk ) {
|
|
||||||
if ( preg_match( '#^<!--[\s\S]*-->$#i', $chunk, $m ) ) {
|
|
||||||
$content_with_links .= $chunk;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( preg_match( '#^<(/)?([a-z-]+)\b[^>]*>$#i', $chunk, $m ) ) {
|
$the_content = \preg_replace_callback( '/' . ACTIVITYPUB_HASHTAGS_REGEXP . '/i', array( '\Activitypub\Hashtag', 'replace_with_links' ), $the_content );
|
||||||
$tag = strtolower( $m[2] );
|
|
||||||
if ( '/' === $m[1] ) {
|
|
||||||
// Closing tag.
|
|
||||||
$i = array_search( $tag, $tag_stack );
|
|
||||||
// We can only remove the tag from the stack if it is in the stack.
|
|
||||||
if ( false !== $i ) {
|
|
||||||
$tag_stack = array_slice( $tag_stack, 0, $i );
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Opening tag, add it to the stack.
|
|
||||||
$tag_stack[] = $tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we're in a protected tag, the tag_stack contains at least one protected tag string.
|
$the_content = str_replace( array_reverse( array_keys( $protected_tags ) ), array_reverse( array_values( $protected_tags ) ), $the_content );
|
||||||
// The protected tag state can only change when we encounter a start or end tag.
|
|
||||||
$in_protected_tag = array_intersect( $tag_stack, $protected_tags );
|
|
||||||
|
|
||||||
// Never inspect tags.
|
return $the_content;
|
||||||
$content_with_links .= $chunk;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $in_protected_tag ) {
|
|
||||||
// Don't inspect a chunk inside an inspected tag.
|
|
||||||
$content_with_links .= $chunk;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only reachable when there is no protected tag in the stack.
|
|
||||||
$content_with_links .= \preg_replace_callback( '/' . ACTIVITYPUB_HASHTAGS_REGEXP . '/i', array( '\Activitypub\Hashtag', 'replace_with_links' ), $chunk );
|
|
||||||
}
|
|
||||||
|
|
||||||
return $content_with_links;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -111,7 +89,7 @@ class Hashtag {
|
||||||
|
|
||||||
if ( $tag_object ) {
|
if ( $tag_object ) {
|
||||||
$link = \get_term_link( $tag_object, 'post_tag' );
|
$link = \get_term_link( $tag_object, 'post_tag' );
|
||||||
return \sprintf( '<a rel="tag" class="hashtag u-tag u-category" href="%s">#%s</a>', $link, $tag );
|
return \sprintf( '<a rel="tag" class="u-tag u-category" href="%s">#%s</a>', $link, $tag );
|
||||||
}
|
}
|
||||||
|
|
||||||
return '#' . $tag;
|
return '#' . $tag;
|
||||||
|
|
|
@ -1,14 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Activitypub;
|
namespace Activitypub;
|
||||||
|
|
||||||
use WP_Error;
|
|
||||||
use Activitypub\Webfinger;
|
|
||||||
use Activitypub\Collection\Users;
|
|
||||||
|
|
||||||
use function Activitypub\get_plugin_version;
|
|
||||||
use function Activitypub\is_user_type_disabled;
|
|
||||||
use function Activitypub\get_webfinger_resource;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub Health_Check Class
|
* ActivityPub Health_Check Class
|
||||||
*
|
*
|
||||||
|
@ -27,23 +19,16 @@ class Health_Check {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function add_tests( $tests ) {
|
public static function add_tests( $tests ) {
|
||||||
if ( ! is_user_type_disabled( 'user' ) ) {
|
|
||||||
$tests['direct']['activitypub_test_author_url'] = array(
|
$tests['direct']['activitypub_test_author_url'] = array(
|
||||||
'label' => \__( 'Author URL test', 'activitypub' ),
|
'label' => \__( 'Author URL test', 'activitypub' ),
|
||||||
'test' => array( self::class, 'test_author_url' ),
|
'test' => array( self::class, 'test_author_url' ),
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
$tests['direct']['activitypub_test_webfinger'] = array(
|
$tests['direct']['activitypub_test_webfinger'] = array(
|
||||||
'label' => __( 'WebFinger Test', 'activitypub' ),
|
'label' => __( 'WebFinger Test', 'activitypub' ),
|
||||||
'test' => array( self::class, 'test_webfinger' ),
|
'test' => array( self::class, 'test_webfinger' ),
|
||||||
);
|
);
|
||||||
|
|
||||||
$tests['direct']['activitypub_test_system_cron'] = array(
|
|
||||||
'label' => __( 'System Cron Test', 'activitypub' ),
|
|
||||||
'test' => array( self::class, 'test_system_cron' ),
|
|
||||||
);
|
|
||||||
|
|
||||||
return $tests;
|
return $tests;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,49 +70,6 @@ class Health_Check {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* System Cron tests
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function test_system_cron() {
|
|
||||||
$result = array(
|
|
||||||
'label' => \__( 'System Task Scheduler configured', 'activitypub' ),
|
|
||||||
'status' => 'good',
|
|
||||||
'badge' => array(
|
|
||||||
'label' => \__( 'ActivityPub', 'activitypub' ),
|
|
||||||
'color' => 'green',
|
|
||||||
),
|
|
||||||
'description' => \sprintf(
|
|
||||||
'<p>%s</p>',
|
|
||||||
\esc_html__( 'You seem to use the System Task Scheduler to process WP_Cron tasks.', 'activitypub' )
|
|
||||||
),
|
|
||||||
'actions' => '',
|
|
||||||
'test' => 'test_system_cron',
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) {
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
$result['status'] = 'recommended';
|
|
||||||
$result['label'] = \__( 'System Task Scheduler not configured', 'activitypub' );
|
|
||||||
$result['badge']['color'] = 'orange';
|
|
||||||
$result['description'] = \sprintf(
|
|
||||||
'<p>%s</p>',
|
|
||||||
\__( 'Enhance your WordPress site’s performance and mitigate potential heavy loads caused by plugins like ActivityPub by setting up a system cron job to run WP Cron. This ensures scheduled tasks are executed consistently and reduces the reliance on website traffic for trigger events.', 'activitypub' )
|
|
||||||
);
|
|
||||||
$result['actions'] .= sprintf(
|
|
||||||
'<p><a href="%s" target="_blank" rel="noopener">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
|
|
||||||
__( 'https://developer.wordpress.org/plugins/cron/hooking-wp-cron-into-the-system-task-scheduler/', 'activitypub' ),
|
|
||||||
__( 'Learn how to hook the WP-Cron into the System Task Scheduler.', 'activitypub' ),
|
|
||||||
/* translators: Hidden accessibility text. */
|
|
||||||
__( '(opens in a new tab)', 'activitypub' )
|
|
||||||
);
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WebFinger tests
|
* WebFinger tests
|
||||||
*
|
*
|
||||||
|
@ -169,7 +111,7 @@ class Health_Check {
|
||||||
/**
|
/**
|
||||||
* Check if `author_posts_url` is accessible and that request returns correct JSON
|
* Check if `author_posts_url` is accessible and that request returns correct JSON
|
||||||
*
|
*
|
||||||
* @return boolean|WP_Error
|
* @return boolean|\WP_Error
|
||||||
*/
|
*/
|
||||||
public static function is_author_url_accessible() {
|
public static function is_author_url_accessible() {
|
||||||
$user = \wp_get_current_user();
|
$user = \wp_get_current_user();
|
||||||
|
@ -178,7 +120,7 @@ class Health_Check {
|
||||||
|
|
||||||
// check for "author" in URL
|
// check for "author" in URL
|
||||||
if ( $author_url !== $reference_author_url ) {
|
if ( $author_url !== $reference_author_url ) {
|
||||||
return new WP_Error(
|
return new \WP_Error(
|
||||||
'author_url_not_accessible',
|
'author_url_not_accessible',
|
||||||
\sprintf(
|
\sprintf(
|
||||||
// translators: %s: Author URL
|
// translators: %s: Author URL
|
||||||
|
@ -201,7 +143,7 @@ class Health_Check {
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( \is_wp_error( $response ) ) {
|
if ( \is_wp_error( $response ) ) {
|
||||||
return new WP_Error(
|
return new \WP_Error(
|
||||||
'author_url_not_accessible',
|
'author_url_not_accessible',
|
||||||
\sprintf(
|
\sprintf(
|
||||||
// translators: %s: Author URL
|
// translators: %s: Author URL
|
||||||
|
@ -218,7 +160,7 @@ class Health_Check {
|
||||||
|
|
||||||
// check for redirects
|
// check for redirects
|
||||||
if ( \in_array( $response_code, array( 301, 302, 307, 308 ), true ) ) {
|
if ( \in_array( $response_code, array( 301, 302, 307, 308 ), true ) ) {
|
||||||
return new WP_Error(
|
return new \WP_Error(
|
||||||
'author_url_not_accessible',
|
'author_url_not_accessible',
|
||||||
\sprintf(
|
\sprintf(
|
||||||
// translators: %s: Author URL
|
// translators: %s: Author URL
|
||||||
|
@ -235,7 +177,7 @@ class Health_Check {
|
||||||
$body = \wp_remote_retrieve_body( $response );
|
$body = \wp_remote_retrieve_body( $response );
|
||||||
|
|
||||||
if ( ! \is_string( $body ) || ! \is_array( \json_decode( $body, true ) ) ) {
|
if ( ! \is_string( $body ) || ! \is_array( \json_decode( $body, true ) ) ) {
|
||||||
return new WP_Error(
|
return new \WP_Error(
|
||||||
'author_url_not_accessible',
|
'author_url_not_accessible',
|
||||||
\sprintf(
|
\sprintf(
|
||||||
// translators: %s: Author URL
|
// translators: %s: Author URL
|
||||||
|
@ -254,20 +196,13 @@ class Health_Check {
|
||||||
/**
|
/**
|
||||||
* Check if WebFinger endpoint is accessible and profile request returns correct JSON
|
* Check if WebFinger endpoint is accessible and profile request returns correct JSON
|
||||||
*
|
*
|
||||||
* @return boolean|WP_Error
|
* @return boolean|\WP_Error
|
||||||
*/
|
*/
|
||||||
public static function is_webfinger_endpoint_accessible() {
|
public static function is_webfinger_endpoint_accessible() {
|
||||||
$user = \wp_get_current_user();
|
$user = \wp_get_current_user();
|
||||||
|
$account = \Activitypub\get_webfinger_resource( $user->ID );
|
||||||
|
|
||||||
if ( ! is_user_type_disabled( 'blog' ) ) {
|
$url = \Activitypub\Webfinger::resolve( $account );
|
||||||
$account = get_webfinger_resource( $user->ID );
|
|
||||||
} elseif ( ! is_user_type_disabled( 'user' ) ) {
|
|
||||||
$account = get_webfinger_resource( Users::BLOG_USER_ID );
|
|
||||||
} else {
|
|
||||||
$account = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$url = Webfinger::resolve( $account );
|
|
||||||
if ( \is_wp_error( $url ) ) {
|
if ( \is_wp_error( $url ) ) {
|
||||||
$allowed = array( 'code' => array() );
|
$allowed = array( 'code' => array() );
|
||||||
$not_accessible = wp_kses(
|
$not_accessible = wp_kses(
|
||||||
|
@ -302,7 +237,7 @@ class Health_Check {
|
||||||
if ( isset( $health_messages[ $url->get_error_code() ] ) ) {
|
if ( isset( $health_messages[ $url->get_error_code() ] ) ) {
|
||||||
$message = $health_messages[ $url->get_error_code() ];
|
$message = $health_messages[ $url->get_error_code() ];
|
||||||
}
|
}
|
||||||
return new WP_Error(
|
return new \WP_Error(
|
||||||
$url->get_error_code(),
|
$url->get_error_code(),
|
||||||
$message,
|
$message,
|
||||||
$url->get_error_data()
|
$url->get_error_data()
|
||||||
|
@ -356,7 +291,7 @@ class Health_Check {
|
||||||
'fields' => array(
|
'fields' => array(
|
||||||
'webfinger' => array(
|
'webfinger' => array(
|
||||||
'label' => __( 'WebFinger Resource', 'activitypub' ),
|
'label' => __( 'WebFinger Resource', 'activitypub' ),
|
||||||
'value' => Webfinger::get_user_resource( wp_get_current_user()->ID ),
|
'value' => \Activitypub\Webfinger::get_user_resource( wp_get_current_user()->ID ),
|
||||||
'private' => true,
|
'private' => true,
|
||||||
),
|
),
|
||||||
'author_url' => array(
|
'author_url' => array(
|
||||||
|
@ -364,11 +299,6 @@ class Health_Check {
|
||||||
'value' => get_author_posts_url( wp_get_current_user()->ID ),
|
'value' => get_author_posts_url( wp_get_current_user()->ID ),
|
||||||
'private' => true,
|
'private' => true,
|
||||||
),
|
),
|
||||||
'plugin_version' => array(
|
|
||||||
'label' => __( 'Plugin Version', 'activitypub' ),
|
|
||||||
'value' => get_plugin_version(),
|
|
||||||
'private' => true,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -52,8 +52,8 @@ class Http {
|
||||||
$response = \wp_safe_remote_post( $url, $args );
|
$response = \wp_safe_remote_post( $url, $args );
|
||||||
$code = \wp_remote_retrieve_response_code( $response );
|
$code = \wp_remote_retrieve_response_code( $response );
|
||||||
|
|
||||||
if ( $code >= 400 ) {
|
if ( 400 <= $code && 500 >= $code ) {
|
||||||
$response = new WP_Error( $code, __( 'Failed HTTP Request', 'activitypub' ), array( 'status' => $code ) );
|
$response = new WP_Error( $code, __( 'Failed HTTP Request', 'activitypub' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
\do_action( 'activitypub_safe_remote_post_response', $response, $url, $body, $user_id );
|
\do_action( 'activitypub_safe_remote_post_response', $response, $url, $body, $user_id );
|
||||||
|
@ -100,8 +100,8 @@ class Http {
|
||||||
$response = \wp_safe_remote_get( $url, $args );
|
$response = \wp_safe_remote_get( $url, $args );
|
||||||
$code = \wp_remote_retrieve_response_code( $response );
|
$code = \wp_remote_retrieve_response_code( $response );
|
||||||
|
|
||||||
if ( $code >= 400 ) {
|
if ( 400 <= $code && 500 >= $code ) {
|
||||||
$response = new WP_Error( $code, __( 'Failed HTTP Request', 'activitypub' ), array( 'status' => $code ) );
|
$response = new WP_Error( $code, __( 'Failed HTTP Request', 'activitypub' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
\do_action( 'activitypub_safe_remote_get_response', $response, $url );
|
\do_action( 'activitypub_safe_remote_get_response', $response, $url );
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
namespace Activitypub;
|
namespace Activitypub;
|
||||||
|
|
||||||
use WP_Error;
|
use WP_Error;
|
||||||
use Activitypub\Webfinger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub Mention Class
|
* ActivityPub Mention Class
|
||||||
|
@ -26,60 +25,44 @@ class Mention {
|
||||||
* @return string the filtered post-content
|
* @return string the filtered post-content
|
||||||
*/
|
*/
|
||||||
public static function the_content( $the_content ) {
|
public static function the_content( $the_content ) {
|
||||||
// small protection against execution timeouts: limit to 1 MB
|
$protected_tags = array();
|
||||||
if ( mb_strlen( $the_content ) > MB_IN_BYTES ) {
|
$protect = function( $m ) use ( &$protected_tags ) {
|
||||||
return $the_content;
|
$c = \wp_rand( 100000, 999999 );
|
||||||
|
$protect = '!#!#PROTECT' . $c . '#!#!';
|
||||||
|
while ( isset( $protected_tags[ $protect ] ) ) {
|
||||||
|
$c = \wp_rand( 100000, 999999 );
|
||||||
|
$protect = '!#!#PROTECT' . $c . '#!#!';
|
||||||
}
|
}
|
||||||
$tag_stack = array();
|
$protected_tags[ $protect ] = $m[0];
|
||||||
$protected_tags = array(
|
return $protect;
|
||||||
'pre',
|
};
|
||||||
'code',
|
$the_content = preg_replace_callback(
|
||||||
'textarea',
|
'#<!\[CDATA\[.*?\]\]>#is',
|
||||||
'style',
|
$protect,
|
||||||
'a',
|
$the_content
|
||||||
|
);
|
||||||
|
$the_content = preg_replace_callback(
|
||||||
|
'#<(pre|code|textarea|style)\b[^>]*>.*?</\1[^>]*>#is',
|
||||||
|
$protect,
|
||||||
|
$the_content
|
||||||
|
);
|
||||||
|
$the_content = preg_replace_callback(
|
||||||
|
'#<a.*?href=[^>]+>.*?</a>#i',
|
||||||
|
$protect,
|
||||||
|
$the_content
|
||||||
);
|
);
|
||||||
$content_with_links = '';
|
|
||||||
$in_protected_tag = false;
|
|
||||||
foreach ( wp_html_split( $the_content ) as $chunk ) {
|
|
||||||
if ( preg_match( '#^<!--[\s\S]*-->$#i', $chunk, $m ) ) {
|
|
||||||
$content_with_links .= $chunk;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( preg_match( '#^<(/)?([a-z-]+)\b[^>]*>$#i', $chunk, $m ) ) {
|
$the_content = preg_replace_callback(
|
||||||
$tag = strtolower( $m[2] );
|
'#<img.*?[^>]+>#i',
|
||||||
if ( '/' === $m[1] ) {
|
$protect,
|
||||||
// Closing tag.
|
$the_content
|
||||||
$i = array_search( $tag, $tag_stack );
|
);
|
||||||
// We can only remove the tag from the stack if it is in the stack.
|
|
||||||
if ( false !== $i ) {
|
|
||||||
$tag_stack = array_slice( $tag_stack, 0, $i );
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Opening tag, add it to the stack.
|
|
||||||
$tag_stack[] = $tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we're in a protected tag, the tag_stack contains at least one protected tag string.
|
$the_content = \preg_replace_callback( '/@' . ACTIVITYPUB_USERNAME_REGEXP . '/', array( self::class, 'replace_with_links' ), $the_content );
|
||||||
// The protected tag state can only change when we encounter a start or end tag.
|
|
||||||
$in_protected_tag = array_intersect( $tag_stack, $protected_tags );
|
|
||||||
|
|
||||||
// Never inspect tags.
|
$the_content = str_replace( array_reverse( array_keys( $protected_tags ) ), array_reverse( array_values( $protected_tags ) ), $the_content );
|
||||||
$content_with_links .= $chunk;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $in_protected_tag ) {
|
return $the_content;
|
||||||
// Don't inspect a chunk inside an inspected tag.
|
|
||||||
$content_with_links .= $chunk;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only reachable when there is no protected tag in the stack.
|
|
||||||
$content_with_links .= \preg_replace_callback( '/@' . ACTIVITYPUB_USERNAME_REGEXP . '/', array( self::class, 'replace_with_links' ), $chunk );
|
|
||||||
}
|
|
||||||
|
|
||||||
return $content_with_links;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -91,8 +74,7 @@ class Mention {
|
||||||
*/
|
*/
|
||||||
public static function replace_with_links( $result ) {
|
public static function replace_with_links( $result ) {
|
||||||
$metadata = get_remote_metadata_by_actor( $result[0] );
|
$metadata = get_remote_metadata_by_actor( $result[0] );
|
||||||
|
if ( ! is_wp_error( $metadata ) && ! empty( $metadata['url'] ) ) {
|
||||||
if ( ! empty( $metadata ) && ! is_wp_error( $metadata ) && ! empty( $metadata['url'] ) ) {
|
|
||||||
$username = ltrim( $result[0], '@' );
|
$username = ltrim( $result[0], '@' );
|
||||||
if ( ! empty( $metadata['name'] ) ) {
|
if ( ! empty( $metadata['name'] ) ) {
|
||||||
$username = $metadata['name'];
|
$username = $metadata['name'];
|
||||||
|
|
|
@ -4,7 +4,6 @@ namespace Activitypub;
|
||||||
use Activitypub\Activitypub;
|
use Activitypub\Activitypub;
|
||||||
use Activitypub\Model\Blog_User;
|
use Activitypub\Model\Blog_User;
|
||||||
use Activitypub\Collection\Followers;
|
use Activitypub\Collection\Followers;
|
||||||
use Activitypub\Admin;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub Migration Class
|
* ActivityPub Migration Class
|
||||||
|
@ -115,30 +114,12 @@ class Migration {
|
||||||
if ( version_compare( $version_from_db, '1.0.0', '<' ) ) {
|
if ( version_compare( $version_from_db, '1.0.0', '<' ) ) {
|
||||||
self::migrate_from_0_17();
|
self::migrate_from_0_17();
|
||||||
}
|
}
|
||||||
if ( version_compare( $version_from_db, 'version_number_transformer_management_placeholder', '<' ) ) {
|
|
||||||
self::migrate_from_version_number_transformer_management_placeholder();
|
|
||||||
}
|
|
||||||
|
|
||||||
update_option( 'activitypub_db_version', self::get_target_version() );
|
update_option( 'activitypub_db_version', self::get_target_version() );
|
||||||
|
|
||||||
self::unlock();
|
self::unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the supported post type settings to the mapped transformer setting.
|
|
||||||
* TODO: Test this
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
private static function migrate_from_version_number_transformer_management_placeholder() {
|
|
||||||
$supported_post_types = \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) );
|
|
||||||
Admin::register_settings();
|
|
||||||
$transformer_mapping = array();
|
|
||||||
foreach ( $supported_post_types as $supported_post_type ) {
|
|
||||||
$transformer_mapping[ $supported_post_type ] = ACTIVITYPUB_DEFAULT_TRANSFORMER;
|
|
||||||
}
|
|
||||||
update_option( 'activitypub_transformer_mapping', $transformer_mapping );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the DB-schema of the followers-list
|
* Updates the DB-schema of the followers-list
|
||||||
*
|
*
|
||||||
|
|
136
includes/class-sanitizer.php
Normal file
|
@ -0,0 +1,136 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Activitypub;
|
||||||
|
|
||||||
|
class Sanitizer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sanitize a multi-dimensional array
|
||||||
|
*
|
||||||
|
* @param array $array The array to sanitize.
|
||||||
|
*
|
||||||
|
* @return array The sanitized array.
|
||||||
|
*/
|
||||||
|
public static function sanitize_array( $array ) {
|
||||||
|
$sanitized_array = array();
|
||||||
|
|
||||||
|
foreach ( $array as $key => $value ) {
|
||||||
|
$key = self::sanitize_key( $key );
|
||||||
|
|
||||||
|
if (
|
||||||
|
in_array(
|
||||||
|
$key,
|
||||||
|
array(
|
||||||
|
'summary_map',
|
||||||
|
'summaryMap',
|
||||||
|
'content_map',
|
||||||
|
'contentMap',
|
||||||
|
),
|
||||||
|
true
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
$sanitized_array[ $key ] = self::sanitize_map( $value );
|
||||||
|
} elseif (
|
||||||
|
in_array(
|
||||||
|
$key,
|
||||||
|
array(
|
||||||
|
'inbox',
|
||||||
|
'outbox',
|
||||||
|
'followers',
|
||||||
|
'following',
|
||||||
|
),
|
||||||
|
true
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
if ( is_string( $value ) ) {
|
||||||
|
$sanitized_array[ $key ] = sanitize_url( $value );
|
||||||
|
} else {
|
||||||
|
$sanitized_array[ $key ] = '';
|
||||||
|
}
|
||||||
|
} elseif ( in_array( $key, array( 'summary', 'content' ), true ) ) {
|
||||||
|
$sanitized_array[ $key ] = self::sanitize_html( $value );
|
||||||
|
} elseif ( is_array( $value ) ) {
|
||||||
|
$sanitized_array[ $key ] = self::sanitize_array( $value );
|
||||||
|
} else {
|
||||||
|
$sanitized_array[ $key ] = self::sanitize_value( $value );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $sanitized_array;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sanitize a value.
|
||||||
|
*
|
||||||
|
* @param string $value The value to sanitize.
|
||||||
|
*
|
||||||
|
* @return string The sanitized value.
|
||||||
|
*/
|
||||||
|
public static function sanitize_value( $value ) {
|
||||||
|
if ( is_email( $value ) ) {
|
||||||
|
return sanitize_email( $value );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( filter_var( $value, FILTER_VALIDATE_URL ) ) {
|
||||||
|
return sanitize_url( $value );
|
||||||
|
}
|
||||||
|
|
||||||
|
return sanitize_text_field( $value );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sanitize HTML.
|
||||||
|
*
|
||||||
|
* @param string $value The value to sanitize.
|
||||||
|
*
|
||||||
|
* @return string The sanitized value.
|
||||||
|
*/
|
||||||
|
public static function sanitize_html( $value ) {
|
||||||
|
if ( is_array( $value ) ) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
global $allowedtags;
|
||||||
|
$tags = array_merge(
|
||||||
|
$allowedtags,
|
||||||
|
array( 'p' => array() )
|
||||||
|
);
|
||||||
|
|
||||||
|
$value = \preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $value );
|
||||||
|
$value = \strip_shortcodes( $value );
|
||||||
|
$value = \wptexturize( $value );
|
||||||
|
$value = \wp_kses( $value, $tags );
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sanitize a translation map
|
||||||
|
*
|
||||||
|
* @param array $map The map to sanitize.
|
||||||
|
*
|
||||||
|
* @return array The sanitized map.
|
||||||
|
*/
|
||||||
|
public static function sanitize_map( $map ) {
|
||||||
|
$sanitized_map = array();
|
||||||
|
|
||||||
|
foreach ( $map as $key => $value ) {
|
||||||
|
$key = self::sanitize_key( $key );
|
||||||
|
|
||||||
|
$sanitized_map[ $key ] = self::sanitize_html( $value );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $sanitized_map;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sanitize an array key
|
||||||
|
*
|
||||||
|
* @param string $key The key to sanitize.
|
||||||
|
*
|
||||||
|
* @return string The sanitized key.
|
||||||
|
*/
|
||||||
|
public static function sanitize_key( $key ) {
|
||||||
|
return \preg_replace( '/[^a-zA-Z0-9_\-]/', '', $key );
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ namespace Activitypub;
|
||||||
|
|
||||||
use Activitypub\Collection\Users;
|
use Activitypub\Collection\Users;
|
||||||
use Activitypub\Collection\Followers;
|
use Activitypub\Collection\Followers;
|
||||||
|
use Activitypub\Transformer\Post;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub Scheduler Class
|
* ActivityPub Scheduler Class
|
||||||
|
@ -104,16 +105,10 @@ class Scheduler {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function update_followers() {
|
public static function update_followers() {
|
||||||
$number = 5;
|
$followers = Followers::get_outdated_followers();
|
||||||
|
|
||||||
if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) {
|
|
||||||
$number = 50;
|
|
||||||
}
|
|
||||||
|
|
||||||
$followers = Followers::get_outdated_followers( $number );
|
|
||||||
|
|
||||||
foreach ( $followers as $follower ) {
|
foreach ( $followers as $follower ) {
|
||||||
$meta = get_remote_metadata_by_actor( $follower->get_url(), false );
|
$meta = get_remote_metadata_by_actor( $follower->get_url(), true );
|
||||||
|
|
||||||
if ( empty( $meta ) || ! is_array( $meta ) || is_wp_error( $meta ) ) {
|
if ( empty( $meta ) || ! is_array( $meta ) || is_wp_error( $meta ) ) {
|
||||||
Followers::add_error( $follower->get__id(), $meta );
|
Followers::add_error( $follower->get__id(), $meta );
|
||||||
|
@ -130,16 +125,10 @@ class Scheduler {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function cleanup_followers() {
|
public static function cleanup_followers() {
|
||||||
$number = 5;
|
$followers = Followers::get_faulty_followers();
|
||||||
|
|
||||||
if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) {
|
|
||||||
$number = 50;
|
|
||||||
}
|
|
||||||
|
|
||||||
$followers = Followers::get_faulty_followers( $number );
|
|
||||||
|
|
||||||
foreach ( $followers as $follower ) {
|
foreach ( $followers as $follower ) {
|
||||||
$meta = get_remote_metadata_by_actor( $follower->get_url(), false );
|
$meta = get_remote_metadata_by_actor( $follower->get_url(), true );
|
||||||
|
|
||||||
if ( is_tombstone( $meta ) ) {
|
if ( is_tombstone( $meta ) ) {
|
||||||
$follower->delete();
|
$follower->delete();
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Activitypub;
|
namespace Activitypub;
|
||||||
|
|
||||||
use function Activitypub\esc_hashtag;
|
|
||||||
|
|
||||||
class Shortcodes {
|
class Shortcodes {
|
||||||
/**
|
/**
|
||||||
* Register the shortcodes
|
* Class constructor, registering WordPress then Shortcodes
|
||||||
*/
|
*/
|
||||||
public static function register() {
|
public static function init() {
|
||||||
|
// do not load on admin pages
|
||||||
|
if ( is_admin() ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ( get_class_methods( self::class ) as $shortcode ) {
|
foreach ( get_class_methods( self::class ) as $shortcode ) {
|
||||||
if ( 'init' !== $shortcode ) {
|
if ( 'init' !== $shortcode ) {
|
||||||
add_shortcode( 'ap_' . $shortcode, array( self::class, $shortcode ) );
|
add_shortcode( 'ap_' . $shortcode, array( self::class, $shortcode ) );
|
||||||
|
@ -15,17 +18,6 @@ class Shortcodes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Unregister the shortcodes
|
|
||||||
*/
|
|
||||||
public static function unregister() {
|
|
||||||
foreach ( get_class_methods( self::class ) as $shortcode ) {
|
|
||||||
if ( 'init' !== $shortcode ) {
|
|
||||||
remove_shortcode( 'ap_' . $shortcode );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates output for the 'ap_hashtags' shortcode
|
* Generates output for the 'ap_hashtags' shortcode
|
||||||
*
|
*
|
||||||
|
@ -52,9 +44,9 @@ class Shortcodes {
|
||||||
|
|
||||||
foreach ( $tags as $tag ) {
|
foreach ( $tags as $tag ) {
|
||||||
$hash_tags[] = \sprintf(
|
$hash_tags[] = \sprintf(
|
||||||
'<a rel="tag" class="hashtag u-tag u-category" href="%s">%s</a>',
|
'<a rel="tag" class="u-tag u-category" href="%s">#%s</a>',
|
||||||
\esc_url( \get_tag_link( $tag ) ),
|
\esc_url( \get_tag_link( $tag ) ),
|
||||||
esc_hashtag( $tag->name )
|
\wp_strip_all_tags( $tag->slug )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +112,7 @@ class Shortcodes {
|
||||||
|
|
||||||
/** This filter is documented in wp-includes/post-template.php */
|
/** This filter is documented in wp-includes/post-template.php */
|
||||||
$excerpt = \apply_filters( 'the_content', $excerpt );
|
$excerpt = \apply_filters( 'the_content', $excerpt );
|
||||||
$excerpt = \str_replace( ']]>', ']]>', $excerpt );
|
$excerpt = \str_replace( ']]>', ']]>', $excerpt );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -365,9 +357,9 @@ class Shortcodes {
|
||||||
|
|
||||||
foreach ( $categories as $category ) {
|
foreach ( $categories as $category ) {
|
||||||
$hash_tags[] = \sprintf(
|
$hash_tags[] = \sprintf(
|
||||||
'<a rel="tag" class="hashtag u-tag u-category" href="%s">%s</a>',
|
'<a rel="tag" class="u-tag u-category" href="%s">#%s</a>',
|
||||||
\esc_url( \get_category_link( $category ) ),
|
\esc_url( \get_category_link( $category ) ),
|
||||||
esc_hashtag( $category->name )
|
\wp_strip_all_tags( $category->slug )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,8 +382,7 @@ class Shortcodes {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$author_id = \get_post_field( 'post_author', $item->ID );
|
$name = \get_the_author_meta( 'display_name', $item->post_author );
|
||||||
$name = \get_the_author_meta( 'display_name', $author_id );
|
|
||||||
|
|
||||||
if ( ! $name ) {
|
if ( ! $name ) {
|
||||||
return '';
|
return '';
|
||||||
|
@ -416,8 +407,7 @@ class Shortcodes {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$author_id = \get_post_field( 'post_author', $item->ID );
|
$url = \get_the_author_meta( 'user_url', $item->post_author );
|
||||||
$url = \get_the_author_meta( 'user_url', $author_id );
|
|
||||||
|
|
||||||
if ( ! $url ) {
|
if ( ! $url ) {
|
||||||
return '';
|
return '';
|
||||||
|
|
|
@ -4,7 +4,7 @@ namespace Activitypub;
|
||||||
use WP_Error;
|
use WP_Error;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use DateTimeZone;
|
use DateTimeZone;
|
||||||
use WP_REST_Request;
|
use Activitypub\Model\User;
|
||||||
use Activitypub\Collection\Users;
|
use Activitypub\Collection\Users;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,14 +23,22 @@ class Signature {
|
||||||
*
|
*
|
||||||
* @return mixed The public key.
|
* @return mixed The public key.
|
||||||
*/
|
*/
|
||||||
public static function get_public_key_for( $user_id, $force = false ) {
|
public static function get_public_key( $user_id, $force = false ) {
|
||||||
if ( $force ) {
|
if ( $force ) {
|
||||||
self::generate_key_pair_for( $user_id );
|
self::generate_key_pair( $user_id );
|
||||||
}
|
}
|
||||||
|
|
||||||
$key_pair = self::get_keypair_for( $user_id );
|
if ( User::APPLICATION_USER_ID === $user_id ) {
|
||||||
|
$key = \get_option( 'activitypub_magic_sig_public_key' );
|
||||||
|
} else {
|
||||||
|
$key = \get_user_meta( $user_id, 'magic_sig_public_key', true );
|
||||||
|
}
|
||||||
|
|
||||||
return $key_pair['public_key'];
|
if ( ! $key ) {
|
||||||
|
return self::get_public_key( $user_id, true );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $key;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,32 +49,22 @@ class Signature {
|
||||||
*
|
*
|
||||||
* @return mixed The private key.
|
* @return mixed The private key.
|
||||||
*/
|
*/
|
||||||
public static function get_private_key_for( $user_id, $force = false ) {
|
public static function get_private_key( $user_id, $force = false ) {
|
||||||
if ( $force ) {
|
if ( $force ) {
|
||||||
self::generate_key_pair_for( $user_id );
|
self::generate_key_pair( $user_id );
|
||||||
}
|
}
|
||||||
|
|
||||||
$key_pair = self::get_keypair_for( $user_id );
|
if ( User::APPLICATION_USER_ID === $user_id ) {
|
||||||
|
$key = \get_option( 'activitypub_magic_sig_private_key' );
|
||||||
return $key_pair['private_key'];
|
} else {
|
||||||
|
$key = \get_user_meta( $user_id, 'magic_sig_private_key', true );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
if ( ! $key ) {
|
||||||
* Return the key pair for a given user.
|
return self::get_private_key( $user_id, true );
|
||||||
*
|
|
||||||
* @param int $user_id The WordPress User ID.
|
|
||||||
*
|
|
||||||
* @return array The key pair.
|
|
||||||
*/
|
|
||||||
public static function get_keypair_for( $user_id ) {
|
|
||||||
$option_key = self::get_signature_options_key_for( $user_id );
|
|
||||||
$key_pair = \get_option( $option_key );
|
|
||||||
|
|
||||||
if ( ! $key_pair ) {
|
|
||||||
$key_pair = self::generate_key_pair_for( $user_id );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $key_pair;
|
return $key;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,18 +72,9 @@ class Signature {
|
||||||
*
|
*
|
||||||
* @param int $user_id The WordPress User ID.
|
* @param int $user_id The WordPress User ID.
|
||||||
*
|
*
|
||||||
* @return array The key pair.
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected static function generate_key_pair_for( $user_id ) {
|
public static function generate_key_pair() {
|
||||||
$option_key = self::get_signature_options_key_for( $user_id );
|
|
||||||
$key_pair = self::check_legacy_key_pair_for( $user_id );
|
|
||||||
|
|
||||||
if ( $key_pair ) {
|
|
||||||
\add_option( $option_key, $key_pair );
|
|
||||||
|
|
||||||
return $key_pair;
|
|
||||||
}
|
|
||||||
|
|
||||||
$config = array(
|
$config = array(
|
||||||
'digest_alg' => 'sha512',
|
'digest_alg' => 'sha512',
|
||||||
'private_key_bits' => 2048,
|
'private_key_bits' => 2048,
|
||||||
|
@ -99,78 +88,10 @@ class Signature {
|
||||||
|
|
||||||
$detail = \openssl_pkey_get_details( $key );
|
$detail = \openssl_pkey_get_details( $key );
|
||||||
|
|
||||||
// check if keys are valid
|
|
||||||
if (
|
|
||||||
empty( $priv_key ) || ! is_string( $priv_key ) ||
|
|
||||||
! isset( $detail['key'] ) || ! is_string( $detail['key'] )
|
|
||||||
) {
|
|
||||||
return array(
|
return array(
|
||||||
'private_key' => null,
|
|
||||||
'public_key' => null,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$key_pair = array(
|
|
||||||
'private_key' => $priv_key,
|
'private_key' => $priv_key,
|
||||||
'public_key' => $detail['key'],
|
'public_key' => $detail['key'],
|
||||||
);
|
);
|
||||||
|
|
||||||
// persist keys
|
|
||||||
\add_option( $option_key, $key_pair );
|
|
||||||
|
|
||||||
return $key_pair;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the option key for a given user.
|
|
||||||
*
|
|
||||||
* @param int $user_id The WordPress User ID.
|
|
||||||
*
|
|
||||||
* @return string The option key.
|
|
||||||
*/
|
|
||||||
protected static function get_signature_options_key_for( $user_id ) {
|
|
||||||
$id = $user_id;
|
|
||||||
|
|
||||||
if ( $user_id > 0 ) {
|
|
||||||
$user = \get_userdata( $user_id );
|
|
||||||
// sanatize username because it could include spaces and special chars
|
|
||||||
$id = sanitize_title( $user->user_login );
|
|
||||||
}
|
|
||||||
|
|
||||||
return 'activitypub_keypair_for_' . $id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if there is a legacy key pair
|
|
||||||
*
|
|
||||||
* @param int $user_id The WordPress User ID.
|
|
||||||
*
|
|
||||||
* @return array|bool The key pair or false.
|
|
||||||
*/
|
|
||||||
protected static function check_legacy_key_pair_for( $user_id ) {
|
|
||||||
switch ( $user_id ) {
|
|
||||||
case 0:
|
|
||||||
$public_key = \get_option( 'activitypub_blog_user_public_key' );
|
|
||||||
$private_key = \get_option( 'activitypub_blog_user_private_key' );
|
|
||||||
break;
|
|
||||||
case -1:
|
|
||||||
$public_key = \get_option( 'activitypub_application_user_public_key' );
|
|
||||||
$private_key = \get_option( 'activitypub_application_user_private_key' );
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$public_key = \get_user_meta( $user_id, 'magic_sig_public_key', true );
|
|
||||||
$private_key = \get_user_meta( $user_id, 'magic_sig_private_key', true );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! empty( $public_key ) && is_string( $public_key ) && ! empty( $private_key ) && is_string( $private_key ) ) {
|
|
||||||
return array(
|
|
||||||
'private_key' => $private_key,
|
|
||||||
'public_key' => $public_key,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -186,7 +107,7 @@ class Signature {
|
||||||
*/
|
*/
|
||||||
public static function generate_signature( $user_id, $http_method, $url, $date, $digest = null ) {
|
public static function generate_signature( $user_id, $http_method, $url, $date, $digest = null ) {
|
||||||
$user = Users::get_by_id( $user_id );
|
$user = Users::get_by_id( $user_id );
|
||||||
$key = self::get_private_key_for( $user->get__id() );
|
$key = $user->get__private_key();
|
||||||
|
|
||||||
$url_parts = \wp_parse_url( $url );
|
$url_parts = \wp_parse_url( $url );
|
||||||
|
|
||||||
|
@ -215,6 +136,7 @@ class Signature {
|
||||||
\openssl_sign( $signed_string, $signature, $key, \OPENSSL_ALGO_SHA256 );
|
\openssl_sign( $signed_string, $signature, $key, \OPENSSL_ALGO_SHA256 );
|
||||||
$signature = \base64_encode( $signature ); // phpcs:ignore
|
$signature = \base64_encode( $signature ); // phpcs:ignore
|
||||||
|
|
||||||
|
$user = Users::get_by_id( $user_id );
|
||||||
$key_id = $user->get_url() . '#main-key';
|
$key_id = $user->get_url() . '#main-key';
|
||||||
|
|
||||||
if ( ! empty( $digest ) ) {
|
if ( ! empty( $digest ) ) {
|
||||||
|
@ -227,7 +149,7 @@ class Signature {
|
||||||
/**
|
/**
|
||||||
* Verifies the http signatures
|
* Verifies the http signatures
|
||||||
*
|
*
|
||||||
* @param WP_REST_Request|array $request The request object or $_SERVER array.
|
* @param WP_REQUEST|array $request The request object or $_SERVER array.
|
||||||
*
|
*
|
||||||
* @return mixed A boolean or WP_Error.
|
* @return mixed A boolean or WP_Error.
|
||||||
*/
|
*/
|
||||||
|
@ -239,38 +161,28 @@ class Signature {
|
||||||
} else {
|
} else {
|
||||||
$route = '/' . rest_get_url_prefix() . '/' . ltrim( $request->get_route(), '/' );
|
$route = '/' . rest_get_url_prefix() . '/' . ltrim( $request->get_route(), '/' );
|
||||||
}
|
}
|
||||||
|
|
||||||
// fix route for subdirectory installs
|
|
||||||
$path = \wp_parse_url( \get_home_url(), PHP_URL_PATH );
|
|
||||||
|
|
||||||
if ( \is_string( $path ) ) {
|
|
||||||
$path = trim( $path, '/' );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $path ) {
|
|
||||||
$route = '/' . $path . $route;
|
|
||||||
}
|
|
||||||
|
|
||||||
$headers = $request->get_headers();
|
$headers = $request->get_headers();
|
||||||
|
$actor = isset( json_decode( $request->get_body() )->actor ) ? json_decode( $request->get_body() )->actor : '';
|
||||||
$headers['(request-target)'][0] = strtolower( $request->get_method() ) . ' ' . $route;
|
$headers['(request-target)'][0] = strtolower( $request->get_method() ) . ' ' . $route;
|
||||||
} else {
|
} else {
|
||||||
$request = self::format_server_request( $request );
|
$request = self::format_server_request( $request );
|
||||||
$headers = $request['headers']; // $_SERVER array
|
$headers = $request['headers']; // $_SERVER array
|
||||||
|
$actor = null;
|
||||||
$headers['(request-target)'][0] = strtolower( $headers['request_method'][0] ) . ' ' . $headers['request_uri'][0];
|
$headers['(request-target)'][0] = strtolower( $headers['request_method'][0] ) . ' ' . $headers['request_uri'][0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! isset( $headers['signature'] ) ) {
|
if ( ! isset( $headers['signature'] ) ) {
|
||||||
return new WP_Error( 'activitypub_signature', __( 'Request not signed', 'activitypub' ), array( 'status' => 401 ) );
|
return new WP_Error( 'activitypub_signature', 'Request not signed', array( 'status' => 403 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( array_key_exists( 'signature', $headers ) ) {
|
if ( array_key_exists( 'signature', $headers ) ) {
|
||||||
$signature_block = self::parse_signature_header( $headers['signature'][0] );
|
$signature_block = self::parse_signature_header( $headers['signature'] );
|
||||||
} elseif ( array_key_exists( 'authorization', $headers ) ) {
|
} elseif ( array_key_exists( 'authorization', $headers ) ) {
|
||||||
$signature_block = self::parse_signature_header( $headers['authorization'][0] );
|
$signature_block = self::parse_signature_header( $headers['authorization'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! isset( $signature_block ) || ! $signature_block ) {
|
if ( ! isset( $signature_block ) || ! $signature_block ) {
|
||||||
return new WP_Error( 'activitypub_signature', __( 'Incompatible request signature. keyId and signature are required', 'activitypub' ), array( 'status' => 401 ) );
|
return new WP_Error( 'activitypub_signature', 'Incompatible request signature. keyId and signature are required', array( 'status' => 403 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
$signed_headers = $signature_block['headers'];
|
$signed_headers = $signature_block['headers'];
|
||||||
|
@ -280,12 +192,12 @@ class Signature {
|
||||||
|
|
||||||
$signed_data = self::get_signed_data( $signed_headers, $signature_block, $headers );
|
$signed_data = self::get_signed_data( $signed_headers, $signature_block, $headers );
|
||||||
if ( ! $signed_data ) {
|
if ( ! $signed_data ) {
|
||||||
return new WP_Error( 'activitypub_signature', __( 'Signed request date outside acceptable time window', 'activitypub' ), array( 'status' => 401 ) );
|
return new WP_Error( 'activitypub_signature', 'Signed request date outside acceptable time window', array( 'status' => 403 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
$algorithm = self::get_signature_algorithm( $signature_block );
|
$algorithm = self::get_signature_algorithm( $signature_block );
|
||||||
if ( ! $algorithm ) {
|
if ( ! $algorithm ) {
|
||||||
return new WP_Error( 'activitypub_signature', __( 'Unsupported signature algorithm (only rsa-sha256 and hs2019 are supported)', 'activitypub' ), array( 'status' => 401 ) );
|
return new WP_Error( 'activitypub_signature', 'Unsupported signature algorithm (only rsa-sha256 and hs2019 are supported)', array( 'status' => 403 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( \in_array( 'digest', $signed_headers, true ) && isset( $body ) ) {
|
if ( \in_array( 'digest', $signed_headers, true ) && isset( $body ) ) {
|
||||||
|
@ -301,12 +213,15 @@ class Signature {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( \base64_encode( \hash( $hashalg, $body, true ) ) !== $digest[1] ) { // phpcs:ignore
|
if ( \base64_encode( \hash( $hashalg, $body, true ) ) !== $digest[1] ) { // phpcs:ignore
|
||||||
return new WP_Error( 'activitypub_signature', __( 'Invalid Digest header', 'activitypub' ), array( 'status' => 401 ) );
|
return new WP_Error( 'activitypub_signature', 'Invalid Digest header', array( 'status' => 403 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( $actor ) {
|
||||||
|
$public_key = self::get_remote_key( $actor );
|
||||||
|
} else {
|
||||||
$public_key = self::get_remote_key( $signature_block['keyId'] );
|
$public_key = self::get_remote_key( $signature_block['keyId'] );
|
||||||
|
}
|
||||||
if ( \is_wp_error( $public_key ) ) {
|
if ( \is_wp_error( $public_key ) ) {
|
||||||
return $public_key;
|
return $public_key;
|
||||||
}
|
}
|
||||||
|
@ -314,7 +229,7 @@ class Signature {
|
||||||
$verified = \openssl_verify( $signed_data, $signature_block['signature'], $public_key, $algorithm ) > 0;
|
$verified = \openssl_verify( $signed_data, $signature_block['signature'], $public_key, $algorithm ) > 0;
|
||||||
|
|
||||||
if ( ! $verified ) {
|
if ( ! $verified ) {
|
||||||
return new WP_Error( 'activitypub_signature', __( 'Invalid signature', 'activitypub' ), array( 'status' => 401 ) );
|
return new WP_Error( 'activitypub_signature', 'Invalid signature', array( 'status' => 403 ) );
|
||||||
}
|
}
|
||||||
return $verified;
|
return $verified;
|
||||||
}
|
}
|
||||||
|
@ -324,25 +239,17 @@ class Signature {
|
||||||
*
|
*
|
||||||
* @param string $key_id The URL to the public key.
|
* @param string $key_id The URL to the public key.
|
||||||
*
|
*
|
||||||
* @return WP_Error|string The public key or WP_Error.
|
* @return string The public key.
|
||||||
*/
|
*/
|
||||||
public static function get_remote_key( $key_id ) { // phpcs:ignore
|
public static function get_remote_key( $key_id ) { // phpcs:ignore
|
||||||
$actor = get_remote_metadata_by_actor( strip_fragment_from_url( $key_id ) ); // phpcs:ignore
|
$actor = get_remote_metadata_by_actor( strtok( strip_fragment_from_url( $key_id ), '?' ) ); // phpcs:ignore
|
||||||
if ( \is_wp_error( $actor ) ) {
|
if ( \is_wp_error( $actor ) ) {
|
||||||
return new WP_Error(
|
return $actor;
|
||||||
'activitypub_no_remote_profile_found',
|
|
||||||
__( 'No Profile found or Profile not accessible', 'activitypub' ),
|
|
||||||
array( 'status' => 401 )
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if ( isset( $actor['publicKey']['publicKeyPem'] ) ) {
|
if ( isset( $actor['publicKey']['publicKeyPem'] ) ) {
|
||||||
return \rtrim( $actor['publicKey']['publicKeyPem'] ); // phpcs:ignore
|
return \rtrim( $actor['publicKey']['publicKeyPem'] ); // phpcs:ignore
|
||||||
}
|
}
|
||||||
return new WP_Error(
|
return null;
|
||||||
'activitypub_no_remote_key_found',
|
|
||||||
__( 'No Public-Key found', 'activitypub' ),
|
|
||||||
array( 'status' => 401 )
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -367,31 +274,32 @@ class Signature {
|
||||||
/**
|
/**
|
||||||
* Parses the Signature header
|
* Parses the Signature header
|
||||||
*
|
*
|
||||||
* @param string $signature The signature header.
|
* @param array $header The signature header.
|
||||||
*
|
*
|
||||||
* @return array signature parts
|
* @return array signature parts
|
||||||
*/
|
*/
|
||||||
public static function parse_signature_header( $signature ) {
|
public static function parse_signature_header( $header ) {
|
||||||
$parsed_header = array();
|
$parsed_header = array();
|
||||||
$matches = array();
|
$matches = array();
|
||||||
|
$h_string = \implode( ',', (array) $header[0] );
|
||||||
|
|
||||||
if ( \preg_match( '/keyId="(.*?)"/ism', $signature, $matches ) ) {
|
if ( \preg_match( '/keyId="(.*?)"/ism', $h_string, $matches ) ) {
|
||||||
$parsed_header['keyId'] = trim( $matches[1] );
|
$parsed_header['keyId'] = $matches[1];
|
||||||
}
|
}
|
||||||
if ( \preg_match( '/created=([0-9]*)/ism', $signature, $matches ) ) {
|
if ( \preg_match( '/created=([0-9]*)/ism', $h_string, $matches ) ) {
|
||||||
$parsed_header['(created)'] = trim( $matches[1] );
|
$parsed_header['(created)'] = $matches[1];
|
||||||
}
|
}
|
||||||
if ( \preg_match( '/expires=([0-9]*)/ism', $signature, $matches ) ) {
|
if ( \preg_match( '/expires=([0-9]*)/ism', $h_string, $matches ) ) {
|
||||||
$parsed_header['(expires)'] = trim( $matches[1] );
|
$parsed_header['(expires)'] = $matches[1];
|
||||||
}
|
}
|
||||||
if ( \preg_match( '/algorithm="(.*?)"/ism', $signature, $matches ) ) {
|
if ( \preg_match( '/algorithm="(.*?)"/ism', $h_string, $matches ) ) {
|
||||||
$parsed_header['algorithm'] = trim( $matches[1] );
|
$parsed_header['algorithm'] = $matches[1];
|
||||||
}
|
}
|
||||||
if ( \preg_match( '/headers="(.*?)"/ism', $signature, $matches ) ) {
|
if ( \preg_match( '/headers="(.*?)"/ism', $h_string, $matches ) ) {
|
||||||
$parsed_header['headers'] = \explode( ' ', trim( $matches[1] ) );
|
$parsed_header['headers'] = \explode( ' ', $matches[1] );
|
||||||
}
|
}
|
||||||
if ( \preg_match( '/signature="(.*?)"/ism', $signature, $matches ) ) {
|
if ( \preg_match( '/signature="(.*?)"/ism', $h_string, $matches ) ) {
|
||||||
$parsed_header['signature'] = \base64_decode( preg_replace( '/\s+/', '', trim( $matches[1] ) ) ); // phpcs:ignore
|
$parsed_header['signature'] = \base64_decode( preg_replace( '/\s+/', '', $matches[1] ) ); // phpcs:ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( $parsed_header['signature'] ) && ( $parsed_header['algorithm'] ) && ( ! $parsed_header['headers'] ) ) {
|
if ( ( $parsed_header['signature'] ) && ( $parsed_header['algorithm'] ) && ( ! $parsed_header['headers'] ) ) {
|
||||||
|
@ -404,7 +312,7 @@ class Signature {
|
||||||
/**
|
/**
|
||||||
* Gets the header data from the included pseudo headers
|
* Gets the header data from the included pseudo headers
|
||||||
*
|
*
|
||||||
* @param array $signed_headers The signed headers.
|
* @param array $signed_headers
|
||||||
* @param array $signature_block (pseudo-headers)
|
* @param array $signature_block (pseudo-headers)
|
||||||
* @param array $headers (http headers)
|
* @param array $headers (http headers)
|
||||||
*
|
*
|
||||||
|
|
|
@ -26,7 +26,7 @@ class Webfinger {
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = Users::get_by_id( $user_id );
|
$user = Users::get_by_id( $user_id );
|
||||||
if ( ! $user || is_wp_error( $user ) ) {
|
if ( ! $user ) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,14 +41,9 @@ class Webfinger {
|
||||||
* @return string|WP_Error The URL or WP_Error
|
* @return string|WP_Error The URL or WP_Error
|
||||||
*/
|
*/
|
||||||
public static function resolve( $resource ) {
|
public static function resolve( $resource ) {
|
||||||
if ( ! $resource ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! preg_match( '/^@?' . ACTIVITYPUB_USERNAME_REGEXP . '$/i', $resource, $m ) ) {
|
if ( ! preg_match( '/^@?' . ACTIVITYPUB_USERNAME_REGEXP . '$/i', $resource, $m ) ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$transient_key = 'activitypub_resolve_' . ltrim( $resource, '@' );
|
$transient_key = 'activitypub_resolve_' . ltrim( $resource, '@' );
|
||||||
|
|
||||||
$link = \get_transient( $transient_key );
|
$link = \get_transient( $transient_key );
|
||||||
|
@ -67,8 +62,8 @@ class Webfinger {
|
||||||
$response = \wp_remote_get(
|
$response = \wp_remote_get(
|
||||||
$url,
|
$url,
|
||||||
array(
|
array(
|
||||||
'headers' => array( 'Accept' => 'application/jrd+json' ),
|
'headers' => array( 'Accept' => 'application/activity+json' ),
|
||||||
'redirection' => 2,
|
'redirection' => 0,
|
||||||
'timeout' => 2,
|
'timeout' => 2,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -99,110 +94,4 @@ class Webfinger {
|
||||||
\set_transient( $transient_key, $link, HOUR_IN_SECONDS ); // Cache the error for a shorter period.
|
\set_transient( $transient_key, $link, HOUR_IN_SECONDS ); // Cache the error for a shorter period.
|
||||||
return $link;
|
return $link;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert a URI string to an identifier and its host.
|
|
||||||
* Automatically adds acct: if it's missing.
|
|
||||||
*
|
|
||||||
* @param string $url The URI (acct:, mailto:, http:, https:)
|
|
||||||
*
|
|
||||||
* @return WP_Error|array Error reaction or array with
|
|
||||||
* identifier and host as values
|
|
||||||
*/
|
|
||||||
public static function get_identifier_and_host( $url ) {
|
|
||||||
// remove leading @
|
|
||||||
$url = ltrim( $url, '@' );
|
|
||||||
|
|
||||||
if ( ! preg_match( '/^([a-zA-Z+]+):/', $url, $match ) ) {
|
|
||||||
$identifier = 'acct:' . $url;
|
|
||||||
$scheme = 'acct';
|
|
||||||
} else {
|
|
||||||
$identifier = $url;
|
|
||||||
$scheme = $match[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
$host = null;
|
|
||||||
|
|
||||||
switch ( $scheme ) {
|
|
||||||
case 'acct':
|
|
||||||
case 'mailto':
|
|
||||||
case 'xmpp':
|
|
||||||
if ( strpos( $identifier, '@' ) !== false ) {
|
|
||||||
$host = substr( $identifier, strpos( $identifier, '@' ) + 1 );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$host = wp_parse_url( $identifier, PHP_URL_HOST );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( empty( $host ) ) {
|
|
||||||
return new WP_Error( 'invalid_identifier', __( 'Invalid Identifier', 'activitypub' ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
return array( $identifier, $host );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the WebFinger data for a given URI
|
|
||||||
*
|
|
||||||
* @param string $identifier The Identifier: <identifier>@<host>
|
|
||||||
* @param string $host The Host: <identifier>@<host>
|
|
||||||
*
|
|
||||||
* @return WP_Error|array Error reaction or array with
|
|
||||||
* identifier and host as values
|
|
||||||
*/
|
|
||||||
public static function get_data( $identifier, $host ) {
|
|
||||||
$webfinger_url = 'https://' . $host . '/.well-known/webfinger?resource=' . rawurlencode( $identifier );
|
|
||||||
|
|
||||||
$response = wp_safe_remote_get(
|
|
||||||
$webfinger_url,
|
|
||||||
array(
|
|
||||||
'headers' => array( 'Accept' => 'application/jrd+json' ),
|
|
||||||
'redirection' => 0,
|
|
||||||
'timeout' => 2,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( is_wp_error( $response ) ) {
|
|
||||||
return new WP_Error( 'webfinger_url_not_accessible', null, $webfinger_url );
|
|
||||||
}
|
|
||||||
|
|
||||||
$body = wp_remote_retrieve_body( $response );
|
|
||||||
|
|
||||||
return json_decode( $body, true );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function get_remote_follow_endpoint( $uri ) {
|
|
||||||
$identifier_and_host = self::get_identifier_and_host( $uri );
|
|
||||||
|
|
||||||
if ( is_wp_error( $identifier_and_host ) ) {
|
|
||||||
return $identifier_and_host;
|
|
||||||
}
|
|
||||||
|
|
||||||
list( $identifier, $host ) = $identifier_and_host;
|
|
||||||
|
|
||||||
$data = self::get_data( $identifier, $host );
|
|
||||||
|
|
||||||
if ( is_wp_error( $data ) ) {
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( empty( $data['links'] ) ) {
|
|
||||||
return new WP_Error( 'webfinger_url_invalid_response', null, $data );
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ( $data['links'] as $link ) {
|
|
||||||
if ( 'http://ostatus.org/schema/1.0/subscribe' === $link['rel'] ) {
|
|
||||||
return $link['template'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new WP_Error( 'webfinger_remote_follow_endpoint_invalid', $data, array( 'status' => 417 ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,7 +160,7 @@ class Followers {
|
||||||
* @param int $user_id The ID of the WordPress User
|
* @param int $user_id The ID of the WordPress User
|
||||||
* @param string $actor The Actor URL
|
* @param string $actor The Actor URL
|
||||||
*
|
*
|
||||||
* @return array|WP_Error The Follower (WP_Post array) or an WP_Error
|
* @return array|WP_Error The Follower (WP_Term array) or an WP_Error
|
||||||
*/
|
*/
|
||||||
public static function add_follower( $user_id, $actor ) {
|
public static function add_follower( $user_id, $actor ) {
|
||||||
$meta = get_remote_metadata_by_actor( $actor );
|
$meta = get_remote_metadata_by_actor( $actor );
|
||||||
|
@ -169,24 +169,29 @@ class Followers {
|
||||||
return $meta;
|
return $meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( empty( $meta ) || ! is_array( $meta ) || is_wp_error( $meta ) ) {
|
$error = null;
|
||||||
return new WP_Error( 'activitypub_invalid_follower', __( 'Invalid Follower', 'activitypub' ), array( 'status' => 400 ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
$follower = new Follower();
|
$follower = new Follower();
|
||||||
|
|
||||||
|
if ( empty( $meta ) || ! is_array( $meta ) || is_wp_error( $meta ) ) {
|
||||||
|
$follower->set_id( $actor );
|
||||||
|
$follower->set_url( $actor );
|
||||||
|
$error = $meta;
|
||||||
|
} else {
|
||||||
$follower->from_array( $meta );
|
$follower->from_array( $meta );
|
||||||
|
|
||||||
$id = $follower->upsert();
|
|
||||||
|
|
||||||
if ( is_wp_error( $id ) ) {
|
|
||||||
return $id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$post_meta = get_post_meta( $id, 'activitypub_user_id' );
|
$follower->upsert();
|
||||||
|
|
||||||
|
$meta = get_post_meta( $follower->get__id(), 'activitypub_user_id' );
|
||||||
|
|
||||||
|
if ( $error ) {
|
||||||
|
self::add_error( $follower->get__id(), $error );
|
||||||
|
}
|
||||||
|
|
||||||
// phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
|
// phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
|
||||||
if ( is_array( $post_meta ) && ! in_array( $user_id, $post_meta ) ) {
|
if ( is_array( $meta ) && ! in_array( $user_id, $meta ) ) {
|
||||||
add_post_meta( $id, 'activitypub_user_id', $user_id );
|
add_post_meta( $follower->get__id(), 'activitypub_user_id', $user_id );
|
||||||
wp_cache_delete( sprintf( self::CACHE_KEY_INBOXES, $user_id ), 'activitypub' );
|
wp_cache_delete( sprintf( self::CACHE_KEY_INBOXES, $user_id ), 'activitypub' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,18 +265,11 @@ class Followers {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// only send minimal data
|
if ( isset( $object['user_id'] ) ) {
|
||||||
$object = array_intersect_key(
|
unset( $object['user_id'] );
|
||||||
$object,
|
}
|
||||||
array_flip(
|
|
||||||
array(
|
unset( $object['@context'] );
|
||||||
'id',
|
|
||||||
'type',
|
|
||||||
'actor',
|
|
||||||
'object',
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$user = Users::get_by_id( $user_id );
|
$user = Users::get_by_id( $user_id );
|
||||||
|
|
||||||
|
@ -284,7 +282,7 @@ class Followers {
|
||||||
$activity->set_object( $object );
|
$activity->set_object( $object );
|
||||||
$activity->set_actor( $user->get_id() );
|
$activity->set_actor( $user->get_id() );
|
||||||
$activity->set_to( $actor );
|
$activity->set_to( $actor );
|
||||||
$activity->set_id( $user->get_id() . '#follow-' . \preg_replace( '~^https?://~', '', $actor ) . '-' . \time() );
|
$activity->set_id( $user->get_id() . '#follow-' . \preg_replace( '~^https?://~', '', $actor ) );
|
||||||
|
|
||||||
$activity = $activity->to_json();
|
$activity = $activity->to_json();
|
||||||
|
|
||||||
|
@ -355,17 +353,7 @@ class Followers {
|
||||||
public static function get_all_followers() {
|
public static function get_all_followers() {
|
||||||
$args = array(
|
$args = array(
|
||||||
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
||||||
'meta_query' => array(
|
'meta_query' => array(),
|
||||||
'relation' => 'AND',
|
|
||||||
array(
|
|
||||||
'key' => 'activitypub_inbox',
|
|
||||||
'compare' => 'EXISTS',
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'key' => 'activitypub_actor_json',
|
|
||||||
'compare' => 'EXISTS',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
return self::get_followers( null, null, null, $args );
|
return self::get_followers( null, null, null, $args );
|
||||||
}
|
}
|
||||||
|
@ -384,19 +372,10 @@ class Followers {
|
||||||
'fields' => 'ids',
|
'fields' => 'ids',
|
||||||
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
||||||
'meta_query' => array(
|
'meta_query' => array(
|
||||||
'relation' => 'AND',
|
|
||||||
array(
|
array(
|
||||||
'key' => 'activitypub_user_id',
|
'key' => 'activitypub_user_id',
|
||||||
'value' => $user_id,
|
'value' => $user_id,
|
||||||
),
|
),
|
||||||
array(
|
|
||||||
'key' => 'activitypub_inbox',
|
|
||||||
'compare' => 'EXISTS',
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'key' => 'activitypub_actor_json',
|
|
||||||
'compare' => 'EXISTS',
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -426,7 +405,6 @@ class Followers {
|
||||||
'fields' => 'ids',
|
'fields' => 'ids',
|
||||||
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
||||||
'meta_query' => array(
|
'meta_query' => array(
|
||||||
'relation' => 'AND',
|
|
||||||
array(
|
array(
|
||||||
'key' => 'activitypub_inbox',
|
'key' => 'activitypub_inbox',
|
||||||
'compare' => 'EXISTS',
|
'compare' => 'EXISTS',
|
||||||
|
@ -435,11 +413,6 @@ class Followers {
|
||||||
'key' => 'activitypub_user_id',
|
'key' => 'activitypub_user_id',
|
||||||
'value' => $user_id,
|
'value' => $user_id,
|
||||||
),
|
),
|
||||||
array(
|
|
||||||
'key' => 'activitypub_inbox',
|
|
||||||
'value' => '',
|
|
||||||
'compare' => '!=',
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -482,7 +455,7 @@ class Followers {
|
||||||
'post_type' => self::POST_TYPE,
|
'post_type' => self::POST_TYPE,
|
||||||
'posts_per_page' => $number,
|
'posts_per_page' => $number,
|
||||||
'orderby' => 'modified',
|
'orderby' => 'modified',
|
||||||
'order' => 'ASC',
|
'order' => 'DESC',
|
||||||
'post_status' => 'any', // 'any' includes 'trash
|
'post_status' => 'any', // 'any' includes 'trash
|
||||||
'date_query' => array(
|
'date_query' => array(
|
||||||
array(
|
array(
|
||||||
|
@ -510,35 +483,16 @@ class Followers {
|
||||||
*
|
*
|
||||||
* @return mixed The Term list of Followers, the format depends on $output.
|
* @return mixed The Term list of Followers, the format depends on $output.
|
||||||
*/
|
*/
|
||||||
public static function get_faulty_followers( $number = 20 ) {
|
public static function get_faulty_followers( $number = 10 ) {
|
||||||
$args = array(
|
$args = array(
|
||||||
'post_type' => self::POST_TYPE,
|
'post_type' => self::POST_TYPE,
|
||||||
'posts_per_page' => $number,
|
'posts_per_page' => $number,
|
||||||
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
||||||
'meta_query' => array(
|
'meta_query' => array(
|
||||||
'relation' => 'OR',
|
|
||||||
array(
|
array(
|
||||||
'key' => 'activitypub_errors',
|
'key' => 'activitypub_errors',
|
||||||
'compare' => 'EXISTS',
|
'compare' => 'EXISTS',
|
||||||
),
|
),
|
||||||
array(
|
|
||||||
'key' => 'activitypub_inbox',
|
|
||||||
'compare' => 'NOT EXISTS',
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'key' => 'activitypub_actor_json',
|
|
||||||
'compare' => 'NOT EXISTS',
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'key' => 'activitypub_inbox',
|
|
||||||
'value' => '',
|
|
||||||
'compare' => '=',
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'key' => 'activitypub_actor_json',
|
|
||||||
'value' => '',
|
|
||||||
'compare' => '=',
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -185,25 +185,4 @@ class Users {
|
||||||
public static function normalize_host( $host ) {
|
public static function normalize_host( $host ) {
|
||||||
return \str_replace( 'www.', '', $host );
|
return \str_replace( 'www.', '', $host );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the User collection.
|
|
||||||
*
|
|
||||||
* @return array The User collection.
|
|
||||||
*/
|
|
||||||
public static function get_collection() {
|
|
||||||
$users = \get_users(
|
|
||||||
array(
|
|
||||||
'capability__in' => array( 'publish_posts' ),
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$return = array();
|
|
||||||
|
|
||||||
foreach ( $users as $user ) {
|
|
||||||
$return[] = User::from_wp_user( $user->ID );
|
|
||||||
}
|
|
||||||
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* ActivityPub implementation for WordPress/PHP functions either missing from older WordPress/PHP versions or not included by default.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if ( ! function_exists( 'str_starts_with' ) ) {
|
|
||||||
/**
|
|
||||||
* Polyfill for `str_starts_with()` function added in PHP 8.0.
|
|
||||||
*
|
|
||||||
* Performs a case-sensitive check indicating if
|
|
||||||
* the haystack begins with needle.
|
|
||||||
*
|
|
||||||
* @param string $haystack The string to search in.
|
|
||||||
* @param string $needle The substring to search for in the `$haystack`.
|
|
||||||
* @return bool True if `$haystack` starts with `$needle`, otherwise false.
|
|
||||||
*/
|
|
||||||
function str_starts_with( $haystack, $needle ) {
|
|
||||||
if ( '' === $needle ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0 === strpos( $haystack, $needle );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! function_exists( 'get_self_link' ) ) {
|
|
||||||
/**
|
|
||||||
* Returns the link for the currently displayed feed.
|
|
||||||
*
|
|
||||||
* @return string Correct link for the atom:self element.
|
|
||||||
*/
|
|
||||||
function get_self_link() {
|
|
||||||
$host = wp_parse_url( home_url() );
|
|
||||||
$path = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
|
|
||||||
return esc_url( apply_filters( 'self_link', set_url_scheme( 'http://' . $host['host'] . $path ) ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! function_exists( 'is_countable' ) ) {
|
|
||||||
/**
|
|
||||||
* Polyfill for `is_countable()` function added in PHP 7.3.
|
|
||||||
*
|
|
||||||
* @param mixed $value The value to check.
|
|
||||||
* @return bool True if `$value` is countable, otherwise false.
|
|
||||||
*/
|
|
||||||
function is_countable( $value ) {
|
|
||||||
return is_array( $value ) || $value instanceof \Countable;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,7 +5,6 @@ use WP_Error;
|
||||||
use Activitypub\Http;
|
use Activitypub\Http;
|
||||||
use Activitypub\Activity\Activity;
|
use Activitypub\Activity\Activity;
|
||||||
use Activitypub\Collection\Followers;
|
use Activitypub\Collection\Followers;
|
||||||
use Activitypub\Collection\Users;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the ActivityPub default JSON-context
|
* Returns the ActivityPub default JSON-context
|
||||||
|
@ -43,7 +42,7 @@ function get_webfinger_resource( $user_id ) {
|
||||||
* @param string $actor The Actor URL.
|
* @param string $actor The Actor URL.
|
||||||
* @param bool $cached If the result should be cached.
|
* @param bool $cached If the result should be cached.
|
||||||
*
|
*
|
||||||
* @return array|WP_Error The Actor profile as array or WP_Error on failure.
|
* @return array The Actor profile as array
|
||||||
*/
|
*/
|
||||||
function get_remote_metadata_by_actor( $actor, $cached = true ) {
|
function get_remote_metadata_by_actor( $actor, $cached = true ) {
|
||||||
$pre = apply_filters( 'pre_get_remote_metadata_by_actor', false, $actor );
|
$pre = apply_filters( 'pre_get_remote_metadata_by_actor', false, $actor );
|
||||||
|
@ -55,7 +54,7 @@ function get_remote_metadata_by_actor( $actor, $cached = true ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! $actor ) {
|
if ( ! $actor ) {
|
||||||
return new WP_Error( 'activitypub_no_valid_actor_identifier', \__( 'The "actor" identifier is not valid', 'activitypub' ), array( 'status' => 404, 'actor' => $actor ) );
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( is_wp_error( $actor ) ) {
|
if ( is_wp_error( $actor ) ) {
|
||||||
|
@ -74,26 +73,33 @@ function get_remote_metadata_by_actor( $actor, $cached = true ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! \wp_http_validate_url( $actor ) ) {
|
if ( ! \wp_http_validate_url( $actor ) ) {
|
||||||
$metadata = new WP_Error( 'activitypub_no_valid_actor_url', \__( 'The "actor" is no valid URL', 'activitypub' ), array( 'status' => 400, 'actor' => $actor ) );
|
$metadata = new \WP_Error( 'activitypub_no_valid_actor_url', \__( 'The "actor" is no valid URL', 'activitypub' ), $actor );
|
||||||
|
\set_transient( $transient_key, $metadata, HOUR_IN_SECONDS ); // Cache the error for a shorter period.
|
||||||
return $metadata;
|
return $metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$short_timeout = function() {
|
||||||
|
return 3;
|
||||||
|
};
|
||||||
|
add_filter( 'activitypub_remote_get_timeout', $short_timeout );
|
||||||
$response = Http::get( $actor );
|
$response = Http::get( $actor );
|
||||||
|
remove_filter( 'activitypub_remote_get_timeout', $short_timeout );
|
||||||
if ( \is_wp_error( $response ) ) {
|
if ( \is_wp_error( $response ) ) {
|
||||||
|
\set_transient( $transient_key, $response, HOUR_IN_SECONDS ); // Cache the error for a shorter period.
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
$metadata = \wp_remote_retrieve_body( $response );
|
$metadata = \wp_remote_retrieve_body( $response );
|
||||||
$metadata = \json_decode( $metadata, true );
|
$metadata = \json_decode( $metadata, true );
|
||||||
|
|
||||||
|
\set_transient( $transient_key, $metadata, WEEK_IN_SECONDS );
|
||||||
|
|
||||||
if ( ! $metadata ) {
|
if ( ! $metadata ) {
|
||||||
$metadata = new WP_Error( 'activitypub_invalid_json', \__( 'No valid JSON data', 'activitypub' ), array( 'status' => 400, 'actor' => $actor ) );
|
$metadata = new \WP_Error( 'activitypub_invalid_json', \__( 'No valid JSON data', 'activitypub' ), $actor );
|
||||||
|
\set_transient( $transient_key, $metadata, HOUR_IN_SECONDS ); // Cache the error for a shorter period.
|
||||||
return $metadata;
|
return $metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
\set_transient( $transient_key, $metadata, WEEK_IN_SECONDS );
|
|
||||||
|
|
||||||
return $metadata;
|
return $metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,43 +232,6 @@ function snake_to_camel_case( $string ) {
|
||||||
return lcfirst( str_replace( '_', '', ucwords( $string, '_' ) ) );
|
return lcfirst( str_replace( '_', '', ucwords( $string, '_' ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Escapes a Tag, to be used as a hashtag.
|
|
||||||
*
|
|
||||||
* @param string $string The string to escape.
|
|
||||||
*
|
|
||||||
* @return string The escaped hastag.
|
|
||||||
*/
|
|
||||||
function esc_hashtag( $string ) {
|
|
||||||
|
|
||||||
$hashtag = \wp_specialchars_decode( $string, ENT_QUOTES );
|
|
||||||
// Remove all characters that are not letters, numbers, or underscores.
|
|
||||||
$hashtag = \preg_replace( '/emoji-regex(*SKIP)(?!)|[^\p{L}\p{Nd}_]+/u', '_', $hashtag );
|
|
||||||
|
|
||||||
// Capitalize every letter that is preceded by an underscore.
|
|
||||||
$hashtag = preg_replace_callback(
|
|
||||||
'/_(.)/',
|
|
||||||
function ( $matches ) {
|
|
||||||
return '' . strtoupper( $matches[1] );
|
|
||||||
},
|
|
||||||
$hashtag
|
|
||||||
);
|
|
||||||
|
|
||||||
// Add a hashtag to the beginning of the string.
|
|
||||||
$hashtag = ltrim( $hashtag, '#' );
|
|
||||||
$hashtag = '#' . $hashtag;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allow defining your own custom hashtag generation rules.
|
|
||||||
*
|
|
||||||
* @param string $hashtag The hashtag to be returned.
|
|
||||||
* @param string $string The original string.
|
|
||||||
*/
|
|
||||||
$hashtag = apply_filters( 'activitypub_esc_hashtag', $hashtag, $string );
|
|
||||||
|
|
||||||
return esc_html( $hashtag );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a request is for an ActivityPub request.
|
* Check if a request is for an ActivityPub request.
|
||||||
*
|
*
|
||||||
|
@ -279,16 +248,6 @@ function is_activitypub_request() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the current post type supports ActivityPub.
|
|
||||||
if ( \is_singular() ) {
|
|
||||||
$queried_object = \get_queried_object();
|
|
||||||
$post_type = \get_post_type( $queried_object );
|
|
||||||
|
|
||||||
if ( ! \post_type_supports( $post_type, 'activitypub' ) ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// One can trigger an ActivityPub request by adding ?activitypub to the URL.
|
// One can trigger an ActivityPub request by adding ?activitypub to the URL.
|
||||||
// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.VariableRedeclaration
|
// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.VariableRedeclaration
|
||||||
global $wp_query;
|
global $wp_query;
|
||||||
|
@ -309,9 +268,8 @@ function is_activitypub_request() {
|
||||||
* and return true when the header includes at least one of the following:
|
* and return true when the header includes at least one of the following:
|
||||||
* - application/activity+json
|
* - application/activity+json
|
||||||
* - application/ld+json
|
* - application/ld+json
|
||||||
* - application/json
|
|
||||||
*/
|
*/
|
||||||
if ( preg_match( '/(application\/(ld\+json|activity\+json|json))/i', $accept ) ) {
|
if ( preg_match( '/(application\/(ld\+json|activity\+json))/', $accept ) ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -420,7 +378,7 @@ function is_user_type_disabled( $type ) {
|
||||||
$return = false;
|
$return = false;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$return = new WP_Error( 'activitypub_wrong_user_type', __( 'Wrong user type', 'activitypub' ), array( 'status' => 400 ) );
|
$return = new WP_Error( 'activitypub_wrong_user_type', __( 'Wrong user type', 'activitypub' ) );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -433,127 +391,31 @@ function is_user_type_disabled( $type ) {
|
||||||
* @return boolean True if the blog is in single-user mode, false otherwise.
|
* @return boolean True if the blog is in single-user mode, false otherwise.
|
||||||
*/
|
*/
|
||||||
function is_single_user() {
|
function is_single_user() {
|
||||||
if (
|
$return = false;
|
||||||
|
|
||||||
|
if ( \defined( 'ACTIVITYPUB_SINGLE_USER_MODE' ) ) {
|
||||||
|
if ( ACTIVITYPUB_SINGLE_USER_MODE ) {
|
||||||
|
$return = true;
|
||||||
|
}
|
||||||
|
} elseif (
|
||||||
false === is_user_type_disabled( 'blog' ) &&
|
false === is_user_type_disabled( 'blog' ) &&
|
||||||
true === is_user_type_disabled( 'user' )
|
true === is_user_type_disabled( 'user' )
|
||||||
) {
|
) {
|
||||||
return true;
|
$return = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ! function_exists( 'get_self_link' ) ) {
|
||||||
/**
|
/**
|
||||||
* Check if a site supports the block editor.
|
* Returns the link for the currently displayed feed.
|
||||||
*
|
*
|
||||||
* @return boolean True if the site supports the block editor, false otherwise.
|
* @return string Correct link for the atom:self element.
|
||||||
*/
|
*/
|
||||||
function site_supports_blocks() {
|
function get_self_link() {
|
||||||
if ( \version_compare( \get_bloginfo( 'version' ), '5.9', '<' ) ) {
|
$host = wp_parse_url( home_url() );
|
||||||
return false;
|
$path = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
|
||||||
|
return esc_url( apply_filters( 'self_link', set_url_scheme( 'http://' . $host['host'] . $path ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! \function_exists( 'register_block_type_from_metadata' ) ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allow plugins to disable block editor support,
|
|
||||||
* thus disabling blocks registered by the ActivityPub plugin.
|
|
||||||
*
|
|
||||||
* @param boolean $supports_blocks True if the site supports the block editor, false otherwise.
|
|
||||||
*/
|
|
||||||
return apply_filters( 'activitypub_site_supports_blocks', true );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if data is valid JSON.
|
|
||||||
*
|
|
||||||
* @param string $data The data to check.
|
|
||||||
*
|
|
||||||
* @return boolean True if the data is JSON, false otherwise.
|
|
||||||
*/
|
|
||||||
function is_json( $data ) {
|
|
||||||
return \is_array( \json_decode( $data, true ) ) ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if a blog is public based on the `blog_public` option
|
|
||||||
*
|
|
||||||
* @return bollean True if public, false if not
|
|
||||||
*/
|
|
||||||
function is_blog_public() {
|
|
||||||
return (bool) apply_filters( 'activitypub_is_blog_public', \get_option( 'blog_public', 1 ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get active users based on a given duration
|
|
||||||
*
|
|
||||||
* @param int $duration The duration to check in month(s)
|
|
||||||
*
|
|
||||||
* @return int The number of active users
|
|
||||||
*/
|
|
||||||
function get_active_users( $duration = 1 ) {
|
|
||||||
|
|
||||||
$duration = intval( $duration );
|
|
||||||
$transient_key = sprintf( 'monthly_active_users_%d', $duration );
|
|
||||||
$count = get_transient( $transient_key );
|
|
||||||
|
|
||||||
if ( false === $count ) {
|
|
||||||
global $wpdb;
|
|
||||||
$query = "SELECT COUNT( DISTINCT post_author ) FROM {$wpdb->posts} WHERE post_type = 'post' AND post_status = 'publish' AND post_date <= DATE_SUB( NOW(), INTERVAL %d MONTH )";
|
|
||||||
$query = $wpdb->prepare( $query, $duration );
|
|
||||||
$count = $wpdb->get_var( $query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
|
|
||||||
|
|
||||||
set_transient( $transient_key, $count, DAY_IN_SECONDS );
|
|
||||||
}
|
|
||||||
|
|
||||||
// if 0 authors where active
|
|
||||||
if ( 0 === $count ) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if single user mode
|
|
||||||
if ( is_single_user() ) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if blog user is disabled
|
|
||||||
if ( is_user_disabled( Users::BLOG_USER_ID ) ) {
|
|
||||||
return $count;
|
|
||||||
}
|
|
||||||
|
|
||||||
// also count blog user
|
|
||||||
return $count + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the total number of users
|
|
||||||
*
|
|
||||||
* @return int The total number of users
|
|
||||||
*/
|
|
||||||
function get_total_users() {
|
|
||||||
// if single user mode
|
|
||||||
if ( is_single_user() ) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
$users = \get_users(
|
|
||||||
array(
|
|
||||||
'capability__in' => array( 'publish_posts' ),
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( is_array( $users ) ) {
|
|
||||||
$users = count( $users );
|
|
||||||
} else {
|
|
||||||
$users = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if blog user is disabled
|
|
||||||
if ( is_user_disabled( Users::BLOG_USER_ID ) ) {
|
|
||||||
return $users;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $users + 1;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
'<dd>' . \wp_kses( __( 'The post\'s title.', 'activitypub' ), array( 'code' => array() ) ) . '</dd>' .
|
'<dd>' . \wp_kses( __( 'The post\'s title.', 'activitypub' ), array( 'code' => array() ) ) . '</dd>' .
|
||||||
'<dt><code>[ap_content apply_filters="yes"]</code></dt>' .
|
'<dt><code>[ap_content apply_filters="yes"]</code></dt>' .
|
||||||
'<dd>' . \wp_kses( __( 'The post\'s content. With <code>apply_filters</code> you can decide if filters (<code>apply_filters( \'the_content\', $content )</code>) should be applied or not (default is <code>yes</code>). The values can be <code>yes</code> or <code>no</code>. <code>apply_filters</code> attribute is optional.', 'activitypub' ), array( 'code' => array() ) ) . '</dd>' .
|
'<dd>' . \wp_kses( __( 'The post\'s content. With <code>apply_filters</code> you can decide if filters (<code>apply_filters( \'the_content\', $content )</code>) should be applied or not (default is <code>yes</code>). The values can be <code>yes</code> or <code>no</code>. <code>apply_filters</code> attribute is optional.', 'activitypub' ), array( 'code' => array() ) ) . '</dd>' .
|
||||||
'<dt><code>[ap_excerpt length="400"]</code></dt>' .
|
'<dt><code>[ap_excerpt lenght="400"]</code></dt>' .
|
||||||
'<dd>' . \wp_kses( __( 'The post\'s excerpt (default 400 chars). <code>length</code> attribute is optional.', 'activitypub' ), array( 'code' => array() ) ) . '</dd>' .
|
'<dd>' . \wp_kses( __( 'The post\'s excerpt (default 400 chars). <code>length</code> attribute is optional.', 'activitypub' ), array( 'code' => array() ) ) . '</dd>' .
|
||||||
'<dt><code>[ap_permalink type="url"]</code></dt>' .
|
'<dt><code>[ap_permalink type="url"]</code></dt>' .
|
||||||
'<dd>' . \wp_kses( __( 'The post\'s permalink. <code>type</code> can be either: <code>url</code> or <code>html</code> (an <a /> tag). <code>type</code> attribute is optional.', 'activitypub' ), array( 'code' => array() ) ) . '</dd>' .
|
'<dd>' . \wp_kses( __( 'The post\'s permalink. <code>type</code> can be either: <code>url</code> or <code>html</code> (an <a /> tag). <code>type</code> attribute is optional.', 'activitypub' ), array( 'code' => array() ) ) . '</dd>' .
|
||||||
|
|
|
@ -22,13 +22,6 @@ class Application_User extends Blog_User {
|
||||||
*/
|
*/
|
||||||
protected $type = 'Application';
|
protected $type = 'Application';
|
||||||
|
|
||||||
/**
|
|
||||||
* If the User is discoverable.
|
|
||||||
*
|
|
||||||
* @var boolean
|
|
||||||
*/
|
|
||||||
protected $discoverable = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the User-Url.
|
* Get the User-Url.
|
||||||
*
|
*
|
||||||
|
@ -42,10 +35,58 @@ class Application_User extends Blog_User {
|
||||||
return 'application';
|
return 'application';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_preferred_username() {
|
public function get_username() {
|
||||||
return $this::get_name();
|
return $this::get_name();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function get__public_key() {
|
||||||
|
$key = \get_option( 'activitypub_application_user_public_key' );
|
||||||
|
|
||||||
|
if ( $key ) {
|
||||||
|
return $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->generate_key_pair();
|
||||||
|
|
||||||
|
$key = \get_option( 'activitypub_application_user_public_key' );
|
||||||
|
|
||||||
|
return $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $user_id
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function get__private_key() {
|
||||||
|
$key = \get_option( 'activitypub_application_user_private_key' );
|
||||||
|
|
||||||
|
if ( $key ) {
|
||||||
|
return $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->generate_key_pair();
|
||||||
|
|
||||||
|
return \get_option( 'activitypub_application_user_private_key' );
|
||||||
|
}
|
||||||
|
|
||||||
|
private function generate_key_pair() {
|
||||||
|
$key_pair = Signature::generate_key_pair();
|
||||||
|
|
||||||
|
if ( ! is_wp_error( $key_pair ) ) {
|
||||||
|
\update_option( 'activitypub_application_user_public_key', $key_pair['public_key'] );
|
||||||
|
\update_option( 'activitypub_application_user_private_key', $key_pair['private_key'] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_inbox() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_outbox() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public function get_followers() {
|
public function get_followers() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -55,18 +96,6 @@ class Application_User extends Blog_User {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_attachment() {
|
public function get_attachment() {
|
||||||
return null;
|
return array();
|
||||||
}
|
|
||||||
|
|
||||||
public function get_featured() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_moderators() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_indexable() {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ use Activitypub\Collection\Users;
|
||||||
|
|
||||||
use function Activitypub\is_single_user;
|
use function Activitypub\is_single_user;
|
||||||
use function Activitypub\is_user_disabled;
|
use function Activitypub\is_user_disabled;
|
||||||
use function Activitypub\get_rest_url_by_path;
|
|
||||||
|
|
||||||
class Blog_User extends User {
|
class Blog_User extends User {
|
||||||
/**
|
/**
|
||||||
|
@ -22,7 +21,7 @@ class Blog_User extends User {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $type = null;
|
protected $type = 'Group';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is Account discoverable?
|
* Is Account discoverable?
|
||||||
|
@ -46,34 +45,13 @@ class Blog_User extends User {
|
||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the type of the object.
|
|
||||||
*
|
|
||||||
* If the Blog is in "single user" mode, return "Person" insted of "Group".
|
|
||||||
*
|
|
||||||
* @return string The type of the object.
|
|
||||||
*/
|
|
||||||
public function get_type() {
|
|
||||||
if ( is_single_user() ) {
|
|
||||||
return 'Person';
|
|
||||||
} else {
|
|
||||||
return 'Group';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the User-Name.
|
* Get the User-Name.
|
||||||
*
|
*
|
||||||
* @return string The User-Name.
|
* @return string The User-Name.
|
||||||
*/
|
*/
|
||||||
public function get_name() {
|
public function get_name() {
|
||||||
return \wp_strip_all_tags(
|
return \esc_html( \get_bloginfo( 'name' ) );
|
||||||
\html_entity_decode(
|
|
||||||
\get_bloginfo( 'name' ),
|
|
||||||
\ENT_QUOTES,
|
|
||||||
'UTF-8'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,15 +77,6 @@ class Blog_User extends User {
|
||||||
return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_preferred_username() );
|
return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_preferred_username() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the User-URL with @-Prefix for the username.
|
|
||||||
*
|
|
||||||
* @return string The User-URL with @-Prefix for the username.
|
|
||||||
*/
|
|
||||||
public function get_at_url() {
|
|
||||||
return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_preferred_username() );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a default Username.
|
* Generate a default Username.
|
||||||
*
|
*
|
||||||
|
@ -144,37 +113,21 @@ class Blog_User extends User {
|
||||||
/**
|
/**
|
||||||
* Get the User-Icon.
|
* Get the User-Icon.
|
||||||
*
|
*
|
||||||
* @return array The User-Icon.
|
* @return array|null The User-Icon.
|
||||||
*/
|
*/
|
||||||
public function get_icon() {
|
public function get_icon() {
|
||||||
// try site icon first
|
$image = wp_get_attachment_image_src( get_theme_mod( 'custom_logo' ) );
|
||||||
$icon_id = get_option( 'site_icon' );
|
|
||||||
|
|
||||||
// try custom logo second
|
|
||||||
if ( ! $icon_id ) {
|
|
||||||
$icon_id = get_theme_mod( 'custom_logo' );
|
|
||||||
}
|
|
||||||
|
|
||||||
$icon_url = false;
|
|
||||||
|
|
||||||
if ( $icon_id ) {
|
|
||||||
$icon = wp_get_attachment_image_src( $icon_id, 'full' );
|
|
||||||
if ( $icon ) {
|
|
||||||
$icon_url = $icon[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! $icon_url ) {
|
|
||||||
// fallback to default icon
|
|
||||||
$icon_url = plugins_url( '/assets/img/wp-logo.png', ACTIVITYPUB_PLUGIN_FILE );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if ( $image ) {
|
||||||
return array(
|
return array(
|
||||||
'type' => 'Image',
|
'type' => 'Image',
|
||||||
'url' => esc_url( $icon_url ),
|
'url' => esc_url( $image[0] ),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the User-Header-Image.
|
* Get the User-Header-Image.
|
||||||
*
|
*
|
||||||
|
@ -209,6 +162,48 @@ class Blog_User extends User {
|
||||||
return \gmdate( 'Y-m-d\TH:i:s\Z', $time );
|
return \gmdate( 'Y-m-d\TH:i:s\Z', $time );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function get__public_key() {
|
||||||
|
$key = \get_option( 'activitypub_blog_user_public_key' );
|
||||||
|
|
||||||
|
if ( $key ) {
|
||||||
|
return $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->generate_key_pair();
|
||||||
|
|
||||||
|
$key = \get_option( 'activitypub_blog_user_public_key' );
|
||||||
|
|
||||||
|
return $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the User-Private-Key.
|
||||||
|
*
|
||||||
|
* @param int $user_id
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function get__private_key() {
|
||||||
|
$key = \get_option( 'activitypub_blog_user_private_key' );
|
||||||
|
|
||||||
|
if ( $key ) {
|
||||||
|
return $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->generate_key_pair();
|
||||||
|
|
||||||
|
return \get_option( 'activitypub_blog_user_private_key' );
|
||||||
|
}
|
||||||
|
|
||||||
|
private function generate_key_pair() {
|
||||||
|
$key_pair = Signature::generate_key_pair();
|
||||||
|
|
||||||
|
if ( ! is_wp_error( $key_pair ) ) {
|
||||||
|
\update_option( 'activitypub_blog_user_public_key', $key_pair['public_key'] );
|
||||||
|
\update_option( 'activitypub_blog_user_private_key', $key_pair['private_key'] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function get_attachment() {
|
public function get_attachment() {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
@ -217,27 +212,18 @@ class Blog_User extends User {
|
||||||
return \home_url();
|
return \home_url();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_moderators() {
|
/**
|
||||||
if ( is_single_user() || 'Group' !== $this->get_type() ) {
|
* Get the type of the object.
|
||||||
return null;
|
*
|
||||||
}
|
* If the Blog is in "single user" mode, return "Person" insted of "Group".
|
||||||
|
*
|
||||||
return get_rest_url_by_path( 'collections/moderators' );
|
* @return string The type of the object.
|
||||||
}
|
*/
|
||||||
|
public function get_type() {
|
||||||
public function get_attributed_to() {
|
if ( is_single_user() ) {
|
||||||
if ( is_single_user() || 'Group' !== $this->get_type() ) {
|
return 'Person';
|
||||||
return null;
|
} else {
|
||||||
}
|
return $this->type;
|
||||||
|
}
|
||||||
return get_rest_url_by_path( 'collections/moderators' );
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_posting_restricted_to_mods() {
|
|
||||||
if ( 'Group' === $this->get_type() ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Activitypub\Model;
|
namespace Activitypub\Model;
|
||||||
|
|
||||||
use WP_Error;
|
|
||||||
use WP_Query;
|
use WP_Query;
|
||||||
use Activitypub\Activity\Actor;
|
use Activitypub\Activity\Actor;
|
||||||
use Activitypub\Collection\Followers;
|
use Activitypub\Collection\Followers;
|
||||||
|
@ -111,40 +110,12 @@ class Follower extends Actor {
|
||||||
$this->save();
|
$this->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate the current Follower-Object.
|
|
||||||
*
|
|
||||||
* @return boolean True if the verification was successful.
|
|
||||||
*/
|
|
||||||
public function is_valid() {
|
|
||||||
// the minimum required attributes
|
|
||||||
$required_attributes = array(
|
|
||||||
'id',
|
|
||||||
'preferredUsername',
|
|
||||||
'inbox',
|
|
||||||
'publicKey',
|
|
||||||
'publicKeyPem',
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ( $required_attributes as $attribute ) {
|
|
||||||
if ( ! $this->get( $attribute ) ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the current Follower-Object.
|
* Save the current Follower-Object.
|
||||||
*
|
*
|
||||||
* @return int|WP_Error The Post-ID or an WP_Error.
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function save() {
|
public function save() {
|
||||||
if ( ! $this->is_valid() ) {
|
|
||||||
return new WP_Error( 'activitypub_invalid_follower', __( 'Invalid Follower', 'activitypub' ), array( 'status' => 400 ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! $this->get__id() ) {
|
if ( ! $this->get__id() ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
|
@ -176,17 +147,15 @@ class Follower extends Actor {
|
||||||
|
|
||||||
$post_id = wp_insert_post( $args );
|
$post_id = wp_insert_post( $args );
|
||||||
$this->_id = $post_id;
|
$this->_id = $post_id;
|
||||||
|
|
||||||
return $post_id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upsert the current Follower-Object.
|
* Upsert the current Follower-Object.
|
||||||
*
|
*
|
||||||
* @return int|WP_Error The Post-ID or an WP_Error.
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function upsert() {
|
public function upsert() {
|
||||||
return $this->save();
|
$this->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -315,7 +284,7 @@ class Follower extends Actor {
|
||||||
$object->set_id( $post->guid );
|
$object->set_id( $post->guid );
|
||||||
$object->set_name( $post->post_title );
|
$object->set_name( $post->post_title );
|
||||||
$object->set_summary( $post->post_excerpt );
|
$object->set_summary( $post->post_excerpt );
|
||||||
$object->set_published( gmdate( 'Y-m-d H:i:s', strtotime( $post->post_date ) ) );
|
$object->set_published( gmdate( 'Y-m-d H:i:s', strtotime( $post->post_published ) ) );
|
||||||
$object->set_updated( gmdate( 'Y-m-d H:i:s', strtotime( $post->post_modified ) ) );
|
$object->set_updated( gmdate( 'Y-m-d H:i:s', strtotime( $post->post_modified ) ) );
|
||||||
|
|
||||||
return $object;
|
return $object;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Activitypub\Model;
|
namespace Activitypub\Model;
|
||||||
|
|
||||||
use Activitypub\Transformer\Post as Transformer_Post;
|
use Activitypub\Transformer\Post as Post_Transformer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub Post Class
|
* ActivityPub Post Class
|
||||||
|
@ -34,8 +34,7 @@ class Post {
|
||||||
_deprecated_function( __CLASS__, '1.0.0', '\Activitypub\Transformer\Post' );
|
_deprecated_function( __CLASS__, '1.0.0', '\Activitypub\Transformer\Post' );
|
||||||
|
|
||||||
$this->post = $post;
|
$this->post = $post;
|
||||||
$transformer = new Transformer_Post();
|
$this->object = Post_Transformer::transform( $post )->to_object();
|
||||||
$this->object = $transformer->set_wp_post( $post )->to_object();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,24 +18,6 @@ class User extends Actor {
|
||||||
*/
|
*/
|
||||||
protected $_id; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
|
protected $_id; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
|
||||||
|
|
||||||
/**
|
|
||||||
* The Featured-Posts.
|
|
||||||
*
|
|
||||||
* @see https://docs.joinmastodon.org/spec/activitypub/#featured
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $featured;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Moderators endpoint.
|
|
||||||
*
|
|
||||||
* @see https://join-lemmy.org/docs/contributors/05-federation.html
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $moderators;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The User-Type
|
* The User-Type
|
||||||
*
|
*
|
||||||
|
@ -43,38 +25,6 @@ class User extends Actor {
|
||||||
*/
|
*/
|
||||||
protected $type = 'Person';
|
protected $type = 'Person';
|
||||||
|
|
||||||
/**
|
|
||||||
* If the User is discoverable.
|
|
||||||
*
|
|
||||||
* @see https://docs.joinmastodon.org/spec/activitypub/#discoverable
|
|
||||||
*
|
|
||||||
* @var boolean
|
|
||||||
*/
|
|
||||||
protected $discoverable = true;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If the User is indexable.
|
|
||||||
*
|
|
||||||
* @var boolean
|
|
||||||
*/
|
|
||||||
protected $indexable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The WebFinger Resource.
|
|
||||||
*
|
|
||||||
* @var string<url>
|
|
||||||
*/
|
|
||||||
protected $resource;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Restrict posting to mods
|
|
||||||
*
|
|
||||||
* @see https://join-lemmy.org/docs/contributors/05-federation.html
|
|
||||||
*
|
|
||||||
* @var boolean
|
|
||||||
*/
|
|
||||||
protected $posting_restricted_to_mods = null;
|
|
||||||
|
|
||||||
public static function from_wp_user( $user_id ) {
|
public static function from_wp_user( $user_id ) {
|
||||||
if ( is_user_disabled( $user_id ) ) {
|
if ( is_user_disabled( $user_id ) ) {
|
||||||
return new WP_Error(
|
return new WP_Error(
|
||||||
|
@ -130,11 +80,6 @@ class User extends Actor {
|
||||||
return \esc_url( \get_author_posts_url( $this->_id ) );
|
return \esc_url( \get_author_posts_url( $this->_id ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the User-URL with @-Prefix for the username.
|
|
||||||
*
|
|
||||||
* @return string The User-URL with @-Prefix for the username.
|
|
||||||
*/
|
|
||||||
public function get_at_url() {
|
public function get_at_url() {
|
||||||
return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_username() );
|
return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_username() );
|
||||||
}
|
}
|
||||||
|
@ -177,10 +122,53 @@ class User extends Actor {
|
||||||
return array(
|
return array(
|
||||||
'id' => $this->get_id() . '#main-key',
|
'id' => $this->get_id() . '#main-key',
|
||||||
'owner' => $this->get_id(),
|
'owner' => $this->get_id(),
|
||||||
'publicKeyPem' => Signature::get_public_key_for( $this->get__id() ),
|
'publicKeyPem' => $this->get__public_key(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $this->get__id()
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function get__public_key() {
|
||||||
|
$key = \get_user_meta( $this->get__id(), 'magic_sig_public_key', true );
|
||||||
|
|
||||||
|
if ( $key ) {
|
||||||
|
return $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->generate_key_pair();
|
||||||
|
|
||||||
|
return \get_user_meta( $this->get__id(), 'magic_sig_public_key', true );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $this->get__id()
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function get__private_key() {
|
||||||
|
$key = \get_user_meta( $this->get__id(), 'magic_sig_private_key', true );
|
||||||
|
|
||||||
|
if ( $key ) {
|
||||||
|
return $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->generate_key_pair();
|
||||||
|
|
||||||
|
return \get_user_meta( $this->get__id(), 'magic_sig_private_key', true );
|
||||||
|
}
|
||||||
|
|
||||||
|
private function generate_key_pair() {
|
||||||
|
$key_pair = Signature::generate_key_pair();
|
||||||
|
|
||||||
|
if ( ! is_wp_error( $key_pair ) ) {
|
||||||
|
\update_user_meta( $this->get__id(), 'magic_sig_public_key', $key_pair['public_key'], true );
|
||||||
|
\update_user_meta( $this->get__id(), 'magic_sig_private_key', $key_pair['private_key'], true );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Inbox-API-Endpoint.
|
* Returns the Inbox-API-Endpoint.
|
||||||
*
|
*
|
||||||
|
@ -217,15 +205,6 @@ class User extends Actor {
|
||||||
return get_rest_url_by_path( sprintf( 'users/%d/following', $this->get__id() ) );
|
return get_rest_url_by_path( sprintf( 'users/%d/following', $this->get__id() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the Featured-API-Endpoint.
|
|
||||||
*
|
|
||||||
* @return string The Featured-Endpoint.
|
|
||||||
*/
|
|
||||||
public function get_featured() {
|
|
||||||
return get_rest_url_by_path( sprintf( 'users/%d/collections/featured', $this->get__id() ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extend the User-Output with Attachments.
|
* Extend the User-Output with Attachments.
|
||||||
*
|
*
|
||||||
|
@ -269,11 +248,6 @@ class User extends Actor {
|
||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a user@domain type of identifier for the user.
|
|
||||||
*
|
|
||||||
* @return string The Webfinger-Identifier.
|
|
||||||
*/
|
|
||||||
public function get_resource() {
|
public function get_resource() {
|
||||||
return $this->get_preferred_username() . '@' . \wp_parse_url( \home_url(), \PHP_URL_HOST );
|
return $this->get_preferred_username() . '@' . \wp_parse_url( \home_url(), \PHP_URL_HOST );
|
||||||
}
|
}
|
||||||
|
@ -281,20 +255,4 @@ class User extends Actor {
|
||||||
public function get_canonical_url() {
|
public function get_canonical_url() {
|
||||||
return $this->get_url();
|
return $this->get_url();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_streams() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_tag() {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_indexable() {
|
|
||||||
if ( \get_option( 'blog_public', 1 ) ) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,222 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Activitypub\Rest;
|
|
||||||
|
|
||||||
use WP_Error;
|
|
||||||
use WP_REST_Server;
|
|
||||||
use WP_REST_Response;
|
|
||||||
use Activitypub\Transformer\Transformers_Manager;
|
|
||||||
use Activitypub\Activity\Activity;
|
|
||||||
use Activitypub\Collection\Users as User_Collection;
|
|
||||||
|
|
||||||
use function Activitypub\esc_hashtag;
|
|
||||||
use function Activitypub\is_single_user;
|
|
||||||
use function Activitypub\get_rest_url_by_path;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ActivityPub Collections REST-Class
|
|
||||||
*
|
|
||||||
* @author Matthias Pfefferle
|
|
||||||
*
|
|
||||||
* @see https://docs.joinmastodon.org/spec/activitypub/#featured
|
|
||||||
* @see https://docs.joinmastodon.org/spec/activitypub/#featuredTags
|
|
||||||
*/
|
|
||||||
class Collection {
|
|
||||||
/**
|
|
||||||
* Initialize the class, registering WordPress hooks
|
|
||||||
*/
|
|
||||||
public static function init() {
|
|
||||||
self::register_routes();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register routes
|
|
||||||
*/
|
|
||||||
public static function register_routes() {
|
|
||||||
\register_rest_route(
|
|
||||||
ACTIVITYPUB_REST_NAMESPACE,
|
|
||||||
'/users/(?P<user_id>[\w\-\.]+)/collections/tags',
|
|
||||||
array(
|
|
||||||
array(
|
|
||||||
'methods' => WP_REST_Server::READABLE,
|
|
||||||
'callback' => array( self::class, 'tags_get' ),
|
|
||||||
'args' => self::request_parameters(),
|
|
||||||
'permission_callback' => '__return_true',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
\register_rest_route(
|
|
||||||
ACTIVITYPUB_REST_NAMESPACE,
|
|
||||||
'/users/(?P<user_id>[\w\-\.]+)/collections/featured',
|
|
||||||
array(
|
|
||||||
array(
|
|
||||||
'methods' => WP_REST_Server::READABLE,
|
|
||||||
'callback' => array( self::class, 'featured_get' ),
|
|
||||||
'args' => self::request_parameters(),
|
|
||||||
'permission_callback' => '__return_true',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
\register_rest_route(
|
|
||||||
ACTIVITYPUB_REST_NAMESPACE,
|
|
||||||
'/collections/moderators',
|
|
||||||
array(
|
|
||||||
array(
|
|
||||||
'methods' => WP_REST_Server::READABLE,
|
|
||||||
'callback' => array( self::class, 'moderators_get' ),
|
|
||||||
'permission_callback' => '__return_true',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Featured Tags endpoint
|
|
||||||
*
|
|
||||||
* @param WP_REST_Request $request The request object.
|
|
||||||
*
|
|
||||||
* @return WP_REST_Response The response object.
|
|
||||||
*/
|
|
||||||
public static function tags_get( $request ) {
|
|
||||||
$user_id = $request->get_param( 'user_id' );
|
|
||||||
$user = User_Collection::get_by_various( $user_id );
|
|
||||||
|
|
||||||
if ( is_wp_error( $user ) ) {
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
$number = 4;
|
|
||||||
|
|
||||||
$tags = \get_terms(
|
|
||||||
array(
|
|
||||||
'taxonomy' => 'post_tag',
|
|
||||||
'orderby' => 'count',
|
|
||||||
'order' => 'DESC',
|
|
||||||
'number' => $number,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( is_wp_error( $tags ) ) {
|
|
||||||
$tags = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$response = array(
|
|
||||||
'@context' => Activity::CONTEXT,
|
|
||||||
'id' => get_rest_url_by_path( sprintf( 'users/%d/collections/tags', $user->get__id() ) ),
|
|
||||||
'type' => 'Collection',
|
|
||||||
'totalItems' => is_countable( $tags ) ? count( $tags ) : 0,
|
|
||||||
'items' => array(),
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ( $tags as $tag ) {
|
|
||||||
$response['items'][] = array(
|
|
||||||
'type' => 'Hashtag',
|
|
||||||
'href' => \esc_url( \get_tag_link( $tag ) ),
|
|
||||||
'name' => esc_hashtag( $tag->name ),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$rest_response = new WP_REST_Response( $response, 200 );
|
|
||||||
$rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) );
|
|
||||||
|
|
||||||
return $rest_response;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Featured posts endpoint
|
|
||||||
*
|
|
||||||
* @param WP_REST_Request $request The request object.
|
|
||||||
*
|
|
||||||
* @return WP_REST_Response The response object.
|
|
||||||
*/
|
|
||||||
public static function featured_get( $request ) {
|
|
||||||
$user_id = $request->get_param( 'user_id' );
|
|
||||||
$user = User_Collection::get_by_various( $user_id );
|
|
||||||
|
|
||||||
if ( is_wp_error( $user ) ) {
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sticky_posts = \get_option( 'sticky_posts' );
|
|
||||||
|
|
||||||
if ( ! is_single_user() && User_Collection::BLOG_USER_ID === $user->get__id() ) {
|
|
||||||
$posts = array();
|
|
||||||
} elseif ( $sticky_posts ) {
|
|
||||||
$args = array(
|
|
||||||
'post__in' => $sticky_posts,
|
|
||||||
'ignore_sticky_posts' => 1,
|
|
||||||
'orderby' => 'date',
|
|
||||||
'order' => 'DESC',
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( $user->get__id() > 0 ) {
|
|
||||||
$args['author'] = $user->get__id();
|
|
||||||
}
|
|
||||||
|
|
||||||
$posts = \get_posts( $args );
|
|
||||||
} else {
|
|
||||||
$posts = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$response = array(
|
|
||||||
'@context' => Activity::CONTEXT,
|
|
||||||
'id' => get_rest_url_by_path( sprintf( 'users/%d/collections/featured', $user_id ) ),
|
|
||||||
'type' => 'OrderedCollection',
|
|
||||||
'totalItems' => is_countable( $posts ) ? count( $posts ) : 0,
|
|
||||||
'orderedItems' => array(),
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ( $posts as $post ) {
|
|
||||||
$response['orderedItems'][] = Transformers_Manager::instance()->get_transformer( $post )->to_object()->to_array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$rest_response = new WP_REST_Response( $response, 200 );
|
|
||||||
$rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) );
|
|
||||||
|
|
||||||
return $rest_response;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Moderators endpoint
|
|
||||||
*
|
|
||||||
* @param WP_REST_Request $request The request object.
|
|
||||||
*
|
|
||||||
* @return WP_REST_Response The response object.
|
|
||||||
*/
|
|
||||||
public static function moderators_get( $request ) {
|
|
||||||
$response = array(
|
|
||||||
'@context' => Activity::CONTEXT,
|
|
||||||
'id' => get_rest_url_by_path( 'collections/moderators' ),
|
|
||||||
'type' => 'OrderedCollection',
|
|
||||||
'orderedItems' => array(),
|
|
||||||
);
|
|
||||||
|
|
||||||
$users = User_Collection::get_collection();
|
|
||||||
|
|
||||||
foreach ( $users as $user ) {
|
|
||||||
$response['orderedItems'][] = $user->get_url();
|
|
||||||
}
|
|
||||||
|
|
||||||
$rest_response = new WP_REST_Response( $response, 200 );
|
|
||||||
$rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) );
|
|
||||||
|
|
||||||
return $rest_response;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The supported parameters
|
|
||||||
*
|
|
||||||
* @return array list of parameters
|
|
||||||
*/
|
|
||||||
public static function request_parameters() {
|
|
||||||
$params = array();
|
|
||||||
|
|
||||||
$params['user_id'] = array(
|
|
||||||
'required' => true,
|
|
||||||
'type' => 'string',
|
|
||||||
);
|
|
||||||
|
|
||||||
return $params;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,6 +5,7 @@ use WP_Error;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
use WP_REST_Server;
|
use WP_REST_Server;
|
||||||
use WP_REST_Response;
|
use WP_REST_Response;
|
||||||
|
use Activitypub\Validator\Query;
|
||||||
use Activitypub\Collection\Users as User_Collection;
|
use Activitypub\Collection\Users as User_Collection;
|
||||||
use Activitypub\Collection\Followers as Follower_Collection;
|
use Activitypub\Collection\Followers as Follower_Collection;
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ class Followers {
|
||||||
* Initialize the class, registering WordPress hooks
|
* Initialize the class, registering WordPress hooks
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
self::register_routes();
|
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,7 +37,7 @@ class Followers {
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::READABLE,
|
'methods' => WP_REST_Server::READABLE,
|
||||||
'callback' => array( self::class, 'get' ),
|
'callback' => array( self::class, 'get' ),
|
||||||
'args' => self::request_parameters(),
|
'args' => Query::get_default_args(),
|
||||||
'permission_callback' => '__return_true',
|
'permission_callback' => '__return_true',
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -103,47 +104,9 @@ class Followers {
|
||||||
$data['followers']
|
$data['followers']
|
||||||
);
|
);
|
||||||
|
|
||||||
$rest_response = new WP_REST_Response( $json, 200 );
|
$response = new WP_REST_Response( $json, 200 );
|
||||||
$rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) );
|
$response->header( 'Content-Type', 'application/activity+json' );
|
||||||
|
|
||||||
return $rest_response;
|
return $response;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The supported parameters
|
|
||||||
*
|
|
||||||
* @return array list of parameters
|
|
||||||
*/
|
|
||||||
public static function request_parameters() {
|
|
||||||
$params = array();
|
|
||||||
|
|
||||||
$params['page'] = array(
|
|
||||||
'type' => 'integer',
|
|
||||||
'default' => 1,
|
|
||||||
);
|
|
||||||
|
|
||||||
$params['per_page'] = array(
|
|
||||||
'type' => 'integer',
|
|
||||||
'default' => 20,
|
|
||||||
);
|
|
||||||
|
|
||||||
$params['order'] = array(
|
|
||||||
'type' => 'string',
|
|
||||||
'default' => 'desc',
|
|
||||||
'enum' => array( 'asc', 'desc' ),
|
|
||||||
);
|
|
||||||
|
|
||||||
$params['user_id'] = array(
|
|
||||||
'required' => true,
|
|
||||||
'type' => 'string',
|
|
||||||
);
|
|
||||||
|
|
||||||
$params['context'] = array(
|
|
||||||
'type' => 'string',
|
|
||||||
'default' => 'simple',
|
|
||||||
'enum' => array( 'simple', 'full' ),
|
|
||||||
);
|
|
||||||
|
|
||||||
return $params;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Activitypub\Rest;
|
namespace Activitypub\Rest;
|
||||||
|
|
||||||
use WP_REST_Response;
|
use Activitypub\Validator\Query;
|
||||||
use Activitypub\Collection\Users as User_Collection;
|
use Activitypub\Collection\Users as User_Collection;
|
||||||
|
|
||||||
use function Activitypub\is_single_user;
|
|
||||||
use function Activitypub\get_rest_url_by_path;
|
use function Activitypub\get_rest_url_by_path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,9 +18,7 @@ class Following {
|
||||||
* Initialize the class, registering WordPress hooks
|
* Initialize the class, registering WordPress hooks
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
self::register_routes();
|
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
||||||
|
|
||||||
\add_filter( 'activitypub_rest_following', array( self::class, 'default_following' ), 10, 2 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,7 +32,7 @@ class Following {
|
||||||
array(
|
array(
|
||||||
'methods' => \WP_REST_Server::READABLE,
|
'methods' => \WP_REST_Server::READABLE,
|
||||||
'callback' => array( self::class, 'get' ),
|
'callback' => array( self::class, 'get' ),
|
||||||
'args' => self::request_parameters(),
|
'args' => Query::get_default_args(),
|
||||||
'permission_callback' => '__return_true',
|
'permission_callback' => '__return_true',
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -72,60 +69,14 @@ class Following {
|
||||||
$json->type = 'OrderedCollectionPage';
|
$json->type = 'OrderedCollectionPage';
|
||||||
|
|
||||||
$json->partOf = get_rest_url_by_path( sprintf( 'users/%d/following', $user->get__id() ) ); // phpcs:ignore
|
$json->partOf = get_rest_url_by_path( sprintf( 'users/%d/following', $user->get__id() ) ); // phpcs:ignore
|
||||||
|
$json->totalItems = 0; // phpcs:ignore
|
||||||
$items = apply_filters( 'activitypub_rest_following', array(), $user ); // phpcs:ignore
|
$json->orderedItems = apply_filters( 'activitypub_following', array(), $user ); // phpcs:ignore
|
||||||
|
|
||||||
$json->totalItems = is_countable( $items ) ? count( $items ) : 0; // phpcs:ignore
|
|
||||||
$json->orderedItems = $items; // phpcs:ignore
|
|
||||||
|
|
||||||
$json->first = $json->partOf; // phpcs:ignore
|
$json->first = $json->partOf; // phpcs:ignore
|
||||||
|
|
||||||
$rest_response = new WP_REST_Response( $json, 200 );
|
$response = new \WP_REST_Response( $json, 200 );
|
||||||
$rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) );
|
$response->header( 'Content-Type', 'application/activity+json' );
|
||||||
|
|
||||||
return $rest_response;
|
return $response;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The supported parameters
|
|
||||||
*
|
|
||||||
* @return array list of parameters
|
|
||||||
*/
|
|
||||||
public static function request_parameters() {
|
|
||||||
$params = array();
|
|
||||||
|
|
||||||
$params['page'] = array(
|
|
||||||
'type' => 'integer',
|
|
||||||
);
|
|
||||||
|
|
||||||
$params['user_id'] = array(
|
|
||||||
'required' => true,
|
|
||||||
'type' => 'string',
|
|
||||||
);
|
|
||||||
|
|
||||||
return $params;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add the Blog Authors to the following list of the Blog Actor
|
|
||||||
* if Blog not in single mode.
|
|
||||||
*
|
|
||||||
* @param array $array The array of following urls.
|
|
||||||
* @param User $user The user object.
|
|
||||||
*
|
|
||||||
* @return array The array of following urls.
|
|
||||||
*/
|
|
||||||
public static function default_following( $array, $user ) {
|
|
||||||
if ( 0 !== $user->get__id() || is_single_user() ) {
|
|
||||||
return $array;
|
|
||||||
}
|
|
||||||
|
|
||||||
$users = User_Collection::get_collection();
|
|
||||||
|
|
||||||
foreach ( $users as $user ) {
|
|
||||||
$array[] = $user->get_url();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $array;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace Activitypub\Rest;
|
||||||
use WP_Error;
|
use WP_Error;
|
||||||
use WP_REST_Server;
|
use WP_REST_Server;
|
||||||
use WP_REST_Response;
|
use WP_REST_Response;
|
||||||
|
use Activitypub\Validator\Query;
|
||||||
use Activitypub\Activity\Activity;
|
use Activitypub\Activity\Activity;
|
||||||
use Activitypub\Collection\Users as User_Collection;
|
use Activitypub\Collection\Users as User_Collection;
|
||||||
|
|
||||||
|
@ -24,7 +25,7 @@ class Inbox {
|
||||||
* Initialize the class, registering WordPress hooks
|
* Initialize the class, registering WordPress hooks
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
self::register_routes();
|
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
||||||
|
|
||||||
\add_action( 'activitypub_inbox_create', array( self::class, 'handle_create' ), 10, 2 );
|
\add_action( 'activitypub_inbox_create', array( self::class, 'handle_create' ), 10, 2 );
|
||||||
}
|
}
|
||||||
|
@ -38,7 +39,7 @@ class Inbox {
|
||||||
'/inbox',
|
'/inbox',
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::CREATABLE,
|
'methods' => WP_REST_Server::EDITABLE,
|
||||||
'callback' => array( self::class, 'shared_inbox_post' ),
|
'callback' => array( self::class, 'shared_inbox_post' ),
|
||||||
'args' => self::shared_inbox_post_parameters(),
|
'args' => self::shared_inbox_post_parameters(),
|
||||||
'permission_callback' => '__return_true',
|
'permission_callback' => '__return_true',
|
||||||
|
@ -51,7 +52,7 @@ class Inbox {
|
||||||
'/users/(?P<user_id>[\w\-\.]+)/inbox',
|
'/users/(?P<user_id>[\w\-\.]+)/inbox',
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::CREATABLE,
|
'methods' => WP_REST_Server::EDITABLE,
|
||||||
'callback' => array( self::class, 'user_inbox_post' ),
|
'callback' => array( self::class, 'user_inbox_post' ),
|
||||||
'args' => self::user_inbox_post_parameters(),
|
'args' => self::user_inbox_post_parameters(),
|
||||||
'permission_callback' => '__return_true',
|
'permission_callback' => '__return_true',
|
||||||
|
@ -59,7 +60,7 @@ class Inbox {
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::READABLE,
|
'methods' => WP_REST_Server::READABLE,
|
||||||
'callback' => array( self::class, 'user_inbox_get' ),
|
'callback' => array( self::class, 'user_inbox_get' ),
|
||||||
'args' => self::user_inbox_get_parameters(),
|
'args' => Query::get_default_args(),
|
||||||
'permission_callback' => '__return_true',
|
'permission_callback' => '__return_true',
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -102,17 +103,18 @@ class Inbox {
|
||||||
$json->first = $json->partOf; // phpcs:ignore
|
$json->first = $json->partOf; // phpcs:ignore
|
||||||
|
|
||||||
// filter output
|
// filter output
|
||||||
$json = \apply_filters( 'activitypub_rest_inbox_array', $json );
|
$json = \apply_filters( 'activitypub_inbox_array', $json );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Action triggerd after the ActivityPub profile has been created and sent to the client
|
* Action triggerd after the ActivityPub profile has been created and sent to the client
|
||||||
*/
|
*/
|
||||||
\do_action( 'activitypub_inbox_post' );
|
\do_action( 'activitypub_inbox_post' );
|
||||||
|
|
||||||
$rest_response = new WP_REST_Response( $json, 200 );
|
$response = new WP_REST_Response( $json, 200 );
|
||||||
$rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) );
|
|
||||||
|
|
||||||
return $rest_response;
|
$response->header( 'Content-Type', 'application/activity+json' );
|
||||||
|
|
||||||
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -130,17 +132,14 @@ class Inbox {
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $request->get_json_params();
|
$data = $request->get_params();
|
||||||
$type = $request->get_param( 'type' );
|
$type = $request->get_param( 'type' );
|
||||||
$type = \strtolower( $type );
|
$type = \strtolower( $type );
|
||||||
|
|
||||||
\do_action( 'activitypub_inbox', $data, $user->get__id(), $type );
|
\do_action( 'activitypub_inbox', $data, $user->get__id(), $type );
|
||||||
\do_action( "activitypub_inbox_{$type}", $data, $user->get__id() );
|
\do_action( "activitypub_inbox_{$type}", $data, $user->get__id() );
|
||||||
|
|
||||||
$rest_response = new WP_REST_Response( array(), 202 );
|
return new WP_REST_Response( array(), 202 );
|
||||||
$rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) );
|
|
||||||
|
|
||||||
return $rest_response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -151,7 +150,7 @@ class Inbox {
|
||||||
* @return WP_REST_Response
|
* @return WP_REST_Response
|
||||||
*/
|
*/
|
||||||
public static function shared_inbox_post( $request ) {
|
public static function shared_inbox_post( $request ) {
|
||||||
$data = $request->get_json_params();
|
$data = $request->get_params();
|
||||||
$type = $request->get_param( 'type' );
|
$type = $request->get_param( 'type' );
|
||||||
$users = self::extract_recipients( $data );
|
$users = self::extract_recipients( $data );
|
||||||
|
|
||||||
|
@ -160,7 +159,7 @@ class Inbox {
|
||||||
'rest_invalid_param',
|
'rest_invalid_param',
|
||||||
\__( 'No recipients found', 'activitypub' ),
|
\__( 'No recipients found', 'activitypub' ),
|
||||||
array(
|
array(
|
||||||
'status' => 400,
|
'status' => 404,
|
||||||
'params' => array(
|
'params' => array(
|
||||||
'to' => \__( 'Please check/validate "to" field', 'activitypub' ),
|
'to' => \__( 'Please check/validate "to" field', 'activitypub' ),
|
||||||
'bto' => \__( 'Please check/validate "bto" field', 'activitypub' ),
|
'bto' => \__( 'Please check/validate "bto" field', 'activitypub' ),
|
||||||
|
@ -173,42 +172,13 @@ class Inbox {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ( $users as $user ) {
|
foreach ( $users as $user ) {
|
||||||
$user = User_Collection::get_by_various( $user );
|
|
||||||
|
|
||||||
if ( is_wp_error( $user ) ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$type = \strtolower( $type );
|
$type = \strtolower( $type );
|
||||||
|
|
||||||
\do_action( 'activitypub_inbox', $data, $user->ID, $type );
|
\do_action( 'activitypub_inbox', $data, $user->ID, $type );
|
||||||
\do_action( "activitypub_inbox_{$type}", $data, $user->ID );
|
\do_action( "activitypub_inbox_{$type}", $data, $user->ID );
|
||||||
}
|
}
|
||||||
|
|
||||||
$rest_response = new WP_REST_Response( array(), 202 );
|
return new WP_REST_Response( array(), 202 );
|
||||||
$rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) );
|
|
||||||
|
|
||||||
return $rest_response;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The supported parameters
|
|
||||||
*
|
|
||||||
* @return array list of parameters
|
|
||||||
*/
|
|
||||||
public static function user_inbox_get_parameters() {
|
|
||||||
$params = array();
|
|
||||||
|
|
||||||
$params['page'] = array(
|
|
||||||
'type' => 'integer',
|
|
||||||
);
|
|
||||||
|
|
||||||
$params['user_id'] = array(
|
|
||||||
'required' => true,
|
|
||||||
'type' => 'string',
|
|
||||||
);
|
|
||||||
|
|
||||||
return $params;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -236,12 +206,8 @@ class Inbox {
|
||||||
$params['actor'] = array(
|
$params['actor'] = array(
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'sanitize_callback' => function( $param, $request, $key ) {
|
'sanitize_callback' => function( $param, $request, $key ) {
|
||||||
if ( \is_array( $param ) ) {
|
if ( ! \is_string( $param ) ) {
|
||||||
if ( isset( $param['id'] ) ) {
|
|
||||||
$param = $param['id'];
|
$param = $param['id'];
|
||||||
} else {
|
|
||||||
$param = $param['url'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return \esc_url_raw( $param );
|
return \esc_url_raw( $param );
|
||||||
},
|
},
|
||||||
|
@ -340,6 +306,53 @@ class Inbox {
|
||||||
return $params;
|
return $params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles "Reaction" requests
|
||||||
|
*
|
||||||
|
* @param array $object The activity-object
|
||||||
|
* @param int $user_id The id of the local blog-user
|
||||||
|
*/
|
||||||
|
public static function handle_reaction( $object, $user_id ) {
|
||||||
|
$meta = get_remote_metadata_by_actor( $object['actor'] );
|
||||||
|
|
||||||
|
$comment_post_id = \url_to_postid( $object['object'] );
|
||||||
|
|
||||||
|
// save only replys and reactions
|
||||||
|
if ( ! $comment_post_id ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$commentdata = array(
|
||||||
|
'comment_post_ID' => $comment_post_id,
|
||||||
|
'comment_author' => \esc_attr( $meta['name'] ),
|
||||||
|
'comment_author_email' => '',
|
||||||
|
'comment_author_url' => \esc_url_raw( $object['actor'] ),
|
||||||
|
'comment_content' => \esc_url_raw( $object['actor'] ),
|
||||||
|
'comment_type' => \esc_attr( \strtolower( $object['type'] ) ),
|
||||||
|
'comment_parent' => 0,
|
||||||
|
'comment_meta' => array(
|
||||||
|
'source_url' => \esc_url_raw( $object['id'] ),
|
||||||
|
'avatar_url' => \esc_url_raw( $meta['icon']['url'] ),
|
||||||
|
'protocol' => 'activitypub',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// disable flood control
|
||||||
|
\remove_action( 'check_comment_flood', 'check_comment_flood_db', 10 );
|
||||||
|
|
||||||
|
// do not require email for AP entries
|
||||||
|
\add_filter( 'pre_option_require_name_email', '__return_false' );
|
||||||
|
|
||||||
|
$state = \wp_new_comment( $commentdata, true );
|
||||||
|
|
||||||
|
\remove_filter( 'pre_option_require_name_email', '__return_false' );
|
||||||
|
|
||||||
|
// re-add flood control
|
||||||
|
\add_action( 'check_comment_flood', 'check_comment_flood_db', 10, 4 );
|
||||||
|
|
||||||
|
do_action( 'activitypub_handled_reaction', $object, $user_id, $state, $commentdata );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles "Create" requests
|
* Handles "Create" requests
|
||||||
*
|
*
|
||||||
|
@ -370,7 +383,7 @@ class Inbox {
|
||||||
'comment_post_ID' => $comment_post_id,
|
'comment_post_ID' => $comment_post_id,
|
||||||
'comment_author' => \esc_attr( $meta['name'] ),
|
'comment_author' => \esc_attr( $meta['name'] ),
|
||||||
'comment_author_url' => \esc_url_raw( $object['actor'] ),
|
'comment_author_url' => \esc_url_raw( $object['actor'] ),
|
||||||
'comment_content' => addslashes( \wp_kses( $object['object']['content'], 'pre_comment_content' ) ),
|
'comment_content' => \wp_filter_kses( $object['object']['content'] ),
|
||||||
'comment_type' => 'comment',
|
'comment_type' => 'comment',
|
||||||
'comment_author_email' => '',
|
'comment_author_email' => '',
|
||||||
'comment_parent' => 0,
|
'comment_parent' => 0,
|
||||||
|
@ -387,19 +400,8 @@ class Inbox {
|
||||||
// do not require email for AP entries
|
// do not require email for AP entries
|
||||||
\add_filter( 'pre_option_require_name_email', '__return_false' );
|
\add_filter( 'pre_option_require_name_email', '__return_false' );
|
||||||
|
|
||||||
// No nonce possible for this submission route
|
|
||||||
\add_filter(
|
|
||||||
'akismet_comment_nonce',
|
|
||||||
function() {
|
|
||||||
return 'inactive';
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
\add_filter( 'wp_kses_allowed_html', array( self::class, 'allowed_comment_html' ), 10, 2 );
|
|
||||||
|
|
||||||
$state = \wp_new_comment( $commentdata, true );
|
$state = \wp_new_comment( $commentdata, true );
|
||||||
|
|
||||||
\remove_filter( 'wp_kses_allowed_html', array( self::class, 'allowed_comment_html' ) );
|
|
||||||
\remove_filter( 'pre_option_require_name_email', '__return_false' );
|
\remove_filter( 'pre_option_require_name_email', '__return_false' );
|
||||||
|
|
||||||
// re-add flood control
|
// re-add flood control
|
||||||
|
@ -428,7 +430,7 @@ class Inbox {
|
||||||
$recipient_items = array_merge( $recipient_items, $recipient );
|
$recipient_items = array_merge( $recipient_items, $recipient );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( is_array( $data['object'] ) && array_key_exists( $i, $data['object'] ) ) {
|
if ( array_key_exists( $i, $data['object'] ) ) {
|
||||||
if ( is_array( $data['object'][ $i ] ) ) {
|
if ( is_array( $data['object'][ $i ] ) ) {
|
||||||
$recipient = $data['object'][ $i ];
|
$recipient = $data['object'][ $i ];
|
||||||
} else {
|
} else {
|
||||||
|
@ -490,29 +492,4 @@ class Inbox {
|
||||||
|
|
||||||
return in_array( 'https://www.w3.org/ns/activitystreams#Public', $recipients, true );
|
return in_array( 'https://www.w3.org/ns/activitystreams#Public', $recipients, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds line breaks to the list of allowed comment tags.
|
|
||||||
*
|
|
||||||
* @param array $allowedtags Allowed HTML tags.
|
|
||||||
* @param string $context Context.
|
|
||||||
* @return array Filtered tag list.
|
|
||||||
*/
|
|
||||||
public static function allowed_comment_html( $allowedtags, $context = '' ) {
|
|
||||||
if ( 'pre_comment_content' !== $context ) {
|
|
||||||
// Do nothing.
|
|
||||||
return $allowedtags;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add `p` and `br` to the list of allowed tags.
|
|
||||||
if ( ! array_key_exists( 'br', $allowedtags ) ) {
|
|
||||||
$allowedtags['br'] = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! array_key_exists( 'p', $allowedtags ) ) {
|
|
||||||
$allowedtags['p'] = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $allowedtags;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,6 @@ namespace Activitypub\Rest;
|
||||||
|
|
||||||
use WP_REST_Response;
|
use WP_REST_Response;
|
||||||
|
|
||||||
use function Activitypub\get_total_users;
|
|
||||||
use function Activitypub\get_active_users;
|
|
||||||
use function Activitypub\get_rest_url_by_path;
|
use function Activitypub\get_rest_url_by_path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,7 +17,9 @@ class Nodeinfo {
|
||||||
* Initialize the class, registering WordPress hooks
|
* Initialize the class, registering WordPress hooks
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
self::register_routes();
|
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
||||||
|
\add_filter( 'nodeinfo_data', array( self::class, 'add_nodeinfo_discovery' ), 10, 2 );
|
||||||
|
\add_filter( 'nodeinfo2_data', array( self::class, 'add_nodeinfo2_discovery' ), 10 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -84,14 +84,24 @@ class Nodeinfo {
|
||||||
'version' => \get_bloginfo( 'version' ),
|
'version' => \get_bloginfo( 'version' ),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$users = \get_users(
|
||||||
|
array(
|
||||||
|
'capability__in' => array( 'publish_posts' ),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( is_array( $users ) ) {
|
||||||
|
$users = count( $users );
|
||||||
|
} else {
|
||||||
|
$users = 1;
|
||||||
|
}
|
||||||
|
|
||||||
$posts = \wp_count_posts();
|
$posts = \wp_count_posts();
|
||||||
$comments = \wp_count_comments();
|
$comments = \wp_count_comments();
|
||||||
|
|
||||||
$nodeinfo['usage'] = array(
|
$nodeinfo['usage'] = array(
|
||||||
'users' => array(
|
'users' => array(
|
||||||
'total' => get_total_users(),
|
'total' => $users,
|
||||||
'activeMonth' => get_active_users( '1 month ago' ),
|
|
||||||
'activeHalfyear' => get_active_users( '6 month ago' ),
|
|
||||||
),
|
),
|
||||||
'localPosts' => (int) $posts->publish,
|
'localPosts' => (int) $posts->publish,
|
||||||
'localComments' => (int) $comments->approved,
|
'localComments' => (int) $comments->approved,
|
||||||
|
@ -131,14 +141,24 @@ class Nodeinfo {
|
||||||
'version' => \get_bloginfo( 'version' ),
|
'version' => \get_bloginfo( 'version' ),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$users = \get_users(
|
||||||
|
array(
|
||||||
|
'capability__in' => array( 'publish_posts' ),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( is_array( $users ) ) {
|
||||||
|
$users = count( $users );
|
||||||
|
} else {
|
||||||
|
$users = 1;
|
||||||
|
}
|
||||||
|
|
||||||
$posts = \wp_count_posts();
|
$posts = \wp_count_posts();
|
||||||
$comments = \wp_count_comments();
|
$comments = \wp_count_comments();
|
||||||
|
|
||||||
$nodeinfo['usage'] = array(
|
$nodeinfo['usage'] = array(
|
||||||
'users' => array(
|
'users' => array(
|
||||||
'total' => get_total_users(),
|
'total' => (int) $users,
|
||||||
'activeMonth' => get_active_users( 1 ),
|
|
||||||
'activeHalfyear' => get_active_users( 6 ),
|
|
||||||
),
|
),
|
||||||
'localPosts' => (int) $posts->publish,
|
'localPosts' => (int) $posts->publish,
|
||||||
'localComments' => (int) $comments->approved,
|
'localComments' => (int) $comments->approved,
|
||||||
|
@ -173,4 +193,36 @@ class Nodeinfo {
|
||||||
|
|
||||||
return new \WP_REST_Response( $discovery, 200 );
|
return new \WP_REST_Response( $discovery, 200 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extend NodeInfo data
|
||||||
|
*
|
||||||
|
* @param array $nodeinfo NodeInfo data
|
||||||
|
* @param string The NodeInfo Version
|
||||||
|
*
|
||||||
|
* @return array The extended array
|
||||||
|
*/
|
||||||
|
public static function add_nodeinfo_discovery( $nodeinfo, $version ) {
|
||||||
|
if ( '2.0' === $version ) {
|
||||||
|
$nodeinfo['protocols'][] = 'activitypub';
|
||||||
|
} else {
|
||||||
|
$nodeinfo['protocols']['inbound'][] = 'activitypub';
|
||||||
|
$nodeinfo['protocols']['outbound'][] = 'activitypub';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $nodeinfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extend NodeInfo2 data
|
||||||
|
*
|
||||||
|
* @param array $nodeinfo NodeInfo2 data
|
||||||
|
*
|
||||||
|
* @return array The extended array
|
||||||
|
*/
|
||||||
|
public static function add_nodeinfo2_discovery( $nodeinfo ) {
|
||||||
|
$nodeinfo['protocols'][] = 'activitypub';
|
||||||
|
|
||||||
|
return $nodeinfo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
33
includes/rest/class-ostatus.php
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
namespace Activitypub\Rest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ActivityPub OStatus REST-Class
|
||||||
|
*
|
||||||
|
* @author Matthias Pfefferle
|
||||||
|
*
|
||||||
|
* @see https://www.w3.org/community/ostatus/
|
||||||
|
*/
|
||||||
|
class Ostatus {
|
||||||
|
/**
|
||||||
|
* Register routes
|
||||||
|
*/
|
||||||
|
public static function register_routes() {
|
||||||
|
\register_rest_route(
|
||||||
|
ACTIVITYPUB_REST_NAMESPACE,
|
||||||
|
'/ostatus/remote-follow',
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'methods' => \WP_REST_Server::READABLE,
|
||||||
|
'callback' => array( '\Activitypub\Rest\Ostatus', 'get' ),
|
||||||
|
// 'args' => self::request_parameters(),
|
||||||
|
'permission_callback' => '__return_true',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get() {
|
||||||
|
// @todo implement
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,7 +5,8 @@ use stdClass;
|
||||||
use WP_Error;
|
use WP_Error;
|
||||||
use WP_REST_Server;
|
use WP_REST_Server;
|
||||||
use WP_REST_Response;
|
use WP_REST_Response;
|
||||||
use Activitypub\Transformer\Transformers_Manager;
|
use Activitypub\Validator\Query;
|
||||||
|
use Activitypub\Transformer\Post;
|
||||||
use Activitypub\Activity\Activity;
|
use Activitypub\Activity\Activity;
|
||||||
use Activitypub\Collection\Users as User_Collection;
|
use Activitypub\Collection\Users as User_Collection;
|
||||||
|
|
||||||
|
@ -24,7 +25,7 @@ class Outbox {
|
||||||
* Initialize the class, registering WordPress hooks
|
* Initialize the class, registering WordPress hooks
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
self::register_routes();
|
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,7 +39,7 @@ class Outbox {
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::READABLE,
|
'methods' => WP_REST_Server::READABLE,
|
||||||
'callback' => array( self::class, 'user_outbox_get' ),
|
'callback' => array( self::class, 'user_outbox_get' ),
|
||||||
'args' => self::request_parameters(),
|
'args' => Query::get_default_args(),
|
||||||
'permission_callback' => '__return_true',
|
'permission_callback' => '__return_true',
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -59,7 +60,7 @@ class Outbox {
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
$post_types = array_keys( \get_option( 'activitypub_transformer_mapping', array( 'post' => 'activitypub/default', 'page' => 'activitypub/default' ) ) );
|
$post_types = \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) );
|
||||||
|
|
||||||
$page = $request->get_param( 'page', 1 );
|
$page = $request->get_param( 'page', 1 );
|
||||||
|
|
||||||
|
@ -105,8 +106,7 @@ class Outbox {
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ( $posts as $post ) {
|
foreach ( $posts as $post ) {
|
||||||
$transformer = \Activitypub\Transformer\Transformers_Manager::instance()->get_transformer( $post );
|
$post = Post::transform( $post )->to_object();
|
||||||
$post = $transformer->to_object();
|
|
||||||
$activity = new Activity();
|
$activity = new Activity();
|
||||||
$activity->set_type( 'Create' );
|
$activity->set_type( 'Create' );
|
||||||
$activity->set_context( null );
|
$activity->set_context( null );
|
||||||
|
@ -117,37 +117,17 @@ class Outbox {
|
||||||
}
|
}
|
||||||
|
|
||||||
// filter output
|
// filter output
|
||||||
$json = \apply_filters( 'activitypub_rest_outbox_array', $json );
|
$json = \apply_filters( 'activitypub_outbox_array', $json );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Action triggerd after the ActivityPub profile has been created and sent to the client
|
* Action triggerd after the ActivityPub profile has been created and sent to the client
|
||||||
*/
|
*/
|
||||||
\do_action( 'activitypub_outbox_post' );
|
\do_action( 'activitypub_outbox_post' );
|
||||||
|
|
||||||
$rest_response = new WP_REST_Response( $json, 200 );
|
$response = new WP_REST_Response( $json, 200 );
|
||||||
$rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) );
|
|
||||||
|
|
||||||
return $rest_response;
|
$response->header( 'Content-Type', 'application/activity+json' );
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
return $response;
|
||||||
* The supported parameters
|
|
||||||
*
|
|
||||||
* @return array list of parameters
|
|
||||||
*/
|
|
||||||
public static function request_parameters() {
|
|
||||||
$params = array();
|
|
||||||
|
|
||||||
$params['page'] = array(
|
|
||||||
'type' => 'integer',
|
|
||||||
'default' => 1,
|
|
||||||
);
|
|
||||||
|
|
||||||
$params['user_id'] = array(
|
|
||||||
'required' => true,
|
|
||||||
'type' => 'string',
|
|
||||||
);
|
|
||||||
|
|
||||||
return $params;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
namespace Activitypub\Rest;
|
namespace Activitypub\Rest;
|
||||||
|
|
||||||
use stdClass;
|
use stdClass;
|
||||||
use WP_Error;
|
|
||||||
use WP_REST_Response;
|
use WP_REST_Response;
|
||||||
use Activitypub\Signature;
|
use Activitypub\Signature;
|
||||||
use Activitypub\Model\Application_User;
|
use Activitypub\Model\Application_User;
|
||||||
|
@ -19,8 +18,7 @@ class Server {
|
||||||
* Initialize the class, registering WordPress hooks
|
* Initialize the class, registering WordPress hooks
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
self::register_routes();
|
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
||||||
|
|
||||||
\add_filter( 'rest_request_before_callbacks', array( self::class, 'authorize_activitypub_requests' ), 10, 3 );
|
\add_filter( 'rest_request_before_callbacks', array( self::class, 'authorize_activitypub_requests' ), 10, 3 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,17 +46,13 @@ class Server {
|
||||||
*/
|
*/
|
||||||
public static function application_actor() {
|
public static function application_actor() {
|
||||||
$user = new Application_User();
|
$user = new Application_User();
|
||||||
|
|
||||||
$user->set_context(
|
|
||||||
\Activitypub\Activity\Activity::CONTEXT
|
|
||||||
);
|
|
||||||
|
|
||||||
$json = $user->to_array();
|
$json = $user->to_array();
|
||||||
|
|
||||||
$rest_response = new WP_REST_Response( $json, 200 );
|
$response = new WP_REST_Response( $json, 200 );
|
||||||
$rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) );
|
|
||||||
|
|
||||||
return $rest_response;
|
$response->header( 'Content-Type', 'application/activity+json' );
|
||||||
|
|
||||||
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,49 +68,28 @@ class Server {
|
||||||
* @return mixed|WP_Error The response, error, or modified response.
|
* @return mixed|WP_Error The response, error, or modified response.
|
||||||
*/
|
*/
|
||||||
public static function authorize_activitypub_requests( $response, $handler, $request ) {
|
public static function authorize_activitypub_requests( $response, $handler, $request ) {
|
||||||
if ( 'HEAD' === $request->get_method() ) {
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
$route = $request->get_route();
|
$route = $request->get_route();
|
||||||
|
|
||||||
// check if it is an activitypub request and exclude webfinger and nodeinfo endpoints
|
// check if it is an activitypub request and exclude webfinger and nodeinfo endpoints
|
||||||
if (
|
if (
|
||||||
! \str_starts_with( $route, '/' . ACTIVITYPUB_REST_NAMESPACE ) ||
|
! str_starts_with( $route, '/' . ACTIVITYPUB_REST_NAMESPACE ) ||
|
||||||
\str_starts_with( $route, '/' . \trailingslashit( ACTIVITYPUB_REST_NAMESPACE ) . 'webfinger' ) ||
|
str_starts_with( $route, '/' . \trailingslashit( ACTIVITYPUB_REST_NAMESPACE ) . 'webfinger' ) ||
|
||||||
\str_starts_with( $route, '/' . \trailingslashit( ACTIVITYPUB_REST_NAMESPACE ) . 'nodeinfo' )
|
str_starts_with( $route, '/' . \trailingslashit( ACTIVITYPUB_REST_NAMESPACE ) . 'nodeinfo' )
|
||||||
) {
|
) {
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Filter to defer signature verification
|
|
||||||
*
|
|
||||||
* Skip signature verification for debugging purposes or to reduce load for
|
|
||||||
* certain Activity-Types, like "Delete".
|
|
||||||
*
|
|
||||||
* @param bool $defer Whether to defer signature verification.
|
|
||||||
* @param WP_REST_Request $request The request used to generate the response.
|
|
||||||
*
|
|
||||||
* @return bool Whether to defer signature verification.
|
|
||||||
*/
|
|
||||||
$defer = \apply_filters( 'activitypub_defer_signature_verification', false, $request );
|
|
||||||
|
|
||||||
if ( $defer ) {
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
// POST-Requets are always signed
|
// POST-Requets are always signed
|
||||||
if ( 'GET' !== $request->get_method() ) {
|
if ( 'POST' === $request->get_method() ) {
|
||||||
$verified_request = Signature::verify_http_signature( $request );
|
$verified_request = Signature::verify_http_signature( $request );
|
||||||
if ( \is_wp_error( $verified_request ) ) {
|
if ( \is_wp_error( $verified_request ) ) {
|
||||||
return new WP_Error( 'activitypub_signature_verification', $verified_request->get_error_message(), array( 'status' => 401 ) );
|
return $verified_request;
|
||||||
}
|
}
|
||||||
} elseif ( 'GET' === $request->get_method() ) { // GET-Requests are only signed in secure mode
|
} elseif ( 'GET' === $request->get_method() ) { // GET-Requests are only signed in secure mode
|
||||||
if ( ACTIVITYPUB_AUTHORIZED_FETCH ) {
|
if ( ACTIVITYPUB_SECURE_MODE ) {
|
||||||
$verified_request = Signature::verify_http_signature( $request );
|
$verified_request = Signature::verify_http_signature( $request );
|
||||||
if ( \is_wp_error( $verified_request ) ) {
|
if ( \is_wp_error( $verified_request ) ) {
|
||||||
return new WP_Error( 'activitypub_signature_verification', $verified_request->get_error_message(), array( 'status' => 401 ) );
|
return $verified_request;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,8 @@ namespace Activitypub\Rest;
|
||||||
|
|
||||||
use WP_Error;
|
use WP_Error;
|
||||||
use WP_REST_Server;
|
use WP_REST_Server;
|
||||||
use WP_REST_Request;
|
|
||||||
use WP_REST_Response;
|
use WP_REST_Response;
|
||||||
use Activitypub\Webfinger;
|
use Activitypub\Validator\Query;
|
||||||
use Activitypub\Activity\Activity;
|
use Activitypub\Activity\Activity;
|
||||||
use Activitypub\Collection\Users as User_Collection;
|
use Activitypub\Collection\Users as User_Collection;
|
||||||
|
|
||||||
|
@ -23,7 +22,7 @@ class Users {
|
||||||
* Initialize the class, registering WordPress hooks
|
* Initialize the class, registering WordPress hooks
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
self::register_routes();
|
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,26 +36,7 @@ class Users {
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::READABLE,
|
'methods' => WP_REST_Server::READABLE,
|
||||||
'callback' => array( self::class, 'get' ),
|
'callback' => array( self::class, 'get' ),
|
||||||
'args' => self::request_parameters(),
|
'args' => Query::get_default_args(),
|
||||||
'permission_callback' => '__return_true',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
\register_rest_route(
|
|
||||||
ACTIVITYPUB_REST_NAMESPACE,
|
|
||||||
'/users/(?P<user_id>[\w\-\.]+)/remote-follow',
|
|
||||||
array(
|
|
||||||
array(
|
|
||||||
'methods' => WP_REST_Server::READABLE,
|
|
||||||
'callback' => array( self::class, 'remote_follow_get' ),
|
|
||||||
|
|
||||||
'args' => array(
|
|
||||||
'resource' => array(
|
|
||||||
'required' => true,
|
|
||||||
'sanitize_callback' => 'sanitize_text_field',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'permission_callback' => '__return_true',
|
'permission_callback' => '__return_true',
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -95,61 +75,9 @@ class Users {
|
||||||
|
|
||||||
$json = $user->to_array();
|
$json = $user->to_array();
|
||||||
|
|
||||||
$rest_response = new WP_REST_Response( $json, 200 );
|
$response = new WP_REST_Response( $json, 200 );
|
||||||
$rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) );
|
$response->header( 'Content-Type', 'application/activity+json' );
|
||||||
|
|
||||||
return $rest_response;
|
return $response;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Endpoint for remote follow UI/Block
|
|
||||||
*
|
|
||||||
* @param WP_REST_Request $request The request object.
|
|
||||||
*
|
|
||||||
* @return void|string The URL to the remote follow page
|
|
||||||
*/
|
|
||||||
public static function remote_follow_get( WP_REST_Request $request ) {
|
|
||||||
$resource = $request->get_param( 'resource' );
|
|
||||||
$user_id = $request->get_param( 'user_id' );
|
|
||||||
$user = User_Collection::get_by_various( $user_id );
|
|
||||||
|
|
||||||
if ( is_wp_error( $user ) ) {
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
$template = Webfinger::get_remote_follow_endpoint( $resource );
|
|
||||||
|
|
||||||
if ( is_wp_error( $template ) ) {
|
|
||||||
return $template;
|
|
||||||
}
|
|
||||||
|
|
||||||
$resource = $user->get_resource();
|
|
||||||
$url = str_replace( '{uri}', $resource, $template );
|
|
||||||
|
|
||||||
return new WP_REST_Response(
|
|
||||||
array( 'url' => $url ),
|
|
||||||
200
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The supported parameters
|
|
||||||
*
|
|
||||||
* @return array list of parameters
|
|
||||||
*/
|
|
||||||
public static function request_parameters() {
|
|
||||||
$params = array();
|
|
||||||
|
|
||||||
$params['page'] = array(
|
|
||||||
'type' => 'string',
|
|
||||||
);
|
|
||||||
|
|
||||||
$params['user_id'] = array(
|
|
||||||
'required' => true,
|
|
||||||
'type' => 'string',
|
|
||||||
);
|
|
||||||
|
|
||||||
return $params;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,9 @@ class Webfinger {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
self::register_routes();
|
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
||||||
|
\add_filter( 'webfinger_user_data', array( self::class, 'add_user_discovery' ), 10, 3 );
|
||||||
|
\add_filter( 'webfinger_data', array( self::class, 'add_pseudo_user_discovery' ), 99, 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,7 +37,7 @@ class Webfinger {
|
||||||
array(
|
array(
|
||||||
'methods' => \WP_REST_Server::READABLE,
|
'methods' => \WP_REST_Server::READABLE,
|
||||||
'callback' => array( self::class, 'webfinger' ),
|
'callback' => array( self::class, 'webfinger' ),
|
||||||
'args' => self::request_parameters(),
|
'args' => self::request_args(),
|
||||||
'permission_callback' => '__return_true',
|
'permission_callback' => '__return_true',
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -66,16 +68,54 @@ class Webfinger {
|
||||||
*
|
*
|
||||||
* @return array list of parameters
|
* @return array list of parameters
|
||||||
*/
|
*/
|
||||||
public static function request_parameters() {
|
public static function request_args() {
|
||||||
$params = array();
|
$args = array();
|
||||||
|
|
||||||
$params['resource'] = array(
|
$args['resource'] = array(
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'pattern' => '^acct:(.+)@(.+)$',
|
'pattern' => '^acct:(.+)@(.+)$',
|
||||||
);
|
);
|
||||||
|
|
||||||
return $params;
|
return $args;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add WebFinger discovery links
|
||||||
|
*
|
||||||
|
* @param array $array the jrd array
|
||||||
|
* @param string $resource the WebFinger resource
|
||||||
|
* @param WP_User $user the WordPress user
|
||||||
|
*
|
||||||
|
* @return array the jrd array
|
||||||
|
*/
|
||||||
|
public static function add_user_discovery( $array, $resource, $user ) {
|
||||||
|
$user = User_Collection::get_by_id( $user->ID );
|
||||||
|
|
||||||
|
$array['links'][] = array(
|
||||||
|
'rel' => 'self',
|
||||||
|
'type' => 'application/activity+json',
|
||||||
|
'href' => $user->get_url(),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add WebFinger discovery links
|
||||||
|
*
|
||||||
|
* @param array $array the jrd array
|
||||||
|
* @param string $resource the WebFinger resource
|
||||||
|
* @param WP_User $user the WordPress user
|
||||||
|
*
|
||||||
|
* @return array the jrd array
|
||||||
|
*/
|
||||||
|
public static function add_pseudo_user_discovery( $array, $resource ) {
|
||||||
|
if ( $array ) {
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::get_profile( $resource );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -32,22 +32,17 @@ class Followers extends WP_List_Table {
|
||||||
return array(
|
return array(
|
||||||
'cb' => '<input type="checkbox" />',
|
'cb' => '<input type="checkbox" />',
|
||||||
'avatar' => \__( 'Avatar', 'activitypub' ),
|
'avatar' => \__( 'Avatar', 'activitypub' ),
|
||||||
'post_title' => \__( 'Name', 'activitypub' ),
|
'name' => \__( 'Name', 'activitypub' ),
|
||||||
'username' => \__( 'Username', 'activitypub' ),
|
'username' => \__( 'Username', 'activitypub' ),
|
||||||
'url' => \__( 'URL', 'activitypub' ),
|
'url' => \__( 'URL', 'activitypub' ),
|
||||||
'published' => \__( 'Followed', 'activitypub' ),
|
'updated' => \__( 'Last updated', 'activitypub' ),
|
||||||
'modified' => \__( 'Last updated', 'activitypub' ),
|
//'errors' => \__( 'Errors', 'activitypub' ),
|
||||||
|
//'latest-error' => \__( 'Latest Error Message', 'activitypub' ),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_sortable_columns() {
|
public function get_sortable_columns() {
|
||||||
$sortable_columns = array(
|
return array();
|
||||||
'post_title' => array( 'post_title', true ),
|
|
||||||
'modified' => array( 'modified', false ),
|
|
||||||
'published' => array( 'published', false ),
|
|
||||||
);
|
|
||||||
|
|
||||||
return $sortable_columns;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function prepare_items() {
|
public function prepare_items() {
|
||||||
|
@ -60,32 +55,8 @@ class Followers extends WP_List_Table {
|
||||||
$page_num = $this->get_pagenum();
|
$page_num = $this->get_pagenum();
|
||||||
$per_page = 20;
|
$per_page = 20;
|
||||||
|
|
||||||
$args = array();
|
$followers = FollowerCollection::get_followers( $this->user_id, $per_page, $page_num );
|
||||||
|
$counter = FollowerCollection::count_followers( $this->user_id );
|
||||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
|
||||||
if ( isset( $_GET['orderby'] ) ) {
|
|
||||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
|
||||||
$args['orderby'] = sanitize_text_field( wp_unslash( $_GET['orderby'] ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
|
||||||
if ( isset( $_GET['order'] ) ) {
|
|
||||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
|
||||||
$args['order'] = sanitize_text_field( wp_unslash( $_GET['order'] ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
|
||||||
if ( isset( $_GET['s'] ) && isset( $_REQUEST['_wpnonce'] ) ) {
|
|
||||||
$nonce = sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) );
|
|
||||||
if ( wp_verify_nonce( $nonce, 'bulk-' . $this->_args['plural'] ) ) {
|
|
||||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
|
||||||
$args['s'] = sanitize_text_field( wp_unslash( $_GET['s'] ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$followers_with_count = FollowerCollection::get_followers_with_count( $this->user_id, $per_page, $page_num, $args );
|
|
||||||
$followers = $followers_with_count['followers'];
|
|
||||||
$counter = $followers_with_count['total'];
|
|
||||||
|
|
||||||
$this->items = array();
|
$this->items = array();
|
||||||
$this->set_pagination_args(
|
$this->set_pagination_args(
|
||||||
|
@ -99,12 +70,13 @@ class Followers extends WP_List_Table {
|
||||||
foreach ( $followers as $follower ) {
|
foreach ( $followers as $follower ) {
|
||||||
$item = array(
|
$item = array(
|
||||||
'icon' => esc_attr( $follower->get_icon_url() ),
|
'icon' => esc_attr( $follower->get_icon_url() ),
|
||||||
'post_title' => esc_attr( $follower->get_name() ),
|
'name' => esc_attr( $follower->get_name() ),
|
||||||
'username' => esc_attr( $follower->get_preferred_username() ),
|
'username' => esc_attr( $follower->get_preferred_username() ),
|
||||||
'url' => esc_attr( $follower->get_url() ),
|
'url' => esc_attr( $follower->get_url() ),
|
||||||
'identifier' => esc_attr( $follower->get_id() ),
|
'identifier' => esc_attr( $follower->get_id() ),
|
||||||
'published' => esc_attr( $follower->get_published() ),
|
'updated' => esc_attr( $follower->get_updated() ),
|
||||||
'modified' => esc_attr( $follower->get_updated() ),
|
'errors' => $follower->count_errors(),
|
||||||
|
'latest-error' => $follower->get_latest_error_message(),
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->items[] = $item;
|
$this->items[] = $item;
|
||||||
|
@ -144,11 +116,11 @@ class Followers extends WP_List_Table {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function process_action() {
|
public function process_action() {
|
||||||
if ( ! isset( $_REQUEST['followers'] ) || ! isset( $_REQUEST['_wpnonce'] ) ) {
|
if ( ! isset( $_REQUEST['followers'] ) || ! isset( $_REQUEST['_apnonce'] ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$nonce = sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) );
|
$nonce = sanitize_text_field( wp_unslash( $_REQUEST['_apnonce'] ) );
|
||||||
if ( ! wp_verify_nonce( $nonce, 'bulk-' . $this->_args['plural'] ) ) {
|
if ( ! wp_verify_nonce( $nonce, 'activitypub-followers-list' ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,619 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Inspired by the PHP ActivityPub Library by @Landrok
|
|
||||||
*
|
|
||||||
* @link https://github.com/landrok/activitypub
|
|
||||||
*/
|
|
||||||
namespace Activitypub\Transformer;
|
|
||||||
|
|
||||||
use WP_Post;
|
|
||||||
use Activitypub\Collection\Users;
|
|
||||||
use Activitypub\Model\Blog_User;
|
|
||||||
use Activitypub\Activity\Base_Object;
|
|
||||||
use Activitypub\Shortcodes;
|
|
||||||
|
|
||||||
use function Activitypub\esc_hashtag;
|
|
||||||
use function Activitypub\is_single_user;
|
|
||||||
use function Activitypub\get_rest_url_by_path;
|
|
||||||
use function Activitypub\site_supports_blocks;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base class to implement WordPress to ActivityPub transformers.
|
|
||||||
*/
|
|
||||||
abstract class Base {
|
|
||||||
/**
|
|
||||||
* The WP_Post object.
|
|
||||||
*
|
|
||||||
* @var WP_Post
|
|
||||||
*/
|
|
||||||
protected $wp_post;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Assign WP_Post Object to a specific transformer instance.
|
|
||||||
*
|
|
||||||
* This helps to chain the output of the Transformer.
|
|
||||||
*
|
|
||||||
* @param WP_Post $wp_post The WP_Post object.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function set_wp_post( WP_Post $wp_post ) {
|
|
||||||
$post_type = get_post_type( $wp_post );
|
|
||||||
if ( ! $this->supports_post_type( $post_type ) ) {
|
|
||||||
_doing_it_wrong(
|
|
||||||
__METHOD__,
|
|
||||||
/* translators: %s: Block name. */
|
|
||||||
sprintf( 'The Transformer "%s" does not support the post type "%s".', esc_html( $this->get_label() ), esc_html( $post_type ) ),
|
|
||||||
'version_number_transformer_management_placeholder'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
$this->wp_post = $wp_post;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the supported WP post types that the transformer can use as an input.
|
|
||||||
*
|
|
||||||
* By default all post types are supported.
|
|
||||||
* You may very likely wish to override this function.
|
|
||||||
*
|
|
||||||
* @since version_number_transformer_management_placeholder
|
|
||||||
* @return string[] An array containing all the supported post types.
|
|
||||||
*/
|
|
||||||
public function get_supported_post_types() {
|
|
||||||
return \get_post_types( array( 'public' => true ), 'names' );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the name of the plugin that registered the transformer.
|
|
||||||
*
|
|
||||||
* @see Forked from the WordPress elementor plugin.
|
|
||||||
* @since version_number_transformer_management_placeholder
|
|
||||||
* @return string Plugin name
|
|
||||||
*/
|
|
||||||
private function get_plugin_name_from_transformer_instance( $transformer ) {
|
|
||||||
$class_reflection = new \ReflectionClass( $transformer );
|
|
||||||
|
|
||||||
$plugin_basename = plugin_basename( $class_reflection->getFileName() );
|
|
||||||
|
|
||||||
$plugin_directory = strtok( $plugin_basename, '/' );
|
|
||||||
|
|
||||||
$plugins_data = get_plugins( '/' . $plugin_directory );
|
|
||||||
$plugin_data = array_shift( $plugins_data );
|
|
||||||
|
|
||||||
if ( isset( $plugin_data['Name'] ) ) {
|
|
||||||
return $plugin_data['Name'];
|
|
||||||
} else {
|
|
||||||
return esc_html__( 'Unknown', 'activitypub' );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return whether the transformer supports a post type.
|
|
||||||
*
|
|
||||||
* @since version_number_transformer_management_placeholder
|
|
||||||
* @return string post_type Post type name.
|
|
||||||
*/
|
|
||||||
final public function supports_post_type( $post_type ) {
|
|
||||||
return in_array( $post_type, $this->get_supported_post_types(), true );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the name used for registering the transformer with the ActivityPub plugin.
|
|
||||||
*
|
|
||||||
* @since version_number_transformer_management_placeholder
|
|
||||||
* @return string name
|
|
||||||
*/
|
|
||||||
abstract public function get_name();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the display name for the ActivityPub transformer.
|
|
||||||
*
|
|
||||||
* @since version_number_transformer_management_placeholder
|
|
||||||
* @return string display name
|
|
||||||
*/
|
|
||||||
abstract public function get_label();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the ActivityStreams 2.0 Object-Type for a Post.
|
|
||||||
*
|
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#activity-types
|
|
||||||
*
|
|
||||||
* @return string The Object-Type.
|
|
||||||
*/
|
|
||||||
abstract protected function get_object_type();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the content for the ActivityPub Item.
|
|
||||||
*
|
|
||||||
* The content will be generated based on the user settings.
|
|
||||||
*
|
|
||||||
* @return string The content.
|
|
||||||
*/
|
|
||||||
protected function get_content() {
|
|
||||||
global $post;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides an action hook so plugins can add their own hooks/filters before AP content is generated.
|
|
||||||
*
|
|
||||||
* Example: if a plugin adds a filter to `the_content` to add a button to the end of posts, it can also remove that filter here.
|
|
||||||
*
|
|
||||||
* @param WP_Post $post The post object.
|
|
||||||
*/
|
|
||||||
do_action( 'activitypub_before_get_content', $post );
|
|
||||||
|
|
||||||
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
|
||||||
$post = $this->wp_post;
|
|
||||||
$content = $this->get_post_content_template();
|
|
||||||
|
|
||||||
// Register our shortcodes just in time.
|
|
||||||
Shortcodes::register();
|
|
||||||
// Fill in the shortcodes.
|
|
||||||
setup_postdata( $post );
|
|
||||||
$content = do_shortcode( $content );
|
|
||||||
wp_reset_postdata();
|
|
||||||
|
|
||||||
$content = \wpautop( $content );
|
|
||||||
$content = \preg_replace( '/[\n\r\t]/', '', $content );
|
|
||||||
$content = \trim( $content );
|
|
||||||
|
|
||||||
$content = \apply_filters( 'activitypub_the_content', $content, $post );
|
|
||||||
|
|
||||||
// Don't need these any more, should never appear in a post.
|
|
||||||
Shortcodes::unregister();
|
|
||||||
|
|
||||||
return $content;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the template to use to generate the content of the activitypub item.
|
|
||||||
*
|
|
||||||
* @return string The Template.
|
|
||||||
*/
|
|
||||||
protected function get_post_content_template() {
|
|
||||||
if ( 'excerpt' === \get_option( 'activitypub_post_content_type', 'content' ) ) {
|
|
||||||
return "[ap_excerpt]\n\n[ap_permalink type=\"html\"]";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( 'title' === \get_option( 'activitypub_post_content_type', 'content' ) ) {
|
|
||||||
return "[ap_title]\n\n[ap_permalink type=\"html\"]";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( 'content' === \get_option( 'activitypub_post_content_type', 'content' ) ) {
|
|
||||||
return "[ap_content]\n\n[ap_permalink type=\"html\"]\n\n[ap_hashtags]";
|
|
||||||
}
|
|
||||||
|
|
||||||
return \get_option( 'activitypub_custom_post_content', ACTIVITYPUB_CUSTOM_POST_CONTENT );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the ID of the Post.
|
|
||||||
*
|
|
||||||
* @return string The Posts ID.
|
|
||||||
*/
|
|
||||||
public function get_id() {
|
|
||||||
return $this->get_url();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the URL of the Post.
|
|
||||||
*
|
|
||||||
* @return string The Posts URL.
|
|
||||||
*/
|
|
||||||
public function get_url() {
|
|
||||||
$post = $this->wp_post;
|
|
||||||
|
|
||||||
if ( 'trash' === get_post_status( $post ) ) {
|
|
||||||
$permalink = \get_post_meta( $post->ID, 'activitypub_canonical_url', true );
|
|
||||||
} else {
|
|
||||||
$permalink = \get_permalink( $post );
|
|
||||||
}
|
|
||||||
|
|
||||||
return \esc_url( $permalink );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the User-URL of the Author of the Post.
|
|
||||||
*
|
|
||||||
* If `single_user` mode is enabled, the URL of the Blog-User is returned.
|
|
||||||
*
|
|
||||||
* @return string The User-URL.
|
|
||||||
*/
|
|
||||||
protected function get_attributed_to() {
|
|
||||||
if ( is_single_user() ) {
|
|
||||||
$user = new Blog_User();
|
|
||||||
return $user->get_url();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Users::get_by_id( $this->wp_post->post_author )->get_url();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates all Media Attachments for a Post.
|
|
||||||
*
|
|
||||||
* @return array The Attachments.
|
|
||||||
*/
|
|
||||||
protected function get_attachments() {
|
|
||||||
// Once upon a time we only supported images, but we now support audio/video as well.
|
|
||||||
// We maintain the image-centric naming for backwards compatibility.
|
|
||||||
$max_media = intval( \apply_filters( 'activitypub_max_image_attachments', \get_option( 'activitypub_max_image_attachments', ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS ) ) );
|
|
||||||
|
|
||||||
if ( site_supports_blocks() && \has_blocks( $this->wp_post->post_content ) ) {
|
|
||||||
return $this->get_block_attachments( $max_media );
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->get_classic_editor_images( $max_media );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get media attachments from blocks. They will be formatted as ActivityPub attachments, not as WP attachments.
|
|
||||||
*
|
|
||||||
* @param int $max_media The maximum number of attachments to return.
|
|
||||||
*
|
|
||||||
* @return array The attachments.
|
|
||||||
*/
|
|
||||||
protected function get_block_attachments( $max_media ) {
|
|
||||||
// max media can't be negative or zero
|
|
||||||
if ( $max_media <= 0 ) {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$id = $this->wp_post->ID;
|
|
||||||
|
|
||||||
$media_ids = array();
|
|
||||||
|
|
||||||
// list post thumbnail first if this post has one
|
|
||||||
if ( \function_exists( 'has_post_thumbnail' ) && \has_post_thumbnail( $id ) ) {
|
|
||||||
$media_ids[] = \get_post_thumbnail_id( $id );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $max_media > 0 ) {
|
|
||||||
$blocks = \parse_blocks( $this->wp_post->post_content );
|
|
||||||
$media_ids = self::get_media_ids_from_blocks( $blocks, $media_ids, $max_media );
|
|
||||||
}
|
|
||||||
|
|
||||||
return \array_filter( \array_map( array( self::class, 'wp_attachment_to_activity_attachment' ), $media_ids ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get image attachments from the classic editor.
|
|
||||||
* Note that audio/video attachments are only supported in the block editor.
|
|
||||||
*
|
|
||||||
* @param int $max_images The maximum number of images to return.
|
|
||||||
*
|
|
||||||
* @return array The attachments.
|
|
||||||
*/
|
|
||||||
protected function get_classic_editor_images( $max_images ) {
|
|
||||||
// max images can't be negative or zero
|
|
||||||
if ( $max_images <= 0 ) {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$id = $this->wp_post->ID;
|
|
||||||
|
|
||||||
$image_ids = array();
|
|
||||||
|
|
||||||
// list post thumbnail first if this post has one
|
|
||||||
if ( \function_exists( 'has_post_thumbnail' ) && \has_post_thumbnail( $id ) ) {
|
|
||||||
$image_ids[] = \get_post_thumbnail_id( $id );
|
|
||||||
--$max_images;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $max_images > 0 ) {
|
|
||||||
$query = new \WP_Query(
|
|
||||||
array(
|
|
||||||
'post_parent' => $id,
|
|
||||||
'post_status' => 'inherit',
|
|
||||||
'post_type' => 'attachment',
|
|
||||||
'post_mime_type' => 'image',
|
|
||||||
'order' => 'ASC',
|
|
||||||
'orderby' => 'menu_order ID',
|
|
||||||
'posts_per_page' => $max_images,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
foreach ( $query->get_posts() as $attachment ) {
|
|
||||||
if ( ! \in_array( $attachment->ID, $image_ids, true ) ) {
|
|
||||||
$image_ids[] = $attachment->ID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$image_ids = \array_unique( $image_ids );
|
|
||||||
|
|
||||||
return \array_filter( \array_map( array( self::class, 'wp_attachment_to_activity_attachment' ), $image_ids ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Recursively get media IDs from blocks.
|
|
||||||
*
|
|
||||||
* @param array $blocks The blocks to search for media IDs
|
|
||||||
* @param array $media_ids The media IDs to append new IDs to
|
|
||||||
* @param int $max_media The maximum number of media to return.
|
|
||||||
*
|
|
||||||
* @return array The image IDs.
|
|
||||||
*/
|
|
||||||
protected static function get_media_ids_from_blocks( $blocks, $media_ids, $max_media ) {
|
|
||||||
|
|
||||||
foreach ( $blocks as $block ) {
|
|
||||||
// recurse into inner blocks
|
|
||||||
if ( ! empty( $block['innerBlocks'] ) ) {
|
|
||||||
$media_ids = self::get_media_ids_from_blocks( $block['innerBlocks'], $media_ids, $max_media );
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ( $block['blockName'] ) {
|
|
||||||
case 'core/image':
|
|
||||||
case 'core/cover':
|
|
||||||
case 'core/audio':
|
|
||||||
case 'core/video':
|
|
||||||
case 'videopress/video':
|
|
||||||
if ( ! empty( $block['attrs']['id'] ) ) {
|
|
||||||
$media_ids[] = $block['attrs']['id'];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'jetpack/slideshow':
|
|
||||||
case 'jetpack/tiled-gallery':
|
|
||||||
if ( ! empty( $block['attrs']['ids'] ) ) {
|
|
||||||
$media_ids = array_merge( $media_ids, $block['attrs']['ids'] );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'jetpack/image-compare':
|
|
||||||
if ( ! empty( $block['attrs']['beforeImageId'] ) ) {
|
|
||||||
$media_ids[] = $block['attrs']['beforeImageId'];
|
|
||||||
}
|
|
||||||
if ( ! empty( $block['attrs']['afterImageId'] ) ) {
|
|
||||||
$media_ids[] = $block['attrs']['afterImageId'];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// depupe
|
|
||||||
$media_ids = \array_unique( $media_ids );
|
|
||||||
|
|
||||||
// stop doing unneeded work
|
|
||||||
if ( count( $media_ids ) >= $max_media ) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// still need to slice it because one gallery could knock us over the limit
|
|
||||||
return array_slice( $media_ids, 0, $max_media );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a WordPress Attachment to an ActivityPub Attachment.
|
|
||||||
*
|
|
||||||
* @param int $id The Attachment ID.
|
|
||||||
*
|
|
||||||
* @return array The ActivityPub Attachment.
|
|
||||||
*/
|
|
||||||
public static function wp_attachment_to_activity_attachment( $id ) {
|
|
||||||
$attachment = array();
|
|
||||||
$mime_type = \get_post_mime_type( $id );
|
|
||||||
$mime_type_parts = \explode( '/', $mime_type );
|
|
||||||
// switching on image/audio/video
|
|
||||||
switch ( $mime_type_parts[0] ) {
|
|
||||||
case 'image':
|
|
||||||
$image_size = 'full';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Filter the image URL returned for each post.
|
|
||||||
*
|
|
||||||
* @param array|false $thumbnail The image URL, or false if no image is available.
|
|
||||||
* @param int $id The attachment ID.
|
|
||||||
* @param string $image_size The image size to retrieve. Set to 'full' by default.
|
|
||||||
*/
|
|
||||||
$thumbnail = apply_filters(
|
|
||||||
'activitypub_get_image',
|
|
||||||
self::get_image( $id, $image_size ),
|
|
||||||
$id,
|
|
||||||
$image_size
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( $thumbnail ) {
|
|
||||||
$alt = \get_post_meta( $id, '_wp_attachment_image_alt', true );
|
|
||||||
$image = array(
|
|
||||||
'type' => 'Image',
|
|
||||||
'url' => $thumbnail[0],
|
|
||||||
'mediaType' => $mime_type,
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( $alt ) {
|
|
||||||
$image['name'] = $alt;
|
|
||||||
}
|
|
||||||
$attachment = $image;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'audio':
|
|
||||||
case 'video':
|
|
||||||
$attachment = array(
|
|
||||||
'type' => 'Document',
|
|
||||||
'mediaType' => $mime_type,
|
|
||||||
'url' => \wp_get_attachment_url( $id ),
|
|
||||||
'name' => \get_the_title( $id ),
|
|
||||||
);
|
|
||||||
$meta = wp_get_attachment_metadata( $id );
|
|
||||||
// height and width for videos
|
|
||||||
if ( isset( $meta['width'] ) && isset( $meta['height'] ) ) {
|
|
||||||
$attachment['width'] = $meta['width'];
|
|
||||||
$attachment['height'] = $meta['height'];
|
|
||||||
}
|
|
||||||
// @todo: add `icon` support for audio/video attachments. Maybe use post thumbnail?
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return \apply_filters( 'activitypub_attachment', $attachment, $id );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return details about an image attachment.
|
|
||||||
*
|
|
||||||
* @param int $id The attachment ID.
|
|
||||||
* @param string $image_size The image size to retrieve. Set to 'full' by default.
|
|
||||||
*
|
|
||||||
* @return array|false Array of image data, or boolean false if no image is available.
|
|
||||||
*/
|
|
||||||
protected static function get_image( $id, $image_size = 'full' ) {
|
|
||||||
/**
|
|
||||||
* Hook into the image retrieval process. Before image retrieval.
|
|
||||||
*
|
|
||||||
* @param int $id The attachment ID.
|
|
||||||
* @param string $image_size The image size to retrieve. Set to 'full' by default.
|
|
||||||
*/
|
|
||||||
do_action( 'activitypub_get_image_pre', $id, $image_size );
|
|
||||||
|
|
||||||
$image = \wp_get_attachment_image_src( $id, $image_size );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hook into the image retrieval process. After image retrieval.
|
|
||||||
*
|
|
||||||
* @param int $id The attachment ID.
|
|
||||||
* @param string $image_size The image size to retrieve. Set to 'full' by default.
|
|
||||||
*/
|
|
||||||
do_action( 'activitypub_get_image_post', $id, $image_size );
|
|
||||||
|
|
||||||
return $image;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function to get the @-Mentions from the post content.
|
|
||||||
*
|
|
||||||
* @return array The list of @-Mentions.
|
|
||||||
*/
|
|
||||||
protected function get_mentions() {
|
|
||||||
return apply_filters( 'activitypub_extract_mentions', array(), $this->wp_post->post_content, $this->wp_post );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a list of Mentions, used in the Post.
|
|
||||||
*
|
|
||||||
* @see https://docs.joinmastodon.org/spec/activitypub/#Mention
|
|
||||||
*
|
|
||||||
* @return array The list of Mentions.
|
|
||||||
*/
|
|
||||||
protected function get_cc() {
|
|
||||||
$cc = array();
|
|
||||||
|
|
||||||
$mentions = $this->get_mentions();
|
|
||||||
if ( $mentions ) {
|
|
||||||
foreach ( $mentions as $url ) {
|
|
||||||
$cc[] = $url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $cc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a list of Tags, used in the Post.
|
|
||||||
*
|
|
||||||
* This includes Hash-Tags and Mentions.
|
|
||||||
*
|
|
||||||
* @return array The list of Tags.
|
|
||||||
*/
|
|
||||||
protected function get_tags() {
|
|
||||||
$tags = array();
|
|
||||||
|
|
||||||
$post_tags = \get_the_tags( $this->wp_post->ID );
|
|
||||||
if ( $post_tags ) {
|
|
||||||
foreach ( $post_tags as $post_tag ) {
|
|
||||||
$tag = array(
|
|
||||||
'type' => 'Hashtag',
|
|
||||||
'href' => \esc_url( \get_tag_link( $post_tag->term_id ) ),
|
|
||||||
'name' => esc_hashtag( $post_tag->name ),
|
|
||||||
);
|
|
||||||
$tags[] = $tag;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$mentions = $this->get_mentions();
|
|
||||||
if ( $mentions ) {
|
|
||||||
foreach ( $mentions as $mention => $url ) {
|
|
||||||
$tag = array(
|
|
||||||
'type' => 'Mention',
|
|
||||||
'href' => \esc_url( $url ),
|
|
||||||
'name' => \esc_html( $mention ),
|
|
||||||
);
|
|
||||||
$tags[] = $tag;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $tags;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the locale of the post.
|
|
||||||
*
|
|
||||||
* @return string The locale of the post.
|
|
||||||
*/
|
|
||||||
public function get_locale() {
|
|
||||||
$post_id = $this->wp_post->ID;
|
|
||||||
$lang = \strtolower( \strtok( \get_locale(), '_-' ) );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Filter the locale of the post.
|
|
||||||
*
|
|
||||||
* @param string $lang The locale of the post.
|
|
||||||
* @param int $post_id The post ID.
|
|
||||||
* @param WP_Post $post The post object.
|
|
||||||
*
|
|
||||||
* @return string The filtered locale of the post.
|
|
||||||
*/
|
|
||||||
return apply_filters( 'activitypub_post_locale', $lang, $post_id, $this->wp_post );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the contentMap
|
|
||||||
*
|
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-contentmap
|
|
||||||
*
|
|
||||||
* @return array the contenmap
|
|
||||||
*/
|
|
||||||
protected function get_content_map() {
|
|
||||||
return array(
|
|
||||||
$this->get_locale() => $this->get_content(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transforms the WP_Post object to an ActivityPub Object
|
|
||||||
*
|
|
||||||
* @see \Activitypub\Activity\Base_Object
|
|
||||||
*
|
|
||||||
* @return \Activitypub\Activity\Base_Object The ActivityPub Object
|
|
||||||
*/
|
|
||||||
public function to_object() {
|
|
||||||
$wp_post = $this->wp_post;
|
|
||||||
$object = new Base_Object();
|
|
||||||
|
|
||||||
$object->set_id( $this->get_id() );
|
|
||||||
$object->set_url( $this->get_url() );
|
|
||||||
$object->set_type( $this->get_object_type() );
|
|
||||||
|
|
||||||
$published = \strtotime( $wp_post->post_date_gmt );
|
|
||||||
|
|
||||||
$object->set_published( \gmdate( 'Y-m-d\TH:i:s\Z', $published ) );
|
|
||||||
|
|
||||||
$updated = \strtotime( $wp_post->post_modified_gmt );
|
|
||||||
|
|
||||||
if ( $updated > $published ) {
|
|
||||||
$object->set_updated( \gmdate( 'Y-m-d\TH:i:s\Z', $updated ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
$object->set_attributed_to( $this->get_attributed_to() );
|
|
||||||
$object->set_content( $this->get_content() );
|
|
||||||
$object->set_content_map( $this->get_content_map );
|
|
||||||
$path = sprintf( 'users/%d/followers', intval( $wp_post->post_author ) );
|
|
||||||
|
|
||||||
$object->set_to(
|
|
||||||
array(
|
|
||||||
'https://www.w3.org/ns/activitystreams#Public',
|
|
||||||
get_rest_url_by_path( $path ),
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$object->set_cc( $this->get_cc() );
|
|
||||||
$object->set_attachment( $this->get_attachments() );
|
|
||||||
$object->set_tag( $this->get_tags() );
|
|
||||||
|
|
||||||
return $object;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,39 +5,278 @@ use WP_Post;
|
||||||
use Activitypub\Collection\Users;
|
use Activitypub\Collection\Users;
|
||||||
use Activitypub\Model\Blog_User;
|
use Activitypub\Model\Blog_User;
|
||||||
use Activitypub\Activity\Base_Object;
|
use Activitypub\Activity\Base_Object;
|
||||||
use Activitypub\Shortcodes;
|
|
||||||
use Activitypub\Transformer\Base;
|
|
||||||
|
|
||||||
use function Activitypub\esc_hashtag;
|
|
||||||
use function Activitypub\is_single_user;
|
use function Activitypub\is_single_user;
|
||||||
use function Activitypub\get_rest_url_by_path;
|
use function Activitypub\get_rest_url_by_path;
|
||||||
use function Activitypub\site_supports_blocks;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WordPress Post Transformer
|
* WordPress Post Transformer
|
||||||
|
*
|
||||||
* The Post Transformer is responsible for transforming a WP_Post object into different othe
|
* The Post Transformer is responsible for transforming a WP_Post object into different othe
|
||||||
* Object-Types.
|
* Object-Types.
|
||||||
*
|
*
|
||||||
* Currently supported are:
|
* Currently supported are:
|
||||||
|
*
|
||||||
* - Activitypub\Activity\Base_Object
|
* - Activitypub\Activity\Base_Object
|
||||||
*/
|
*/
|
||||||
class Post extends Base {
|
class Post {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter function for the name of the transformer.
|
* The WP_Post object.
|
||||||
*
|
*
|
||||||
* @return string name
|
* @var WP_Post
|
||||||
*/
|
*/
|
||||||
public function get_name() {
|
protected $wp_post;
|
||||||
return 'activitypub/default';
|
|
||||||
|
/**
|
||||||
|
* The Allowed Tags, used in the content.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $allowed_tags = array(
|
||||||
|
'a' => array(
|
||||||
|
'href' => array(),
|
||||||
|
'title' => array(),
|
||||||
|
'class' => array(),
|
||||||
|
'rel' => array(),
|
||||||
|
),
|
||||||
|
'br' => array(),
|
||||||
|
'p' => array(
|
||||||
|
'class' => array(),
|
||||||
|
),
|
||||||
|
'span' => array(
|
||||||
|
'class' => array(),
|
||||||
|
),
|
||||||
|
'div' => array(
|
||||||
|
'class' => array(),
|
||||||
|
),
|
||||||
|
'ul' => array(),
|
||||||
|
'ol' => array(
|
||||||
|
'reversed' => array(),
|
||||||
|
'start' => array(),
|
||||||
|
),
|
||||||
|
'li' => array(
|
||||||
|
'value' => array(),
|
||||||
|
),
|
||||||
|
'strong' => array(
|
||||||
|
'class' => array(),
|
||||||
|
),
|
||||||
|
'b' => array(
|
||||||
|
'class' => array(),
|
||||||
|
),
|
||||||
|
'i' => array(
|
||||||
|
'class' => array(),
|
||||||
|
),
|
||||||
|
'em' => array(
|
||||||
|
'class' => array(),
|
||||||
|
),
|
||||||
|
'blockquote' => array(),
|
||||||
|
'cite' => array(),
|
||||||
|
'code' => array(
|
||||||
|
'class' => array(),
|
||||||
|
),
|
||||||
|
'pre' => array(
|
||||||
|
'class' => array(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static function to Transform a WP_Post Object.
|
||||||
|
*
|
||||||
|
* This helps to chain the output of the Transformer.
|
||||||
|
*
|
||||||
|
* @param WP_Post $wp_post The WP_Post object
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function transform( WP_Post $wp_post ) {
|
||||||
|
return new static( $wp_post );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter function for the display name (label/title) of the transformer.
|
|
||||||
*
|
*
|
||||||
* @return string name
|
*
|
||||||
|
* @param WP_Post $wp_post
|
||||||
*/
|
*/
|
||||||
public function get_label() {
|
public function __construct( WP_Post $wp_post ) {
|
||||||
return 'Built-In';
|
$this->wp_post = $wp_post;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms the WP_Post object to an ActivityPub Object
|
||||||
|
*
|
||||||
|
* @see \Activitypub\Activity\Base_Object
|
||||||
|
*
|
||||||
|
* @return \Activitypub\Activity\Base_Object The ActivityPub Object
|
||||||
|
*/
|
||||||
|
public function to_object() {
|
||||||
|
$wp_post = $this->wp_post;
|
||||||
|
$object = new Base_Object();
|
||||||
|
|
||||||
|
$object->set_id( \esc_url( \get_permalink( $wp_post->ID ) ) );
|
||||||
|
$object->set_url( \esc_url( \get_permalink( $wp_post->ID ) ) );
|
||||||
|
$object->set_type( $this->get_object_type() );
|
||||||
|
|
||||||
|
$published = \strtotime( $wp_post->post_date_gmt );
|
||||||
|
|
||||||
|
$object->set_published( \gmdate( 'Y-m-d\TH:i:s\Z', $published ) );
|
||||||
|
|
||||||
|
$updated = \strtotime( $wp_post->post_modified_gmt );
|
||||||
|
|
||||||
|
if ( $updated > $published ) {
|
||||||
|
$object->set_updated( \gmdate( 'Y-m-d\TH:i:s\Z', $updated ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
$object->set_attributed_to( $this->get_attributed_to() );
|
||||||
|
$object->set_content( $this->get_content() );
|
||||||
|
$object->set_content_map(
|
||||||
|
array(
|
||||||
|
\strstr( \get_locale(), '_', true ) => $this->get_content(),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$path = sprintf( 'users/%d/followers', intval( $wp_post->post_author ) );
|
||||||
|
|
||||||
|
$object->set_to(
|
||||||
|
array(
|
||||||
|
'https://www.w3.org/ns/activitystreams#Public',
|
||||||
|
get_rest_url_by_path( $path ),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$object->set_cc( $this->get_cc() );
|
||||||
|
$object->set_attachment( $this->get_attachments() );
|
||||||
|
$object->set_tag( $this->get_tags() );
|
||||||
|
|
||||||
|
return $object;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the User-URL of the Author of the Post.
|
||||||
|
*
|
||||||
|
* If `single_user` mode is enabled, the URL of the Blog-User is returned.
|
||||||
|
*
|
||||||
|
* @return string The User-URL.
|
||||||
|
*/
|
||||||
|
protected function get_attributed_to() {
|
||||||
|
if ( is_single_user() ) {
|
||||||
|
$user = new Blog_User();
|
||||||
|
return $user->get_url();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Users::get_by_id( $this->wp_post->post_author )->get_url();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates all Image Attachments for a Post.
|
||||||
|
*
|
||||||
|
* @return array The Image Attachments.
|
||||||
|
*/
|
||||||
|
protected function get_attachments() {
|
||||||
|
$max_images = intval( \apply_filters( 'activitypub_max_image_attachments', \get_option( 'activitypub_max_image_attachments', ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS ) ) );
|
||||||
|
|
||||||
|
$images = array();
|
||||||
|
|
||||||
|
// max images can't be negative or zero
|
||||||
|
if ( $max_images <= 0 ) {
|
||||||
|
return $images;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = $this->wp_post->ID;
|
||||||
|
|
||||||
|
$image_ids = array();
|
||||||
|
|
||||||
|
// list post thumbnail first if this post has one
|
||||||
|
if ( \function_exists( 'has_post_thumbnail' ) && \has_post_thumbnail( $id ) ) {
|
||||||
|
$image_ids[] = \get_post_thumbnail_id( $id );
|
||||||
|
--$max_images;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $max_images > 0 ) {
|
||||||
|
// then list any image attachments
|
||||||
|
$query = new \WP_Query(
|
||||||
|
array(
|
||||||
|
'post_parent' => $id,
|
||||||
|
'post_status' => 'inherit',
|
||||||
|
'post_type' => 'attachment',
|
||||||
|
'post_mime_type' => 'image',
|
||||||
|
'order' => 'ASC',
|
||||||
|
'orderby' => 'menu_order ID',
|
||||||
|
'posts_per_page' => $max_images,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
foreach ( $query->get_posts() as $attachment ) {
|
||||||
|
if ( ! \in_array( $attachment->ID, $image_ids, true ) ) {
|
||||||
|
$image_ids[] = $attachment->ID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$image_ids = \array_unique( $image_ids );
|
||||||
|
|
||||||
|
// get URLs for each image
|
||||||
|
foreach ( $image_ids as $id ) {
|
||||||
|
$image_size = 'full';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter the image URL returned for each post.
|
||||||
|
*
|
||||||
|
* @param array|false $thumbnail The image URL, or false if no image is available.
|
||||||
|
* @param int $id The attachment ID.
|
||||||
|
* @param string $image_size The image size to retrieve. Set to 'full' by default.
|
||||||
|
*/
|
||||||
|
$thumbnail = apply_filters(
|
||||||
|
'activitypub_get_image',
|
||||||
|
$this->get_image( $id, $image_size ),
|
||||||
|
$id,
|
||||||
|
$image_size
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( $thumbnail ) {
|
||||||
|
$mimetype = \get_post_mime_type( $id );
|
||||||
|
$alt = \get_post_meta( $id, '_wp_attachment_image_alt', true );
|
||||||
|
$image = array(
|
||||||
|
'type' => 'Image',
|
||||||
|
'url' => $thumbnail[0],
|
||||||
|
'mediaType' => $mimetype,
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( $alt ) {
|
||||||
|
$image['name'] = $alt;
|
||||||
|
}
|
||||||
|
$images[] = $image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $images;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return details about an image attachment.
|
||||||
|
*
|
||||||
|
* @param int $id The attachment ID.
|
||||||
|
* @param string $image_size The image size to retrieve. Set to 'full' by default.
|
||||||
|
*
|
||||||
|
* @return array|false Array of image data, or boolean false if no image is available.
|
||||||
|
*/
|
||||||
|
protected function get_image( $id, $image_size = 'full' ) {
|
||||||
|
/**
|
||||||
|
* Hook into the image retrieval process. Before image retrieval.
|
||||||
|
*
|
||||||
|
* @param int $id The attachment ID.
|
||||||
|
* @param string $image_size The image size to retrieve. Set to 'full' by default.
|
||||||
|
*/
|
||||||
|
do_action( 'activitypub_get_image_pre', $id, $image_size );
|
||||||
|
|
||||||
|
$thumbnail = \wp_get_attachment_image_src( $id, $image_size );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook into the image retrieval process. After image retrieval.
|
||||||
|
*
|
||||||
|
* @param int $id The attachment ID.
|
||||||
|
* @param string $image_size The image size to retrieve. Set to 'full' by default.
|
||||||
|
*/
|
||||||
|
do_action( 'activitypub_get_image_pre', $id, $image_size );
|
||||||
|
|
||||||
|
return $thumbnail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,8 +292,6 @@ class Post extends Base {
|
||||||
return \ucfirst( \get_option( 'activitypub_object_type', 'note' ) );
|
return \ucfirst( \get_option( 'activitypub_object_type', 'note' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default to Article.
|
|
||||||
$object_type = 'Article';
|
|
||||||
$post_type = \get_post_type( $this->wp_post );
|
$post_type = \get_post_type( $this->wp_post );
|
||||||
switch ( $post_type ) {
|
switch ( $post_type ) {
|
||||||
case 'post':
|
case 'post':
|
||||||
|
@ -106,4 +343,121 @@ class Post extends Base {
|
||||||
|
|
||||||
return $object_type;
|
return $object_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of Mentions, used in the Post.
|
||||||
|
*
|
||||||
|
* @see https://docs.joinmastodon.org/spec/activitypub/#Mention
|
||||||
|
*
|
||||||
|
* @return array The list of Mentions.
|
||||||
|
*/
|
||||||
|
protected function get_cc() {
|
||||||
|
$cc = array();
|
||||||
|
|
||||||
|
$mentions = $this->get_mentions();
|
||||||
|
if ( $mentions ) {
|
||||||
|
foreach ( $mentions as $mention => $url ) {
|
||||||
|
$cc[] = $url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $cc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of Tags, used in the Post.
|
||||||
|
*
|
||||||
|
* This includes Hash-Tags and Mentions.
|
||||||
|
*
|
||||||
|
* @return array The list of Tags.
|
||||||
|
*/
|
||||||
|
protected function get_tags() {
|
||||||
|
$tags = array();
|
||||||
|
|
||||||
|
$post_tags = \get_the_tags( $this->wp_post->ID );
|
||||||
|
if ( $post_tags ) {
|
||||||
|
foreach ( $post_tags as $post_tag ) {
|
||||||
|
$tag = array(
|
||||||
|
'type' => 'Hashtag',
|
||||||
|
'href' => esc_url( \get_tag_link( $post_tag->term_id ) ),
|
||||||
|
'name' => '#' . \esc_attr( $post_tag->slug ),
|
||||||
|
);
|
||||||
|
$tags[] = $tag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$mentions = $this->get_mentions();
|
||||||
|
if ( $mentions ) {
|
||||||
|
foreach ( $mentions as $mention => $url ) {
|
||||||
|
$tag = array(
|
||||||
|
'type' => 'Mention',
|
||||||
|
'href' => \esc_url( $url ),
|
||||||
|
'name' => \esc_html( $mention ),
|
||||||
|
);
|
||||||
|
$tags[] = $tag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the content for the ActivityPub Item.
|
||||||
|
*
|
||||||
|
* The content will be generated based on the user settings.
|
||||||
|
*
|
||||||
|
* @return string The content.
|
||||||
|
*/
|
||||||
|
protected function get_content() {
|
||||||
|
global $post;
|
||||||
|
|
||||||
|
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
||||||
|
$post = $this->wp_post;
|
||||||
|
$content = $this->get_post_content_template();
|
||||||
|
|
||||||
|
// Fill in the shortcodes.
|
||||||
|
setup_postdata( $post );
|
||||||
|
$content = do_shortcode( $content );
|
||||||
|
wp_reset_postdata();
|
||||||
|
|
||||||
|
$content = \wp_kses( $content, $this->allowed_tags );
|
||||||
|
$content = \wpautop( $content );
|
||||||
|
$content = \preg_replace( '/[\n\r\t]/', '', $content );
|
||||||
|
$content = \trim( $content );
|
||||||
|
|
||||||
|
$content = \apply_filters( 'activitypub_the_content', $content, $post );
|
||||||
|
$content = \html_entity_decode( $content, \ENT_QUOTES, 'UTF-8' );
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the template to use to generate the content of the activitypub item.
|
||||||
|
*
|
||||||
|
* @return string The Template.
|
||||||
|
*/
|
||||||
|
protected function get_post_content_template() {
|
||||||
|
if ( 'excerpt' === \get_option( 'activitypub_post_content_type', 'content' ) ) {
|
||||||
|
return "[ap_excerpt]\n\n[ap_permalink type=\"html\"]";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( 'title' === \get_option( 'activitypub_post_content_type', 'content' ) ) {
|
||||||
|
return "[ap_title]\n\n[ap_permalink type=\"html\"]";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( 'content' === \get_option( 'activitypub_post_content_type', 'content' ) ) {
|
||||||
|
return "[ap_content]\n\n[ap_hashtags]\n\n[ap_permalink type=\"html\"]";
|
||||||
|
}
|
||||||
|
|
||||||
|
return \get_option( 'activitypub_custom_post_content', ACTIVITYPUB_CUSTOM_POST_CONTENT );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to get the @-Mentions from the post content.
|
||||||
|
*
|
||||||
|
* @return array The list of @-Mentions.
|
||||||
|
*/
|
||||||
|
protected function get_mentions() {
|
||||||
|
return apply_filters( 'activitypub_extract_mentions', array(), $this->wp_post->post_content, $this->wp_post );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,292 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Inspired by the way elementor handles addons.
|
|
||||||
*
|
|
||||||
* @link https://github.com/elementor/elementor/
|
|
||||||
* @package Activitypub
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Activitypub\Transformer;
|
|
||||||
|
|
||||||
use WP_Post;
|
|
||||||
use WP_Comment;
|
|
||||||
|
|
||||||
use function Activitypub\camel_to_snake_case;
|
|
||||||
use function Activitypub\snake_to_camel_case;
|
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
|
||||||
exit; // Exit if accessed directly.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ActivityPub transformers manager.
|
|
||||||
*
|
|
||||||
* ActivityPub transformers manager handler class is responsible for registering and
|
|
||||||
* initializing all the supported WP-Pobject to ActivityPub transformers.
|
|
||||||
*
|
|
||||||
* @since version_number_transformer_management_placeholder
|
|
||||||
*/
|
|
||||||
class Transformers_Manager {
|
|
||||||
const DEFAULT_TRANSFORMER_MAPPING = array(
|
|
||||||
'post' => ACTIVITYPUB_DEFAULT_TRANSFORMER,
|
|
||||||
'page' => ACTIVITYPUB_DEFAULT_TRANSFORMER,
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transformers.
|
|
||||||
*
|
|
||||||
* Holds the list of all the ActivityPub transformers. Default is `null`.
|
|
||||||
*
|
|
||||||
* @since version_number_transformer_management_placeholder
|
|
||||||
* @access private
|
|
||||||
*
|
|
||||||
* @var \ActivityPub\Transformer\Base[]
|
|
||||||
*/
|
|
||||||
private $transformers = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transformer_Manager instance.
|
|
||||||
*
|
|
||||||
* Holds the transformer instance.
|
|
||||||
*
|
|
||||||
* @since version_number_transformer_management_placeholder
|
|
||||||
* @access protected
|
|
||||||
*
|
|
||||||
* @var Transformer_Manager
|
|
||||||
*/
|
|
||||||
protected static $_instances = [];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instance.
|
|
||||||
*
|
|
||||||
* Ensures only one instance of the transformer manager class is loaded or can be loaded.
|
|
||||||
*
|
|
||||||
* @since version_number_transformer_management_placeholder
|
|
||||||
* @access public
|
|
||||||
* @static
|
|
||||||
*
|
|
||||||
* @return Transformer_Manager An instance of the class.
|
|
||||||
*/
|
|
||||||
public static function instance() {
|
|
||||||
$class_name = static::class_name();
|
|
||||||
|
|
||||||
if ( empty( static::$_instances[ $class_name ] ) ) {
|
|
||||||
static::$_instances[ $class_name ] = new static();
|
|
||||||
}
|
|
||||||
|
|
||||||
return static::$_instances[ $class_name ];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class name.
|
|
||||||
*
|
|
||||||
* Retrieve the name of the class.
|
|
||||||
*
|
|
||||||
* @since version_number_transformer_management_placeholder
|
|
||||||
* @access public
|
|
||||||
* @static
|
|
||||||
*/
|
|
||||||
public static function class_name() {
|
|
||||||
return get_called_class();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transformers manager constructor.
|
|
||||||
*
|
|
||||||
* Initializing ActivityPub transformers manager.
|
|
||||||
*
|
|
||||||
* @since version_number_transformer_management_placeholder
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
public function __construct() {
|
|
||||||
$this->require_files();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Require files.
|
|
||||||
*
|
|
||||||
* Require ActivityPub transformer base class.
|
|
||||||
*
|
|
||||||
* @since version_number_transformer_management_placeholder
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
private function require_files() {
|
|
||||||
require ACTIVITYPUB_PLUGIN_DIR . 'includes/transformer/class-base.php';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if a transformer is registered.
|
|
||||||
*
|
|
||||||
* @since version_number_transformer_management_placeholder
|
|
||||||
*
|
|
||||||
* @param string $name Transformer name including namespace.
|
|
||||||
* @return bool True if the block type is registered, false otherwise.
|
|
||||||
*/
|
|
||||||
public function is_registered( $name ) {
|
|
||||||
return isset( $this->transformers[ $name ] );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a transformer.
|
|
||||||
*
|
|
||||||
* @since version_number_transformer_management_placeholder
|
|
||||||
* @access public
|
|
||||||
*
|
|
||||||
* @param \ActivityPub\Transformer\Base $transformer_instance ActivityPub Transformer.
|
|
||||||
*
|
|
||||||
* @return bool True if the ActivityPub transformer was registered.
|
|
||||||
*/
|
|
||||||
public function register( \ActivityPub\Transformer\Base $transformer_instance ) {
|
|
||||||
|
|
||||||
if ( ! $transformer_instance instanceof \ActivityPub\Transformer\Base ) {
|
|
||||||
_doing_it_wrong(
|
|
||||||
__METHOD__,
|
|
||||||
\esc_html__( 'ActivityPub transformer instance must be a of \ActivityPub\Transformer_Base class.' ),
|
|
||||||
'version_number_transformer_management_placeholder'
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$transformer_name = $transformer_instance->get_name();
|
|
||||||
if ( preg_match( '/[A-Z]+/', $transformer_name ) ) {
|
|
||||||
_doing_it_wrong(
|
|
||||||
__METHOD__,
|
|
||||||
\esc_html__( 'ActivityPub transformer names must not contain uppercase characters.' ),
|
|
||||||
'version_number_transformer_management_placeholder'
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$name_matcher = '/^[a-z0-9-]+\/[a-z0-9-]+$/';
|
|
||||||
if ( ! preg_match( $name_matcher, $transformer_name ) ) {
|
|
||||||
_doing_it_wrong(
|
|
||||||
__METHOD__,
|
|
||||||
\esc_html__( 'ActivityPub transformer names must contain a namespace prefix. Example: my-plugin/my-custom-transformer' ),
|
|
||||||
'version_number_transformer_management_placeholder'
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $this->is_registered( $transformer_name ) ) {
|
|
||||||
_doing_it_wrong(
|
|
||||||
__METHOD__,
|
|
||||||
/* translators: %s: Block name. */
|
|
||||||
sprintf( 'ActivityPub transformer with name "%s" is already registered.', esc_html( $transformer_name ) ),
|
|
||||||
'version_number_transformer_management_placeholder'
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should the ActivityPub transformer be registered.
|
|
||||||
*
|
|
||||||
* @since version_number_transformer_management_placeholder
|
|
||||||
*
|
|
||||||
* @param bool $should_register Should the ActivityPub transformer be registered. Default is `true`.
|
|
||||||
* @param \ActivityPub\Transformer\Base $transformer_instance Widget instance.
|
|
||||||
*/
|
|
||||||
// TODO: does not implementing this slow down the website? -> compare with gutenberg block registration.
|
|
||||||
// $should_register = apply_filters( 'activitypub/transformers/is_transformer_enabled', true, $transformer_instance );
|
|
||||||
|
|
||||||
// if ( ! $should_register ) {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
$this->transformers[ $transformer_name ] = $transformer_instance;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Init transformers.
|
|
||||||
*
|
|
||||||
* Initialize ActivityPub transformer manager.
|
|
||||||
* Include the builtin transformers by default and add third party ones.
|
|
||||||
*
|
|
||||||
* @since version_number_transformer_management_placeholder
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
private function init_transformers() {
|
|
||||||
$builtin_transformers = [
|
|
||||||
'post',
|
|
||||||
];
|
|
||||||
|
|
||||||
$this->transformers = [];
|
|
||||||
|
|
||||||
foreach ( $builtin_transformers as $transformer_name ) {
|
|
||||||
include ACTIVITYPUB_PLUGIN_DIR . 'includes/transformer/class-' . $transformer_name . '.php';
|
|
||||||
|
|
||||||
$class_name = ucfirst( $transformer_name );
|
|
||||||
|
|
||||||
$class_name = '\Activitypub\Transformer\\' . $class_name;
|
|
||||||
|
|
||||||
$this->register( new $class_name() );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Let other transformers register.
|
|
||||||
*
|
|
||||||
* Fires after the built-in Activitypub transformers are registered.
|
|
||||||
*
|
|
||||||
* @since version_number_transformer_management_placeholder
|
|
||||||
*
|
|
||||||
* @param Transformers_Manager $this The widgets manager.
|
|
||||||
*/
|
|
||||||
do_action( 'activitypub_transformers_register', $this );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get available ActivityPub transformers.
|
|
||||||
*
|
|
||||||
* Retrieve the registered transformers list. If given a transformer name
|
|
||||||
* it returns the given transformer if it is registered.
|
|
||||||
*
|
|
||||||
* @since version_number_transformer_management_placeholder
|
|
||||||
* @access public
|
|
||||||
*
|
|
||||||
* @param string $transformer_name Optional. Transformer name. Default is null.
|
|
||||||
*
|
|
||||||
* @return Base|Base[]|null Registered transformers.
|
|
||||||
*/
|
|
||||||
public function get_transformers( $transformer_name = null ) {
|
|
||||||
if ( is_null( $this->transformers ) ) {
|
|
||||||
$this->init_transformers();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( null !== $transformer_name ) {
|
|
||||||
return isset( $this->transformers[ $transformer_name ] ) ? $this->transformers[ $transformer_name ] : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->transformers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the mapped ActivityPub transformer.
|
|
||||||
*
|
|
||||||
* Returns a new instance of the needed WordPress to ActivityPub transformer.
|
|
||||||
*
|
|
||||||
* @since version_number_transformer_management_placeholder
|
|
||||||
* @access public
|
|
||||||
*
|
|
||||||
* @param WP_Post|WP_Comment $object The WordPress Post/Comment.
|
|
||||||
*
|
|
||||||
* @return \ActivityPub\Transformer\Base|null Registered transformers.
|
|
||||||
*/
|
|
||||||
public function get_transformer( $object ) {
|
|
||||||
switch ( get_class( $object ) ) {
|
|
||||||
case 'WP_Post':
|
|
||||||
$post_type = get_post_type( $object );
|
|
||||||
$transformer_mapping = \get_option( 'activitypub_transformer_mapping', self::DEFAULT_TRANSFORMER_MAPPING );
|
|
||||||
$transformer_name = $transformer_mapping[ $post_type ];
|
|
||||||
$transformer_class = $this->get_transformers( $transformer_name );
|
|
||||||
$transformer_instance = new $transformer_class();
|
|
||||||
$transformer_instance->set_wp_post( $object );
|
|
||||||
return $transformer_instance;
|
|
||||||
case 'WP_Comment':
|
|
||||||
return new Comment( $object );
|
|
||||||
default:
|
|
||||||
return apply_filters( 'activitypub_transformer', null, $object, get_class( $object ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
38
includes/validator/class-query.php
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Activitypub\Validator;
|
||||||
|
|
||||||
|
class Query {
|
||||||
|
/**
|
||||||
|
* Validate the query parameters.
|
||||||
|
*
|
||||||
|
* @return array A list of arguments and how to validate them.
|
||||||
|
*/
|
||||||
|
public static function get_default_args() {
|
||||||
|
$args = array();
|
||||||
|
|
||||||
|
$args['page'] = array(
|
||||||
|
'type' => 'integer',
|
||||||
|
'default' => 1,
|
||||||
|
);
|
||||||
|
|
||||||
|
$args['per_page'] = array(
|
||||||
|
'type' => 'integer',
|
||||||
|
'default' => 20,
|
||||||
|
);
|
||||||
|
|
||||||
|
$args['order'] = array(
|
||||||
|
'type' => 'string',
|
||||||
|
'default' => 'desc',
|
||||||
|
'enum' => array( 'asc', 'desc' ),
|
||||||
|
);
|
||||||
|
|
||||||
|
$args['context'] = array(
|
||||||
|
'type' => 'string',
|
||||||
|
'default' => 'simple',
|
||||||
|
'enum' => array( 'simple', 'full' ),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $args;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,15 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Activitypub\Integration;
|
namespace Activitypub\Integration;
|
||||||
|
|
||||||
/**
|
|
||||||
* Compatibility with the BuddyPress plugin
|
|
||||||
*
|
|
||||||
* @see https://buddypress.org/
|
|
||||||
*/
|
|
||||||
class Buddypress {
|
class Buddypress {
|
||||||
/**
|
|
||||||
* Initialize the class, registering WordPress hooks
|
|
||||||
*/
|
|
||||||
public static function init() {
|
public static function init() {
|
||||||
\add_filter( 'activitypub_json_author_array', array( self::class, 'add_user_metadata' ), 11, 2 );
|
\add_filter( 'activitypub_json_author_array', array( self::class, 'add_user_metadata' ), 11, 2 );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,64 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Activitypub\Integration;
|
|
||||||
|
|
||||||
use function Activitypub\get_total_users;
|
|
||||||
use function Activitypub\get_active_users;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compatibility with the NodeInfo plugin
|
|
||||||
*
|
|
||||||
* @see https://wordpress.org/plugins/nodeinfo/
|
|
||||||
*/
|
|
||||||
class Nodeinfo {
|
|
||||||
/**
|
|
||||||
* Initialize the class, registering WordPress hooks
|
|
||||||
*/
|
|
||||||
public static function init() {
|
|
||||||
\add_filter( 'nodeinfo_data', array( self::class, 'add_nodeinfo_discovery' ), 10, 2 );
|
|
||||||
\add_filter( 'nodeinfo2_data', array( self::class, 'add_nodeinfo2_discovery' ), 10 );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extend NodeInfo data
|
|
||||||
*
|
|
||||||
* @param array $nodeinfo NodeInfo data
|
|
||||||
* @param string The NodeInfo Version
|
|
||||||
*
|
|
||||||
* @return array The extended array
|
|
||||||
*/
|
|
||||||
public static function add_nodeinfo_discovery( $nodeinfo, $version ) {
|
|
||||||
if ( $version >= '2.0' ) {
|
|
||||||
$nodeinfo['protocols'][] = 'activitypub';
|
|
||||||
} else {
|
|
||||||
$nodeinfo['protocols']['inbound'][] = 'activitypub';
|
|
||||||
$nodeinfo['protocols']['outbound'][] = 'activitypub';
|
|
||||||
}
|
|
||||||
|
|
||||||
$nodeinfo['usage']['users'] = array(
|
|
||||||
'total' => get_total_users(),
|
|
||||||
'activeMonth' => get_active_users( '1 month ago' ),
|
|
||||||
'activeHalfyear' => get_active_users( '6 month ago' ),
|
|
||||||
);
|
|
||||||
|
|
||||||
return $nodeinfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extend NodeInfo2 data
|
|
||||||
*
|
|
||||||
* @param array $nodeinfo NodeInfo2 data
|
|
||||||
*
|
|
||||||
* @return array The extended array
|
|
||||||
*/
|
|
||||||
public static function add_nodeinfo2_discovery( $nodeinfo ) {
|
|
||||||
$nodeinfo['protocols'][] = 'activitypub';
|
|
||||||
|
|
||||||
$nodeinfo['usage']['users'] = array(
|
|
||||||
'total' => get_total_users(),
|
|
||||||
'activeMonth' => get_active_users( '1 month ago' ),
|
|
||||||
'activeHalfyear' => get_active_users( '6 month ago' ),
|
|
||||||
);
|
|
||||||
|
|
||||||
return $nodeinfo;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,62 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Activitypub\Integration;
|
|
||||||
|
|
||||||
use Activitypub\Rest\Webfinger as Webfinger_Rest;
|
|
||||||
use Activitypub\Collection\Users as User_Collection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compatibility with the WebFinger plugin
|
|
||||||
*
|
|
||||||
* @see https://wordpress.org/plugins/webfinger/
|
|
||||||
*/
|
|
||||||
class Webfinger {
|
|
||||||
/**
|
|
||||||
* Initialize the class, registering WordPress hooks
|
|
||||||
*/
|
|
||||||
public static function init() {
|
|
||||||
\add_filter( 'webfinger_user_data', array( self::class, 'add_user_discovery' ), 10, 3 );
|
|
||||||
\add_filter( 'webfinger_data', array( self::class, 'add_pseudo_user_discovery' ), 99, 2 );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add WebFinger discovery links
|
|
||||||
*
|
|
||||||
* @param array $array the jrd array
|
|
||||||
* @param string $resource the WebFinger resource
|
|
||||||
* @param WP_User $user the WordPress user
|
|
||||||
*
|
|
||||||
* @return array the jrd array
|
|
||||||
*/
|
|
||||||
public static function add_user_discovery( $array, $resource, $user ) {
|
|
||||||
$user = User_Collection::get_by_id( $user->ID );
|
|
||||||
|
|
||||||
if ( ! $user || is_wp_error( $user ) ) {
|
|
||||||
return $array;
|
|
||||||
}
|
|
||||||
|
|
||||||
$array['links'][] = array(
|
|
||||||
'rel' => 'self',
|
|
||||||
'type' => 'application/activity+json',
|
|
||||||
'href' => $user->get_url(),
|
|
||||||
);
|
|
||||||
|
|
||||||
return $array;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add WebFinger discovery links
|
|
||||||
*
|
|
||||||
* @param array $array the jrd array
|
|
||||||
* @param string $resource the WebFinger resource
|
|
||||||
* @param WP_User $user the WordPress user
|
|
||||||
*
|
|
||||||
* @return array the jrd array
|
|
||||||
*/
|
|
||||||
public static function add_pseudo_user_discovery( $array, $resource ) {
|
|
||||||
if ( $array ) {
|
|
||||||
return $array;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Webfinger_Rest::get_profile( $resource );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -11,8 +11,7 @@
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "wp-scripts start",
|
"dev": "wp-scripts start",
|
||||||
"build": "wp-scripts build",
|
"build": "wp-scripts build"
|
||||||
"readme": "grunt wp_readme_to_markdown"
|
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
<rule ref="WordPress-Core">
|
<rule ref="WordPress-Core">
|
||||||
<exclude name="Generic.Formatting.MultipleStatementAlignment.NotSameWarning" />
|
<exclude name="Generic.Formatting.MultipleStatementAlignment.NotSameWarning" />
|
||||||
<exclude name="WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned" />
|
<exclude name="WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned" />
|
||||||
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.SpaceAfterFunction" />
|
|
||||||
</rule>
|
</rule>
|
||||||
<rule ref="WordPress.Files.FileName">
|
<rule ref="WordPress.Files.FileName">
|
||||||
<properties>
|
<properties>
|
||||||
|
|
171
readme.txt
|
@ -1,9 +1,9 @@
|
||||||
=== ActivityPub ===
|
=== ActivityPub ===
|
||||||
Contributors: automattic, pfefferle, mediaformat, mattwiebe, akirk, jeherve, nuriapena, cavalierlife
|
Contributors: automattic, pfefferle, mediaformat, mattwiebe, akirk, jeherve, nuriapena
|
||||||
Tags: OStatus, fediverse, activitypub, activitystream
|
Tags: OStatus, fediverse, activitypub, activitystream
|
||||||
Requires at least: 4.7
|
Requires at least: 4.7
|
||||||
Tested up to: 6.4
|
Tested up to: 6.3
|
||||||
Stable tag: 1.2.0
|
Stable tag: 1.0.0
|
||||||
Requires PHP: 5.6
|
Requires PHP: 5.6
|
||||||
License: MIT
|
License: MIT
|
||||||
License URI: http://opensource.org/licenses/MIT
|
License URI: http://opensource.org/licenses/MIT
|
||||||
|
@ -12,39 +12,39 @@ The ActivityPub protocol is a decentralized social networking protocol based upo
|
||||||
|
|
||||||
== Description ==
|
== Description ==
|
||||||
|
|
||||||
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.
|
This is BETA software, see the FAQ to see the current feature set or rather what is still planned.
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
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:
|
The plugin works with the following tested federated platforms, but there may be more that it works with as well:
|
||||||
|
|
||||||
* [Mastodon](https://joinmastodon.org/)
|
* [Mastodon](https://joinmastodon.org/)
|
||||||
* [Pleroma](https://pleroma.social/)/[Akkoma](https://akkoma.social/)
|
* [Pleroma](https://pleroma.social/)
|
||||||
* [friendica](https://friendi.ca/)
|
* [friendica](https://friendi.ca/)
|
||||||
* [Hubzilla](https://hubzilla.org/)
|
* [Hubzilla](https://hubzilla.org/)
|
||||||
* [Pixelfed](https://pixelfed.org/)
|
* [Pixelfed](https://pixelfed.org/)
|
||||||
* [Socialhome](https://socialhome.network/)
|
* [Socialhome](https://socialhome.network/)
|
||||||
* [Misskey](https://join.misskey.page/)
|
* [Misskey](https://join.misskey.page/)
|
||||||
* [Firefish](https://joinfirefish.org/) (rebrand of Calckey)
|
* [Calckey](https://calckey.org/)
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
Some things to note:
|
Some things to note:
|
||||||
|
|
||||||
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 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. 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 still resolve 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.
|
||||||
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?
|
So what’s the process?
|
||||||
|
|
||||||
1. Install the ActivityPub plugin.
|
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. 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 if you are using author profiles.
|
1. Make sure your blog’s author profile page is active.
|
||||||
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. 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. On your blog, publish a new post.
|
1. On your blog, publish a new post.
|
||||||
1. From Mastodon, check to see if the new post appears in your Home feed.
|
1. From Mastodon, check to see if the new post appears in your Home feed.
|
||||||
|
|
||||||
|
@ -54,25 +54,34 @@ Please note that it may take up to 15 minutes or so for the new post to show up
|
||||||
|
|
||||||
= tl;dr =
|
= 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.
|
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.
|
||||||
|
|
||||||
= What is the status of this plugin? =
|
= What is the status of this plugin? =
|
||||||
|
|
||||||
Implemented:
|
Implemented:
|
||||||
|
|
||||||
* blog profile pages (JSON representation)
|
* profile pages (JSON representation)
|
||||||
* author profile pages (JSON representation)
|
|
||||||
* custom links
|
* custom links
|
||||||
* functional inbox/outbox
|
* functional inbox/outbox
|
||||||
* follow (accept follows)
|
* follow (accept follows)
|
||||||
* share posts
|
* share posts
|
||||||
* receive comments/reactions
|
* receive comments/reactions
|
||||||
* signature verification
|
|
||||||
|
|
||||||
To implement:
|
To implement:
|
||||||
|
|
||||||
|
* signature verification
|
||||||
|
* better WordPress integration
|
||||||
|
* better configuration possibilities
|
||||||
* threaded comments support
|
* threaded comments support
|
||||||
* replace shortcodes with blocks for layout
|
|
||||||
|
|
||||||
= What is "ActivityPub for WordPress" =
|
= What is "ActivityPub for WordPress" =
|
||||||
|
|
||||||
|
@ -86,7 +95,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:
|
Add the following to the .htaccess file in the root directory:
|
||||||
|
|
||||||
RedirectMatch "^\/\.well-known/(webfinger|nodeinfo|x-nodeinfo2)(.*)$" /blog/.well-known/$1$2
|
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.
|
Where 'blog' is the path to the subdirectory at which your blog resides.
|
||||||
|
|
||||||
|
@ -105,115 +114,19 @@ Where 'blog' is the path to the subdirectory at which your blog resides.
|
||||||
|
|
||||||
Project maintained on GitHub at [automattic/wordpress-activitypub](https://github.com/automattic/wordpress-activitypub).
|
Project maintained on GitHub at [automattic/wordpress-activitypub](https://github.com/automattic/wordpress-activitypub).
|
||||||
|
|
||||||
= 1.2.0 =
|
|
||||||
|
|
||||||
* Add: Search and order followerer lists
|
|
||||||
* Add: Have a filter to defer signature verification
|
|
||||||
* Improved: "Follow Me" styles for dark themes
|
|
||||||
* Improved: Allow `p` and `br` tags only for AP comments
|
|
||||||
* Fixed: Deduplicate attachments earlier to prevent incorrect max_media
|
|
||||||
|
|
||||||
|
|
||||||
= 1.1.0 =
|
|
||||||
|
|
||||||
* Improved: audio and video attachments are now supported!
|
|
||||||
* Improved: better error messages if remote profile is not accessible
|
|
||||||
* Improved: PHP 8.1 compatibility
|
|
||||||
* Fixed: don't try to parse mentions or hashtags for very large (>1MB) posts to prevent timeouts
|
|
||||||
* Fixed: better handling of ISO-639-1 locale codes
|
|
||||||
* Improved: more reliable [ap_author], props @uk3
|
|
||||||
* Improved: NodeInfo statistics
|
|
||||||
|
|
||||||
= 1.0.10 =
|
|
||||||
|
|
||||||
* Improved: better error messages if remote profile is not accessible
|
|
||||||
|
|
||||||
= 1.0.9 =
|
|
||||||
|
|
||||||
* Fixed: broken following endpoint
|
|
||||||
|
|
||||||
= 1.0.8 =
|
|
||||||
|
|
||||||
* Fixed: blocking of HEAD requests
|
|
||||||
* Fixed: PHP fatal error
|
|
||||||
* Fixed: several typos
|
|
||||||
* Fixed: error codes
|
|
||||||
* Improved: loading of shortcodes
|
|
||||||
* Updated: caching of followers
|
|
||||||
* Updated: Application-User is no longer "indexable"
|
|
||||||
* Updated: more consistent usage of the `application/activity+json` Content-Type
|
|
||||||
* Removed: featured tags endpoint
|
|
||||||
|
|
||||||
= 1.0.7 =
|
|
||||||
|
|
||||||
* Fixed: broken function call
|
|
||||||
* Add: filter to hook into "is blog public" check
|
|
||||||
|
|
||||||
= 1.0.6 =
|
|
||||||
|
|
||||||
* Fixed: more restrictive request verification
|
|
||||||
|
|
||||||
= 1.0.5 =
|
|
||||||
|
|
||||||
* Fixed: compatibility with WebFinger and NodeInfo plugin
|
|
||||||
|
|
||||||
= 1.0.4 =
|
|
||||||
|
|
||||||
* Fixed: Constants were not loaded early enough, resulting in a race condition
|
|
||||||
* Fixed: Featured image was ignored when using the block editor
|
|
||||||
|
|
||||||
= 1.0.3 =
|
|
||||||
|
|
||||||
* Fixed: compatibility with older WordPress/PHP versions
|
|
||||||
* Update: refactoring of the Plugin init process
|
|
||||||
* Update: better frontend UX and improved theme compat for blocks
|
|
||||||
* Compatibility: add a ACTIVITYPUB_DISABLE_REWRITES constant
|
|
||||||
* Compatibility: add pre-fetch hook to allow plugins to hang filters on
|
|
||||||
|
|
||||||
= 1.0.2 =
|
|
||||||
|
|
||||||
* Updated: improved hashtag visibility in default template
|
|
||||||
* Updated: reduced number of followers to be checked/updated via Cron, when System Cron is not set up
|
|
||||||
* Updated: check if username of Blog-User collides with an Authors name
|
|
||||||
* Compatibility: improved Group meta informations
|
|
||||||
* Fixed: detection of single user mode
|
|
||||||
* Fixed: remote delete
|
|
||||||
* Fixed: styles in Follow-Me block
|
|
||||||
* Fixed: various encoding and formatting issues
|
|
||||||
* Fixed: (health) check Author URLs only if Authors are enabled
|
|
||||||
|
|
||||||
= 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 =
|
= 1.0.0 =
|
||||||
|
|
||||||
* Add: blog-wide Account (catchall, like `example.com@example.com`)
|
* Add: blog-wide Account (catchall, like `mydomain.com@mydomain.com`)
|
||||||
* Add: a Follow Me block (help visitors to follow your Profile)
|
* Add: Signature Verification: https://docs.joinmastodon.org/spec/security/ .
|
||||||
* Add: Signature Verification: https://docs.joinmastodon.org/spec/security/
|
* Add: a Followers Block.
|
||||||
* Add: a Followers Block (show off your Followers)
|
|
||||||
* Add: Simple caching
|
* Add: Simple caching
|
||||||
* Add: Collection endpoints for Featured Tags and Featured Posts
|
* Update: Complete rewrite of the Follower-System based on Custom Post Types.
|
||||||
* Add: Better handling of Hashtags in mobile apps
|
|
||||||
* Update: Complete rewrite of the Follower-System based on Custom Post Types
|
|
||||||
* Update: Improved linter (PHPCS)
|
* Update: Improved linter (PHPCS)
|
||||||
* Compatibility: Add a new conditional, `\Activitypub\is_activitypub_request()`, to allow third-party plugins to detect ActivityPub requests
|
* 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: 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: 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
|
* 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: 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 =
|
= 0.17.0 =
|
||||||
|
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
{
|
|
||||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
|
||||||
"name": "activitypub/follow-me",
|
|
||||||
"apiVersion": 3,
|
|
||||||
"version": "1.0.0",
|
|
||||||
"title": "Follow me on the Fediverse",
|
|
||||||
"category": "widgets",
|
|
||||||
"description": "Display your Fediverse profile so that visitors can follow you.",
|
|
||||||
"textdomain": "activitypub",
|
|
||||||
"icon": "groups",
|
|
||||||
"supports": {
|
|
||||||
"html": false,
|
|
||||||
"color": {
|
|
||||||
"gradients": true,
|
|
||||||
"link": true,
|
|
||||||
"__experimentalDefaultControls": {
|
|
||||||
"background": true,
|
|
||||||
"text": true,
|
|
||||||
"link": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"__experimentalBorder": {
|
|
||||||
"radius": true,
|
|
||||||
"width": true,
|
|
||||||
"color": true,
|
|
||||||
"style": true
|
|
||||||
},
|
|
||||||
"typography": {
|
|
||||||
"fontSize": true,
|
|
||||||
"__experimentalDefaultControls": {
|
|
||||||
"fontSize": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"attributes": {
|
|
||||||
"selectedUser": {
|
|
||||||
"type": "string",
|
|
||||||
"default": "site"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"editorScript": "file:./index.js",
|
|
||||||
"viewScript": "file:./view.js",
|
|
||||||
"style": ["file:./style-index.css", "wp-components"]
|
|
||||||
}
|
|
|
@ -1,75 +0,0 @@
|
||||||
function presetVarColorCss( color ) {
|
|
||||||
return `var(--wp--preset--color--${ color })`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getBackgroundColor( color ) {
|
|
||||||
// if color is a string, it's a var like this.
|
|
||||||
if ( typeof color === 'string' ) {
|
|
||||||
return presetVarColorCss( color );
|
|
||||||
}
|
|
||||||
|
|
||||||
return color?.color?.background || null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getLinkColor( text ) {
|
|
||||||
if ( typeof text !== 'string' ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
// if it starts with a hash, leave it be
|
|
||||||
if ( text.match( /^#/ ) ) {
|
|
||||||
// we don't handle the alpha channel if present.
|
|
||||||
return text.substring( 0, 7 );
|
|
||||||
}
|
|
||||||
// var:preset|color|luminous-vivid-amber
|
|
||||||
// var(--wp--preset--color--luminous-vivid-amber)
|
|
||||||
// we will receive the top format, we need to output the bottom format
|
|
||||||
const [ , , color ] = text.split( '|' );
|
|
||||||
return presetVarColorCss( color );
|
|
||||||
}
|
|
||||||
|
|
||||||
function generateSelector( selector, prop, value = null, pseudo = '' ) {
|
|
||||||
if ( ! value ) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
return `${ selector }${ pseudo } { ${ prop }: ${ value }; }\n`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getStyles( selector, button, text, hover ) {
|
|
||||||
return generateSelector( selector, 'background-color', button )
|
|
||||||
+ generateSelector( selector, 'color', text )
|
|
||||||
+ generateSelector( selector, 'background-color', hover, ':hover' )
|
|
||||||
+ generateSelector( selector, 'background-color', hover, ':focus' );
|
|
||||||
}
|
|
||||||
|
|
||||||
function getBlockStyles( base, style, backgroundColor ) {
|
|
||||||
const selector = `${ base } .components-button`;
|
|
||||||
// we grab the background color if set as a good color for our button text
|
|
||||||
const buttonTextColor = getBackgroundColor( backgroundColor )
|
|
||||||
// bg might be in this form.
|
|
||||||
|| style?.color?.background;
|
|
||||||
// we misuse the link color for the button background
|
|
||||||
const buttonColor = getLinkColor( style?.elements?.link?.color?.text );
|
|
||||||
// hover!
|
|
||||||
const buttonHoverColor = getLinkColor( style?.elements?.link?.[':hover']?.color?.text );
|
|
||||||
|
|
||||||
return getStyles( selector, buttonColor, buttonTextColor, buttonHoverColor );
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getPopupStyles( style ) {
|
|
||||||
// we don't acept backgroundColor because the popup is always white (right?)
|
|
||||||
const buttonColor = getLinkColor( style?.elements?.link?.color?.text )
|
|
||||||
|| '#111';
|
|
||||||
const buttonTextColor = '#fff';
|
|
||||||
const buttonHoverColor = getLinkColor( style?.elements?.link?.[':hover']?.color?.text )
|
|
||||||
|| '#333';
|
|
||||||
const selector = '.apfmd__button-group .components-button';
|
|
||||||
|
|
||||||
return getStyles( selector, buttonColor, buttonTextColor, buttonHoverColor );
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ButtonStyle( { selector, style, backgroundColor } ) {
|
|
||||||
const css = getBlockStyles( selector, style, backgroundColor );
|
|
||||||
return (
|
|
||||||
<style>{ css }</style>
|
|
||||||
);
|
|
||||||
}
|
|
|
@ -1,43 +0,0 @@
|
||||||
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
|
|
||||||
import { __ } from '@wordpress/i18n';
|
|
||||||
import { SelectControl, PanelBody } from '@wordpress/components';
|
|
||||||
import { useUserOptions } from '../shared/use-user-options';
|
|
||||||
import FollowMe from './follow-me';
|
|
||||||
import { useEffect } from '@wordpress/element';
|
|
||||||
|
|
||||||
export default function Edit( { attributes, setAttributes } ) {
|
|
||||||
const blockProps = useBlockProps( {
|
|
||||||
className: 'activitypub-follow-me-block-wrapper',
|
|
||||||
} );
|
|
||||||
const usersOptions = useUserOptions();
|
|
||||||
const { selectedUser } = attributes;
|
|
||||||
|
|
||||||
useEffect( () => {
|
|
||||||
// if there are no users yet, do nothing
|
|
||||||
if ( ! usersOptions.length ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// ensure that the selected user is in the list of options, if not, select the first available user
|
|
||||||
if ( ! usersOptions.find( ( { value } ) => value === selectedUser ) ) {
|
|
||||||
setAttributes( { selectedUser: usersOptions[ 0 ].value } );
|
|
||||||
}
|
|
||||||
}, [ selectedUser, usersOptions ] );
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div { ...blockProps }>
|
|
||||||
{ usersOptions.length > 1 && (
|
|
||||||
<InspectorControls key="setting">
|
|
||||||
<PanelBody title={ __( 'Followers Options', 'activitypub' ) }>
|
|
||||||
<SelectControl
|
|
||||||
label= { __( 'Select User', 'activitypub' ) }
|
|
||||||
value={ attributes.selectedUser }
|
|
||||||
options={ usersOptions }
|
|
||||||
onChange={ ( value ) => setAttributes( { selectedUser: value } ) }
|
|
||||||
/>
|
|
||||||
</PanelBody>
|
|
||||||
</InspectorControls>
|
|
||||||
) }
|
|
||||||
<FollowMe { ...attributes } id={ blockProps.id } />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
|
@ -1,181 +0,0 @@
|
||||||
|
|
||||||
import apiFetch from '@wordpress/api-fetch';
|
|
||||||
import { useCallback, useEffect, useState, createInterpolateElement } from '@wordpress/element';
|
|
||||||
import { Button, Modal } from '@wordpress/components';
|
|
||||||
import { __, sprintf } from '@wordpress/i18n';
|
|
||||||
import { copy, check, Icon } from '@wordpress/icons';
|
|
||||||
import { useCopyToClipboard } from '@wordpress/compose';
|
|
||||||
import { ButtonStyle, getPopupStyles } from './button-style';
|
|
||||||
import './style.scss';
|
|
||||||
const { namespace } = window._activityPubOptions;
|
|
||||||
|
|
||||||
const DEFAULT_PROFILE_DATA = {
|
|
||||||
avatar: '',
|
|
||||||
resource: '@well@hello.dolly',
|
|
||||||
name: __( 'Hello Dolly Fan Account', 'activitypub' ),
|
|
||||||
url: '#',
|
|
||||||
};
|
|
||||||
|
|
||||||
function getNormalizedProfile( profile ) {
|
|
||||||
if ( ! profile ) {
|
|
||||||
return DEFAULT_PROFILE_DATA;
|
|
||||||
}
|
|
||||||
const data = { ...DEFAULT_PROFILE_DATA, ...profile };
|
|
||||||
data.avatar = data?.icon?.url;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
function fetchProfile( userId ) {
|
|
||||||
const fetchOptions = {
|
|
||||||
headers: { Accept: 'application/activity+json' },
|
|
||||||
path: `/${ namespace }/users/${ userId }`,
|
|
||||||
};
|
|
||||||
return apiFetch( fetchOptions );
|
|
||||||
}
|
|
||||||
|
|
||||||
function Profile( { profile, popupStyles, userId } ) {
|
|
||||||
const { avatar, name, resource } = profile;
|
|
||||||
return (
|
|
||||||
<div className="activitypub-profile">
|
|
||||||
<img className="activitypub-profile__avatar" src={ avatar } />
|
|
||||||
<div className="activitypub-profile__content">
|
|
||||||
<div className="activitypub-profile__name">{ name }</div>
|
|
||||||
<div className="activitypub-profile__handle" title={ resource }>{ resource }</div>
|
|
||||||
</div>
|
|
||||||
<Follow profile={ profile } popupStyles={ popupStyles } userId={ userId } />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function Follow( { profile, popupStyles, userId } ) {
|
|
||||||
const [ isOpen, setIsOpen ] = useState( false );
|
|
||||||
const title = sprintf( __( 'Follow %s', 'activitypub' ), profile?.name );
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Button className="activitypub-profile__follow" onClick={ () => setIsOpen( true ) } >
|
|
||||||
{ __( 'Follow', 'activitypub' ) }
|
|
||||||
</Button>
|
|
||||||
{ isOpen && (
|
|
||||||
<Modal
|
|
||||||
className="activitypub-profile__confirm"
|
|
||||||
onRequestClose={ () => setIsOpen( false ) }
|
|
||||||
title={ title }
|
|
||||||
>
|
|
||||||
<Dialog profile={ profile } userId={ userId } />
|
|
||||||
<style>{ popupStyles }</style>
|
|
||||||
</Modal>
|
|
||||||
) }
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isUrl( string ) {
|
|
||||||
try {
|
|
||||||
new URL( string );
|
|
||||||
return true;
|
|
||||||
} catch ( _ ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function isHandle( string ) {
|
|
||||||
// remove leading @, there should still be an @ in there
|
|
||||||
const parts = string.replace( /^@/, '' ).split( '@' );
|
|
||||||
return parts.length === 2 && isUrl( `https://${ parts[ 1 ] }` );
|
|
||||||
}
|
|
||||||
|
|
||||||
function Dialog( { profile, userId } ) {
|
|
||||||
const { resource } = profile;
|
|
||||||
const followText = __( 'Follow', 'activitypub' );
|
|
||||||
const loadingText = __( 'Loading...', 'activitypub' );
|
|
||||||
const openingText = __( 'Opening...', 'activitypub' );
|
|
||||||
const errorText = __( 'Error', 'activitypub' );
|
|
||||||
const invalidText = __( 'Invalid', 'activitypub' );
|
|
||||||
const [ buttonText, setButtonText ] = useState( followText );
|
|
||||||
const [ buttonIcon, setButtonIcon ] = useState( copy );
|
|
||||||
const ref = useCopyToClipboard( resource, () => {
|
|
||||||
setButtonIcon( check );
|
|
||||||
setTimeout( () => setButtonIcon( copy ), 1000 );
|
|
||||||
} );
|
|
||||||
const [ remoteProfile, setRemoteProfile ] = useState( '' );
|
|
||||||
const retrieveAndFollow = useCallback( () => {
|
|
||||||
let timeout;
|
|
||||||
if ( ! ( isUrl( remoteProfile ) || isHandle( remoteProfile ) ) ) {
|
|
||||||
setButtonText( invalidText );
|
|
||||||
timeout = setTimeout( () => setButtonText( followText ), 2000 );
|
|
||||||
return () => clearTimeout( timeout );
|
|
||||||
}
|
|
||||||
const path = `/${ namespace }/users/${userId}/remote-follow?resource=${ remoteProfile }`;
|
|
||||||
setButtonText( loadingText );
|
|
||||||
apiFetch( { path } ).then( ( { url } ) => {
|
|
||||||
setButtonText( openingText );
|
|
||||||
setTimeout( () => {
|
|
||||||
window.open( url, '_blank' );
|
|
||||||
setButtonText( followText );
|
|
||||||
}, 200 );
|
|
||||||
} ).catch( () => {
|
|
||||||
setButtonText( errorText );
|
|
||||||
setTimeout( () => setButtonText( followText ), 2000 );
|
|
||||||
} );
|
|
||||||
}, [ remoteProfile ] );
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="activitypub-follow-me__dialog">
|
|
||||||
<div className="apmfd__section">
|
|
||||||
<h4>{ __( 'My Profile', 'activitypub' ) }</h4>
|
|
||||||
<div className="apfmd-description">
|
|
||||||
{ __( 'Copy and paste my profile into the search field of your favorite fediverse app or server.', 'activitypub' ) }
|
|
||||||
</div>
|
|
||||||
<div className="apfmd__button-group">
|
|
||||||
<input type="text" value={ resource } readOnly />
|
|
||||||
<Button ref={ ref }>
|
|
||||||
<Icon icon={ buttonIcon } />
|
|
||||||
{ __( 'Copy', 'activitypub' ) }
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="apmfd__section">
|
|
||||||
<h4>{ __( 'Your Profile', 'activitypub' ) }</h4>
|
|
||||||
<div className="apfmd-description">
|
|
||||||
{ createInterpolateElement(
|
|
||||||
__( 'Or, if you know your own profile, we can start things that way! (eg <code>https://example.com/yourusername</code> or <code>yourusername@example.com</code>)', 'activitypub' ),
|
|
||||||
{ code: <code /> }
|
|
||||||
) }
|
|
||||||
</div>
|
|
||||||
<div className="apfmd__button-group">
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
value={ remoteProfile }
|
|
||||||
onKeyDown={ ( event ) => { event?.code === 'Enter' && retrieveAndFollow() } }
|
|
||||||
onChange={ e => setRemoteProfile( e.target.value ) }
|
|
||||||
/>
|
|
||||||
<Button onClick={ retrieveAndFollow }>{ buttonText }</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function FollowMe( { selectedUser, style, backgroundColor, id, useId = false, profileData = false } ) {
|
|
||||||
const [ profile, setProfile ] = useState( getNormalizedProfile() );
|
|
||||||
const userId = selectedUser === 'site' ? 0 : selectedUser;
|
|
||||||
const popupStyles = getPopupStyles( style );
|
|
||||||
const wrapperProps = useId ? { id } : {};
|
|
||||||
function setProfileData( profile ) {
|
|
||||||
setProfile( getNormalizedProfile( profile ) );
|
|
||||||
}
|
|
||||||
useEffect( () => {
|
|
||||||
if ( profileData ) {
|
|
||||||
return setProfileData( profileData );
|
|
||||||
}
|
|
||||||
fetchProfile( userId ).then( setProfileData );
|
|
||||||
}, [ userId, profileData ] );
|
|
||||||
|
|
||||||
return(
|
|
||||||
<div { ...wrapperProps }>
|
|
||||||
<ButtonStyle selector={ `#${ id }` } style={ style } backgroundColor={ backgroundColor } />
|
|
||||||
<Profile profile={ profile } userId={ userId } popupStyles={ popupStyles } />
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
import { registerBlockType } from '@wordpress/blocks';
|
|
||||||
import { people } from '@wordpress/icons';
|
|
||||||
import edit from './edit';
|
|
||||||
const save = () => null;
|
|
||||||
registerBlockType( 'activitypub/follow-me', { edit, save, icon: people } );
|
|
|
@ -1,93 +0,0 @@
|
||||||
.activitypub-follow-me-block-wrapper {
|
|
||||||
width: 100%;
|
|
||||||
|
|
||||||
// extra side padding for border/background colors
|
|
||||||
&.has-border-color, &.has-background {
|
|
||||||
.activitypub-profile {
|
|
||||||
padding-left: 1rem;
|
|
||||||
padding-right: 1rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.activitypub-profile {
|
|
||||||
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
// right/left padding overridden above for border/background colors
|
|
||||||
padding: 1rem 0;
|
|
||||||
|
|
||||||
.activitypub-profile__avatar {
|
|
||||||
height: 75px;
|
|
||||||
width: 75px;
|
|
||||||
margin-right: 1rem;
|
|
||||||
border-radius: 50%;
|
|
||||||
}
|
|
||||||
.activitypub-profile__content {
|
|
||||||
flex: 1;
|
|
||||||
min-width: 0;
|
|
||||||
}
|
|
||||||
.activitypub-profile__name, .activitypub-profile__handle {
|
|
||||||
margin: 0;
|
|
||||||
line-height: 1.2;
|
|
||||||
white-space: nowrap;
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
}
|
|
||||||
.activitypub-profile__name {
|
|
||||||
font-size: 1.25em;
|
|
||||||
}
|
|
||||||
.activitypub-profile__follow {
|
|
||||||
margin-left: 1rem;
|
|
||||||
align-self: center;
|
|
||||||
background-color: var(--wp--preset--color--black);
|
|
||||||
color: var(--wp--preset--color--white);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.activitypub-profile__confirm.components-modal__frame {
|
|
||||||
// @todo: play more nicely with dark background themes. the dialog is hardcoded to white bg in core, we go #eee here.
|
|
||||||
color: #333;
|
|
||||||
background-color: #f7f7f7;
|
|
||||||
.components-modal__header-heading, h4 {
|
|
||||||
color: #333;
|
|
||||||
// resets against potential theme weirdness
|
|
||||||
letter-spacing: inherit;
|
|
||||||
word-spacing: inherit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.activitypub-follow-me__dialog {
|
|
||||||
max-width: 30em;
|
|
||||||
h4 {
|
|
||||||
line-height: 1;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
.apmfd__section {
|
|
||||||
margin-bottom: 2em;
|
|
||||||
}
|
|
||||||
.apfmd-description {
|
|
||||||
font-size: var( --wp--preset--font-size--normal, .75rem );
|
|
||||||
margin: 0.33em 0 1em;
|
|
||||||
}
|
|
||||||
.apfmd__button-group {
|
|
||||||
display: flex;
|
|
||||||
justify-content: flex-end;
|
|
||||||
align-items: flex-end;
|
|
||||||
|
|
||||||
svg {
|
|
||||||
margin-right: .5em;
|
|
||||||
height: 21px;
|
|
||||||
width: 21px;
|
|
||||||
}
|
|
||||||
|
|
||||||
input {
|
|
||||||
flex: 1;
|
|
||||||
padding: 6px 12px;
|
|
||||||
background-color: var( --wp--preset--color--white );
|
|
||||||
color: var( --wp--preset--color--black );
|
|
||||||
border: 1px solid var( --wp--preset--color--black );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
import { render } from '@wordpress/element';
|
|
||||||
import domReady from '@wordpress/dom-ready';
|
|
||||||
import FollowMe from './follow-me';
|
|
||||||
|
|
||||||
let id = 1;
|
|
||||||
function getUniqueId() {
|
|
||||||
return `activitypub-follow-me-block-${ id++ }`;
|
|
||||||
}
|
|
||||||
|
|
||||||
domReady( () => {
|
|
||||||
// iterate over a nodelist
|
|
||||||
[].forEach.call( document.querySelectorAll( '.activitypub-follow-me-block-wrapper' ), ( element ) => {
|
|
||||||
const attrs = JSON.parse( element.dataset.attrs );
|
|
||||||
render( <FollowMe { ...attrs } id={ getUniqueId() } useId={ true } />, element );
|
|
||||||
} );
|
|
||||||
} );
|
|
|
@ -1,9 +1,31 @@
|
||||||
import { SelectControl, RangeControl, PanelBody, TextControl } from '@wordpress/components';
|
import { SelectControl, RangeControl, PanelBody, TextControl } from '@wordpress/components';
|
||||||
import { useState, useEffect } from '@wordpress/element';
|
import { useSelect } from '@wordpress/data';
|
||||||
|
import { useMemo, useState } from '@wordpress/element';
|
||||||
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
|
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { Followers } from './followers';
|
import { Followers } from './followers';
|
||||||
import { useUserOptions } from '../shared/use-user-options';
|
|
||||||
|
const enabled = window._activityPubOptions?.enabled;
|
||||||
|
|
||||||
|
function useUserOptions() {
|
||||||
|
const users = enabled?.users ? useSelect( ( select ) => select( 'core' ).getUsers( { who: 'authors' } ) ) : [];
|
||||||
|
return useMemo( () => {
|
||||||
|
if ( ! users ) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const withBlogUser = enabled?.site ? [ {
|
||||||
|
label: __( 'Whole Site', 'activitypub' ),
|
||||||
|
value: 'site'
|
||||||
|
} ] : [];
|
||||||
|
return users.reduce( ( acc, user ) => {
|
||||||
|
acc.push({
|
||||||
|
label: user.name,
|
||||||
|
value: user.id
|
||||||
|
} );
|
||||||
|
return acc;
|
||||||
|
}, withBlogUser );
|
||||||
|
}, [ users ] );
|
||||||
|
}
|
||||||
|
|
||||||
export default function Edit( { attributes, setAttributes } ) {
|
export default function Edit( { attributes, setAttributes } ) {
|
||||||
const { order, per_page, selectedUser, title } = attributes;
|
const { order, per_page, selectedUser, title } = attributes;
|
||||||
|
@ -21,17 +43,6 @@ export default function Edit( { attributes, setAttributes } ) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect( () => {
|
|
||||||
// if there are no users yet, do nothing
|
|
||||||
if ( ! usersOptions.length ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// ensure that the selected user is in the list of options, if not, select the first available user
|
|
||||||
if ( ! usersOptions.find( ( { value } ) => value === selectedUser ) ) {
|
|
||||||
setAttributes( { selectedUser: usersOptions[ 0 ].value } );
|
|
||||||
}
|
|
||||||
}, [ selectedUser, usersOptions ] );
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div { ...blockProps }>
|
<div { ...blockProps }>
|
||||||
<InspectorControls key="setting">
|
<InspectorControls key="setting">
|
||||||
|
@ -42,14 +53,12 @@ export default function Edit( { attributes, setAttributes } ) {
|
||||||
value={ title }
|
value={ title }
|
||||||
onChange={ value => setAttributes( { title: value } ) }
|
onChange={ value => setAttributes( { title: value } ) }
|
||||||
/>
|
/>
|
||||||
{ usersOptions.length > 1 && (
|
|
||||||
<SelectControl
|
<SelectControl
|
||||||
label= { __( 'Select User', 'activitypub' ) }
|
label= { __( 'Select User', 'activitypub' ) }
|
||||||
value={ selectedUser }
|
value={ selectedUser }
|
||||||
options={ usersOptions }
|
options={ usersOptions }
|
||||||
onChange={ setAttributestAndResetPage( 'selectedUser' ) }
|
onChange={ setAttributestAndResetPage( 'selectedUser' ) }
|
||||||
/>
|
/>
|
||||||
) }
|
|
||||||
<SelectControl
|
<SelectControl
|
||||||
label={ __( 'Sort', 'activitypub' ) }
|
label={ __( 'Sort', 'activitypub' ) }
|
||||||
value={ order }
|
value={ order }
|
||||||
|
|
|
@ -32,8 +32,7 @@ export function Followers( {
|
||||||
page: passedPage,
|
page: passedPage,
|
||||||
setPage: passedSetPage,
|
setPage: passedSetPage,
|
||||||
className = '',
|
className = '',
|
||||||
followLinks = true,
|
followLinks = true
|
||||||
followerData = false
|
|
||||||
} ) {
|
} ) {
|
||||||
const userId = selectedUser === 'site' ? 0 : selectedUser;
|
const userId = selectedUser === 'site' ? 0 : selectedUser;
|
||||||
const [ followers, setFollowers ] = useState( [] );
|
const [ followers, setFollowers ] = useState( [] );
|
||||||
|
@ -57,22 +56,16 @@ export function Followers( {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const setData = ( followers, total ) => {
|
|
||||||
setFollowers( followers );
|
|
||||||
setTotal( total );
|
|
||||||
setPages( Math.ceil( total / per_page ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
if ( followerData && page === 1 ) {
|
|
||||||
return setData( followerData.followers, followerData.total );
|
|
||||||
}
|
|
||||||
|
|
||||||
const path = getPath( userId, per_page, order, page );
|
const path = getPath( userId, per_page, order, page );
|
||||||
apiFetch( { path } )
|
apiFetch( { path } )
|
||||||
.then( ( data ) => setData( data.orderedItems, data.totalItems ) )
|
.then( ( data ) => {
|
||||||
.catch( () => {} );
|
setPages( Math.ceil( data.totalItems / per_page ) );
|
||||||
}, [ userId, per_page, order, page, followerData ] );
|
setTotal( data.totalItems );
|
||||||
|
setFollowers( data.orderedItems );
|
||||||
|
} )
|
||||||
|
.catch( ( error ) => console.error( error ) );
|
||||||
|
}, [ userId, per_page, order, page ] );
|
||||||
return (
|
return (
|
||||||
<div className={ "activitypub-follower-block " + className }>
|
<div className={ "activitypub-follower-block " + className }>
|
||||||
<h3>{ title }</h3>
|
<h3>{ title }</h3>
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
import { __ } from '@wordpress/i18n';
|
|
||||||
import { useSelect } from '@wordpress/data';
|
|
||||||
import { useMemo } from '@wordpress/element';
|
|
||||||
const enabled = window._activityPubOptions?.enabled;
|
|
||||||
|
|
||||||
export function useUserOptions() {
|
|
||||||
const users = enabled?.users ? useSelect( ( select ) => select( 'core' ).getUsers( { who: 'authors' } ) ) : [];
|
|
||||||
return useMemo( () => {
|
|
||||||
if ( ! users ) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
const withBlogUser = enabled?.site ? [ {
|
|
||||||
label: __( 'Whole Site', 'activitypub' ),
|
|
||||||
value: 'site'
|
|
||||||
} ] : [];
|
|
||||||
return users.reduce( ( acc, user ) => {
|
|
||||||
acc.push({
|
|
||||||
label: user.name,
|
|
||||||
value: `${ user.id }` // casting to string because that's how the attribute is stored by Gutenberg
|
|
||||||
} );
|
|
||||||
return acc;
|
|
||||||
}, withBlogUser );
|
|
||||||
}, [ users ] );
|
|
||||||
}
|
|
|
@ -6,7 +6,7 @@
|
||||||
<h1><?php \esc_html_e( 'ActivityPub', 'activitypub' ); ?></h1>
|
<h1><?php \esc_html_e( 'ActivityPub', 'activitypub' ); ?></h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<nav class="activitypub-settings-tabs-wrapper" aria-label="<?php \esc_attr_e( 'Secondary menu', 'activitypub' ); ?>">
|
<nav class="activitypub-settings-tabs-wrapper hide-if-no-js" aria-label="<?php \esc_attr_e( 'Secondary menu', 'activitypub' ); ?>">
|
||||||
<a href="<?php echo \esc_url_raw( admin_url( 'options-general.php?page=activitypub' ) ); ?>" class="activitypub-settings-tab <?php echo \esc_attr( $args['welcome'] ); ?>">
|
<a href="<?php echo \esc_url_raw( admin_url( 'options-general.php?page=activitypub' ) ); ?>" class="activitypub-settings-tab <?php echo \esc_attr( $args['welcome'] ); ?>">
|
||||||
<?php \esc_html_e( 'Welcome', 'activitypub' ); ?>
|
<?php \esc_html_e( 'Welcome', 'activitypub' ); ?>
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -8,21 +8,23 @@
|
||||||
'followers' => 'active',
|
'followers' => 'active',
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$table = new \Activitypub\Table\Followers();
|
|
||||||
$follower_count = $table->get_user_count();
|
|
||||||
// translators: The follower count.
|
|
||||||
$followers_template = _n( 'Your blog profile currently has %s follower.', 'Your blog profile currently has %s followers.', $follower_count, 'activitypub' );
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="wrap activitypub-followers-page">
|
<div class="wrap activitypub-followers-page">
|
||||||
<p><?php \printf( \esc_html( $followers_template ), \esc_attr( $follower_count ) ); ?></p>
|
<h1><?php \esc_html_e( 'Followers', 'activitypub' ); ?></h1>
|
||||||
|
|
||||||
|
<?php $table = new \Activitypub\Table\Followers(); ?>
|
||||||
|
|
||||||
|
<?php // translators: The follower count. ?>
|
||||||
|
<p><?php \printf( \esc_html__( 'You currently have %s followers.', 'activitypub' ), \esc_attr( $table->get_user_count() ) ); ?></p>
|
||||||
|
|
||||||
<form method="get">
|
<form method="get">
|
||||||
<input type="hidden" name="page" value="activitypub" />
|
<input type="hidden" name="page" value="activitypub" />
|
||||||
<input type="hidden" name="tab" value="followers" />
|
<input type="hidden" name="tab" value="followers" />
|
||||||
<?php
|
<?php
|
||||||
$table->prepare_items();
|
$table->prepare_items();
|
||||||
$table->search_box( 'Search', 'search' );
|
|
||||||
$table->display();
|
$table->display();
|
||||||
?>
|
?>
|
||||||
|
<?php wp_nonce_field( 'activitypub-followers-list', '_apnonce' ); ?>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -2,9 +2,8 @@
|
||||||
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
||||||
$post = \get_post();
|
$post = \get_post();
|
||||||
|
|
||||||
$transformer = \Activitypub\Transformer\Transformers_Manager::instance()->get_transformer( $post );
|
$object = new \Activitypub\Transformer\Post( $post );
|
||||||
|
$json = \array_merge( array( '@context' => \Activitypub\get_context() ), $object->to_object()->to_array() );
|
||||||
$json = \array_merge( array( '@context' => \Activitypub\get_context() ), $transformer->to_object()->to_array() );
|
|
||||||
|
|
||||||
// filter output
|
// filter output
|
||||||
$json = \apply_filters( 'activitypub_json_post_array', $json );
|
$json = \apply_filters( 'activitypub_json_post_array', $json );
|
||||||
|
|
|
@ -11,41 +11,60 @@
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="activitypub-settings activitypub-settings-page hide-if-no-js">
|
<div class="activitypub-settings activitypub-settings-page hide-if-no-js">
|
||||||
|
<div class="box">
|
||||||
|
<h3><?php \esc_html_e( 'Troubleshooting', 'activitypub' ); ?></h3>
|
||||||
|
<p>
|
||||||
|
<?php
|
||||||
|
echo \wp_kses(
|
||||||
|
\sprintf(
|
||||||
|
// translators:
|
||||||
|
\__( 'If you have problems using this plugin, please check the <a href="%s">Site Health</a> to ensure that your site is compatible and/or use the "Help" tab (in the top right of the settings pages).', 'activitypub' ),
|
||||||
|
\esc_url_raw( \admin_url( 'site-health.php' ) )
|
||||||
|
),
|
||||||
|
'default'
|
||||||
|
);
|
||||||
|
?>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<form method="post" action="options.php">
|
<form method="post" action="options.php">
|
||||||
<?php \settings_fields( 'activitypub' ); ?>
|
<?php \settings_fields( 'activitypub' ); ?>
|
||||||
|
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<h3><?php \esc_html_e( 'Profiles', 'activitypub' ); ?></h3>
|
<h3><?php \esc_html_e( 'Users', 'activitypub' ); ?></h3>
|
||||||
|
|
||||||
|
<p><?php \esc_html_e( 'All user related settings.', 'activitypub' ); ?></p>
|
||||||
|
|
||||||
<table class="form-table">
|
<table class="form-table">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">
|
<th scope="row">
|
||||||
<?php \esc_html_e( 'Enable profiles by type', 'activitypub' ); ?>
|
<?php \esc_html_e( 'Enable/disable Users by Type', 'activitypub' ); ?>
|
||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<p>
|
<p>
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" name="activitypub_enable_users" id="activitypub_enable_users" value="1" <?php echo \checked( '1', \get_option( 'activitypub_enable_users', '1' ) ); ?> />
|
<input type="checkbox" name="activitypub_enable_users" id="activitypub_enable_users" value="1" <?php echo \checked( '1', \get_option( 'activitypub_enable_users', '1' ) ); ?> />
|
||||||
<?php \esc_html_e( 'Enable authors', 'activitypub' ); ?>
|
<?php \esc_html_e( 'Enable Authors', 'activitypub' ); ?>
|
||||||
</label>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
<p class="description">
|
<p class="description">
|
||||||
<?php echo \wp_kses( \__( 'Every author on this blog (with the <code>publish_posts</code> capability) gets their own ActivityPub profile.', 'activitypub' ), array( 'code' => array() ) ); ?>
|
<?php echo \wp_kses( \__( 'Every Author on this Blog (with the <code>publish_posts</code> capability) gets his own ActivityPub enabled Profile.', 'activitypub' ), array( 'code' => array() ) ); ?>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" name="activitypub_enable_blog_user" id="activitypub_enable_blog_user" value="1" <?php echo \checked( '1', \get_option( 'activitypub_enable_blog_user', '0' ) ); ?> />
|
<input type="checkbox" name="activitypub_enable_blog_user" id="activitypub_enable_blog_user" value="1" <?php echo \checked( '1', \get_option( 'activitypub_enable_blog_user', '0' ) ); ?> />
|
||||||
<?php \esc_html_e( 'Enable blog', 'activitypub' ); ?>
|
<?php \esc_html_e( 'Enable Blog-User', 'activitypub' ); ?>
|
||||||
</label>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
<p class="description">
|
<p class="description">
|
||||||
<?php \esc_html_e( 'Your blog becomes an ActivityPub profile.', 'activitypub' ); ?>
|
<?php \esc_html_e( 'Your Blog becomes an ActivityPub compatible Profile.', 'activitypub' ); ?>
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">
|
<th scope="row">
|
||||||
<?php \esc_html_e( 'Change blog profile ID', 'activitypub' ); ?>
|
<?php \esc_html_e( 'Change Blog-User Identifier', 'activitypub' ); ?>
|
||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<label for="activitypub_blog_user_identifier">
|
<label for="activitypub_blog_user_identifier">
|
||||||
|
@ -53,12 +72,7 @@
|
||||||
@<?php echo esc_html( \wp_parse_url( \home_url(), PHP_URL_HOST ) ); ?>
|
@<?php echo esc_html( \wp_parse_url( \home_url(), PHP_URL_HOST ) ); ?>
|
||||||
</label>
|
</label>
|
||||||
<p class="description">
|
<p class="description">
|
||||||
<?php \esc_html_e( 'This profile name will federate all posts written on your blog, regardless of the author who posted it.', 'activitypub' ); ?>
|
<?php \esc_html_e( 'This Blog-User will federate all posts written on your Blog, regardless of the User who posted it.', 'activitypub' ); ?>
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
<strong>
|
|
||||||
<?php \esc_html_e( 'Please avoid using an existing author’s name as the blog profile ID. Fediverse platforms might use caching and this could break the functionality completely.', 'activitypub' ); ?>
|
|
||||||
</strong>
|
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -70,11 +84,14 @@
|
||||||
|
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<h3><?php \esc_html_e( 'Activities', 'activitypub' ); ?></h3>
|
<h3><?php \esc_html_e( 'Activities', 'activitypub' ); ?></h3>
|
||||||
|
|
||||||
|
<p><?php \esc_html_e( 'All activity related settings.', 'activitypub' ); ?></p>
|
||||||
|
|
||||||
<table class="form-table">
|
<table class="form-table">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">
|
<th scope="row">
|
||||||
<?php \esc_html_e( 'Post content', 'activitypub' ); ?>
|
<?php \esc_html_e( 'Post-Content', 'activitypub' ); ?>
|
||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<p>
|
<p>
|
||||||
|
@ -113,7 +130,7 @@
|
||||||
<?php \esc_html_e( 'Custom', 'activitypub' ); ?>
|
<?php \esc_html_e( 'Custom', 'activitypub' ); ?>
|
||||||
-
|
-
|
||||||
<span class="description">
|
<span class="description">
|
||||||
<?php \esc_html_e( 'Use the text area below, to customize your activities.', 'activitypub' ); ?>
|
<?php \esc_html_e( 'Use the text-area below, to customize your activities.', 'activitypub' ); ?>
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
|
@ -138,7 +155,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">
|
<th scope="row">
|
||||||
<?php \esc_html_e( 'Media attachments', 'activitypub' ); ?>
|
<?php \esc_html_e( 'Number of images', 'activitypub' ); ?>
|
||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<input value="<?php echo esc_attr( \get_option( 'activitypub_max_image_attachments', ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS ) ); ?>" name="activitypub_max_image_attachments" id="activitypub_max_image_attachments" type="number" min="0" />
|
<input value="<?php echo esc_attr( \get_option( 'activitypub_max_image_attachments', ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS ) ); ?>" name="activitypub_max_image_attachments" id="activitypub_max_image_attachments" type="number" min="0" />
|
||||||
|
@ -147,20 +164,13 @@
|
||||||
echo \wp_kses(
|
echo \wp_kses(
|
||||||
\sprintf(
|
\sprintf(
|
||||||
// translators:
|
// translators:
|
||||||
\__( 'The number of media (images, audio, video) to attach to posts. Default: <code>%s</code>', 'activitypub' ),
|
\__( 'The number of images to attach to posts. Default: <code>%s</code>', 'activitypub' ),
|
||||||
\esc_html( ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS )
|
\esc_html( ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS )
|
||||||
),
|
),
|
||||||
'default'
|
'default'
|
||||||
);
|
);
|
||||||
?>
|
?>
|
||||||
</p>
|
</p>
|
||||||
<p class="description">
|
|
||||||
<em>
|
|
||||||
<?php
|
|
||||||
esc_html_e( 'Note: audio and video attachments are only supported from Block Editor.', 'activitypub' );
|
|
||||||
?>
|
|
||||||
</em>
|
|
||||||
</p>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -178,14 +188,13 @@
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
<p><strong><?php \esc_html_e( 'Please note that the following "Activity-Object-Type" options may cause your texts to be displayed differently on each platform and/or parts may be completely ignored. Mastodon, for example, displays all content that is not of the "Note" type as links only.', 'activitypub' ); ?></strong></p>
|
|
||||||
<p>
|
<p>
|
||||||
<label for="activitypub_object_type_article">
|
<label for="activitypub_object_type_article">
|
||||||
<input type="radio" name="activitypub_object_type" id="activitypub_object_type_article" value="article" <?php echo \checked( 'article', \get_option( 'activitypub_object_type', 'note' ) ); ?> />
|
<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' ); ?>
|
<?php \esc_html_e( 'Article', 'activitypub' ); ?>
|
||||||
-
|
-
|
||||||
<span class="description">
|
<span class="description">
|
||||||
<?php \esc_html_e( 'The presentation of the "Article" might change on different platforms.', 'activitypub' ); ?>
|
<?php \esc_html_e( 'The presentation of the "Article" might change on different platforms. Mastodon for example shows the "Article" type as a simple link.', 'activitypub' ); ?>
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
|
@ -201,13 +210,33 @@
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row"><?php \esc_html_e( 'Supported post types', 'activitypub' ); ?></th>
|
||||||
|
<td>
|
||||||
|
<fieldset>
|
||||||
|
<?php \esc_html_e( 'Enable ActivityPub support for the following post types:', 'activitypub' ); ?>
|
||||||
|
|
||||||
|
<?php $post_types = \get_post_types( array( 'public' => true ), 'objects' ); ?>
|
||||||
|
<?php $support_post_types = \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) ) ? \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) ) : array(); ?>
|
||||||
|
<ul>
|
||||||
|
<?php // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited ?>
|
||||||
|
<?php foreach ( $post_types as $post_type ) { ?>
|
||||||
|
<li>
|
||||||
|
<input type="checkbox" id="activitypub_support_post_type_<?php echo \esc_attr( $post_type->name ); ?>" name="activitypub_support_post_types[]" value="<?php echo \esc_attr( $post_type->name ); ?>" <?php echo \checked( \in_array( $post_type->name, $support_post_types, true ) ); ?> />
|
||||||
|
<label for="activitypub_support_post_type_<?php echo \esc_attr( $post_type->name ); ?>"><?php echo \esc_html( $post_type->label ); ?></label>
|
||||||
|
</li>
|
||||||
|
<?php } ?>
|
||||||
|
</ul>
|
||||||
|
</fieldset>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">
|
<th scope="row">
|
||||||
<?php \esc_html_e( 'Hashtags (beta)', 'activitypub' ); ?>
|
<?php \esc_html_e( 'Hashtags (beta)', 'activitypub' ); ?>
|
||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<p>
|
<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 echo wp_kses( \__( 'Add hashtags in the content as native tags and replace the <code>#tag</code> with the tag link. <strong>This feature is experimental! Please disable it, if you find any HTML or CSS errors.</strong>', 'activitypub' ), 'default' ); ?></label>
|
<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 echo wp_kses( \__( 'Add hashtags in the content as native tags and replace the <code>#tag</code> with the tag-link. <strong>This feature is experimental! Please disable it, if you find any HTML or CSS errors.</strong>', 'activitypub' ), 'default' ); ?></label>
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -217,95 +246,11 @@
|
||||||
<?php \do_settings_fields( 'activitypub', 'activity' ); ?>
|
<?php \do_settings_fields( 'activitypub', 'activity' ); ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- OUR FORK HERE -->
|
|
||||||
<div class="box">
|
|
||||||
<h3><?php \esc_html_e( 'Enable ActivityPub support for post type', 'activitypub' ); ?></h3>
|
|
||||||
|
|
||||||
<table class="form-table">
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">
|
|
||||||
<?php \esc_html_e( 'Mapping', 'activitypub' ); ?>
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
<?php \esc_html_e( 'Enable ActivityPub support for a certain post type by selecting one of the available ActivityPub transformers.', 'activitypub' ); ?>
|
|
||||||
|
|
||||||
<?php $all_public_post_types = \get_post_types( array( 'public' => true ), 'objects' );
|
|
||||||
$transformer_mapping = \get_option( 'activitypub_transformer_mapping', array( 'default' => 'note' ) );
|
|
||||||
|
|
||||||
$all_public_post_type_names = array_map(function ($object) {
|
|
||||||
return $object->name;
|
|
||||||
}, $all_public_post_types);
|
|
||||||
|
|
||||||
$transformer_manager = \Activitypub\Transformer\Transformers_Manager::instance();
|
|
||||||
$transformers = $transformer_manager->get_transformers();
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
||||||
|
|
||||||
<script>
|
|
||||||
// TODO Probably we should use checkboxes and not select and make this less buggy and insert the js at the right place.
|
|
||||||
document.addEventListener('DOMContentLoaded', function () {
|
|
||||||
var radioGroups = {};
|
|
||||||
|
|
||||||
var radioButtons = document.querySelectorAll('input[type="radio"]');
|
|
||||||
|
|
||||||
radioButtons.forEach(function (radioButton) {
|
|
||||||
radioButton.addEventListener('click', function () {
|
|
||||||
var name = this.name;
|
|
||||||
|
|
||||||
if (!radioGroups[name]) {
|
|
||||||
radioGroups[name] = this;
|
|
||||||
} else {
|
|
||||||
radioGroups[name].checked = false;
|
|
||||||
radioGroups[name] = this;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th></th>
|
|
||||||
<?php
|
|
||||||
// Generate column headers based on transformer objects
|
|
||||||
foreach ($transformers as $transformer) {
|
|
||||||
echo '<th>' . htmlspecialchars($transformer->get_label()) . '</th>';
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<?php
|
|
||||||
// Generate rows based on post types and transformers
|
|
||||||
foreach ($all_public_post_types as $post_type) {
|
|
||||||
echo '<tr>';
|
|
||||||
echo '<td><strong>' . htmlspecialchars($post_type->label) . '</strong></td>';
|
|
||||||
// Generate radio inputs for each transformer, considering support for the post type
|
|
||||||
foreach ($transformers as $transformer) {
|
|
||||||
$disabled_attribute = $transformer->supports_post_type( $post_type->name ) ? '' : ' disabled';
|
|
||||||
$is_selected = ( is_array( $transformer_mapping ) && isset( $transformer_mapping[ $post_type->name ] ) && $transformer_mapping[ $post_type->name ] === $transformer->get_name() ) ? ' checked ' : '';
|
|
||||||
echo '<td><input type="radio" name="activitypub_transformer_mapping[' . $post_type->name . ']" value="' . $transformer->get_name() . '"' . $is_selected . $disabled_attribute . '></td>';
|
|
||||||
}
|
|
||||||
|
|
||||||
echo '</tr>';
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<!-- OUR FORK ENDS HERE -->
|
|
||||||
|
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<h3><?php \esc_html_e( 'Server', 'activitypub' ); ?></h3>
|
<h3><?php \esc_html_e( 'Server', 'activitypub' ); ?></h3>
|
||||||
|
|
||||||
|
<p><?php \esc_html_e( 'Server related settings.', 'activitypub' ); ?></p>
|
||||||
|
|
||||||
<table class="form-table">
|
<table class="form-table">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -1,12 +1,7 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
$follower_count = \Activitypub\Collection\Followers::count_followers( \get_current_user_id() );
|
|
||||||
// translators: The follower count.
|
|
||||||
$followers_template = _n( 'Your author profile currently has %s follower.', 'Your author profile currently has %s followers.', $follower_count, 'activitypub' );
|
|
||||||
?>
|
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
<h1><?php \esc_html_e( 'Author Followers', 'activitypub' ); ?></h1>
|
<h1><?php \esc_html_e( 'Followers', 'activitypub' ); ?></h1>
|
||||||
<p><?php \printf( \esc_html( $followers_template ), \esc_attr( $follower_count ) ); ?></p>
|
<?php // translators: The follower count. ?>
|
||||||
|
<p><?php \printf( \esc_html__( 'You currently have %s followers.', 'activitypub' ), \esc_attr( \Activitypub\Collection\Followers::count_followers( \get_current_user_id() ) ) ); ?></p>
|
||||||
|
|
||||||
<?php $table = new \Activitypub\Table\Followers(); ?>
|
<?php $table = new \Activitypub\Table\Followers(); ?>
|
||||||
|
|
||||||
|
@ -14,8 +9,8 @@ $followers_template = _n( 'Your author profile currently has %s follower.', 'You
|
||||||
<input type="hidden" name="page" value="activitypub-followers-list" />
|
<input type="hidden" name="page" value="activitypub-followers-list" />
|
||||||
<?php
|
<?php
|
||||||
$table->prepare_items();
|
$table->prepare_items();
|
||||||
$table->search_box( 'Search', 'search' );
|
|
||||||
$table->display();
|
$table->display();
|
||||||
?>
|
?>
|
||||||
|
<?php wp_nonce_field( 'activitypub-followers-list', '_apnonce' ); ?>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -7,7 +7,7 @@ $user = \Activitypub\Collection\Users::get_by_id( \get_current_user_id() ); ?>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">
|
<th scope="row">
|
||||||
<label><?php \esc_html_e( 'Profile URL', 'activitypub' ); ?></label>
|
<label><?php \esc_html_e( 'Profile identifier', 'activitypub' ); ?></label>
|
||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<p>
|
<p>
|
||||||
|
@ -15,7 +15,7 @@ $user = \Activitypub\Collection\Users::get_by_id( \get_current_user_id() ); ?>
|
||||||
<code><?php echo \esc_url( $user->get_url() ); ?></code>
|
<code><?php echo \esc_url( $user->get_url() ); ?></code>
|
||||||
</p>
|
</p>
|
||||||
<?php // translators: the webfinger resource ?>
|
<?php // translators: the webfinger resource ?>
|
||||||
<p class="description"><?php \printf( \esc_html__( 'Follow "@%s" by searching for it on Mastodon, Friendica, etc.', 'activitypub' ), \esc_html( $user->get_resource() ) ); ?></p>
|
<p class="description"><?php \printf( \esc_html__( 'Try to follow "@%s" by searching for it on Mastodon,Friendica & Co.', 'activitypub' ), \esc_html( $user->get_resource() ) ); ?></p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="activitypub-user-description-wrap">
|
<tr class="activitypub-user-description-wrap">
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<h2><?php \esc_html_e( 'Welcome', 'activitypub' ); ?></h2>
|
<h2><?php \esc_html_e( 'Welcome', 'activitypub' ); ?></h2>
|
||||||
|
|
||||||
<p><?php echo wp_kses( \__( 'Enter the fediverse with <strong>ActivityPub</strong>, broadcasting your blog to a wider audience. Attract followers, deliver updates, and receive comments from a diverse user base on <strong>Mastodon</strong>, <strong>Friendica</strong>, <strong>Pleroma</strong>, <strong>Pixelfed</strong>, and all <strong>ActivityPub</strong>-compliant platforms.', 'activitypub' ), array( 'strong' => array() ) ); ?></p>
|
<p><?php echo wp_kses( \__( 'With ActivityPub your blog becomes part of a federated social network. This means you can share and talk to everyone using the <strong>ActivityPub</strong> protocol, including users of <strong>Friendica</strong>, <strong>Pleroma</strong>, <strong>Pixelfed</strong> and <strong>Mastodon</strong>.', 'activitypub' ), array( 'strong' => array() ) ); ?></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
@ -22,28 +22,28 @@
|
||||||
$blog_user = new \Activitypub\Model\Blog_User();
|
$blog_user = new \Activitypub\Model\Blog_User();
|
||||||
?>
|
?>
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<h3><?php \esc_html_e( 'Blog profile', 'activitypub' ); ?></h3>
|
<h3><?php \esc_html_e( 'Blog Account', 'activitypub' ); ?></h3>
|
||||||
<p>
|
<p>
|
||||||
<?php \esc_html_e( 'People can follow your blog by using:', 'activitypub' ); ?>
|
<?php \esc_html_e( 'People can follow your Blog by using:', 'activitypub' ); ?>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<label for="activitypub-blog-identifier"><?php \esc_html_e( 'Username', 'activitypub' ); ?></label>
|
<label for="activitypub-blog-identifier"><?php \esc_html_e( 'Username', 'activitypub' ); ?></label>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<input type="text" class="regular-text" id="activitypub-blog-identifier" value="<?php echo \esc_attr( $blog_user->get_resource() ); ?>" readonly />
|
<input type="text" class="regular-text" id="activitypub-blog-identifier" value="<?php echo \esc_attr( $blog_user->get_resource() ); ?>" />
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<label for="activitypub-blog-url"><?php \esc_html_e( 'Profile URL', 'activitypub' ); ?></label>
|
<label for="activitypub-blog-url"><?php \esc_html_e( 'Profile-URL', 'activitypub' ); ?></label>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<input type="text" class="regular-text" id="activitypub-blog-url" value="<?php echo \esc_attr( $blog_user->get_url() ); ?>" readonly />
|
<input type="text" class="regular-text" id="activitypub-blog-url" value="<?php echo \esc_attr( $blog_user->get_url() ); ?>" />
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<?php \esc_html_e( 'This blog profile will federate all posts written on your blog, regardless of the author who posted it.', 'activitypub' ); ?>
|
<?php \esc_html_e( 'This Blog-User will federate all posts written on your Blog, regardless of the User who posted it.', 'activitypub' ); ?>
|
||||||
<p>
|
<p>
|
||||||
<p>
|
<p>
|
||||||
<a href="<?php echo \esc_url_raw( \admin_url( '/options-general.php?page=activitypub&tab=settings' ) ); ?>">
|
<a href="<?php echo \esc_url_raw( \admin_url( '/options-general.php?page=activitypub&tab=settings' ) ); ?>">
|
||||||
<?php \esc_html_e( 'Customize the blog profile', 'activitypub' ); ?>
|
<?php \esc_html_e( 'Customize Blog-User on Settings page.', 'activitypub' ); ?>
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -54,28 +54,28 @@
|
||||||
$user = \Activitypub\Collection\Users::get_by_id( wp_get_current_user()->ID );
|
$user = \Activitypub\Collection\Users::get_by_id( wp_get_current_user()->ID );
|
||||||
?>
|
?>
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<h3><?php \esc_html_e( 'Author profile', 'activitypub' ); ?></h3>
|
<h3><?php \esc_html_e( 'Personal Account', 'activitypub' ); ?></h3>
|
||||||
<p>
|
<p>
|
||||||
<?php \esc_html_e( 'People can follow you by using your author name:', 'activitypub' ); ?>
|
<?php \esc_html_e( 'People can follow you by using your Username:', 'activitypub' ); ?>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<label for="activitypub-user-identifier"><?php \esc_html_e( 'Username', 'activitypub' ); ?></label>
|
<label for="activitypub-user-identifier"><?php \esc_html_e( 'Username', 'activitypub' ); ?></label>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<input type="text" class="regular-text" id="activitypub-user-identifier" value="<?php echo \esc_attr( $user->get_resource() ); ?>" readonly />
|
<input type="text" class="regular-text" id="activitypub-user-identifier" value="<?php echo \esc_attr( $user->get_resource() ); ?>" />
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<label for="activitypub-user-url"><?php \esc_html_e( 'Profile URL', 'activitypub' ); ?></label>
|
<label for="activitypub-user-url"><?php \esc_html_e( 'Profile-URL', 'activitypub' ); ?></label>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<input type="text" class="regular-text" id="activitypub-user-url" value="<?php echo \esc_attr( $user->get_url() ); ?>" readonly />
|
<input type="text" class="regular-text" id="activitypub-user-url" value="<?php echo \esc_attr( $user->get_url() ); ?>" />
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<?php \esc_html_e( 'Authors who can not access this settings page will find their username on the "Edit Profile" page.', 'activitypub' ); ?>
|
<?php \esc_html_e( 'Users who can not access this settings page will find their username on the "Edit Profile" page.', 'activitypub' ); ?>
|
||||||
<p>
|
<p>
|
||||||
<p>
|
<p>
|
||||||
<a href="<?php echo \esc_url_raw( \admin_url( '/profile.php#activitypub' ) ); ?>">
|
<a href="<?php echo \esc_url_raw( \admin_url( '/profile.php#activitypub' ) ); ?>">
|
||||||
<?php \esc_html_e( 'Customize username on "Edit Profile" page.', 'activitypub' ); ?>
|
<?php \esc_html_e( 'Customize Username on "Edit Profile" page.', 'activitypub' ); ?>
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -87,9 +87,9 @@
|
||||||
<?php
|
<?php
|
||||||
echo wp_kses(
|
echo wp_kses(
|
||||||
\sprintf(
|
\sprintf(
|
||||||
/* translators: the placeholder is the Site Health URL */
|
// translators:
|
||||||
\__(
|
\__(
|
||||||
'If you have problems using this plugin, please check the <a href="%s">Site Health</a> page to ensure that your site is compatible and/or use the "Help" tab (in the top right of the settings pages).',
|
'If you have problems using this plugin, please check the <a href="%s">Site Health</a> to ensure that your site is compatible and/or use the "Help" tab (in the top right of the settings pages).',
|
||||||
'activitypub'
|
'activitypub'
|
||||||
),
|
),
|
||||||
\esc_url_raw( admin_url( 'site-health.php' ) )
|
\esc_url_raw( admin_url( 'site-health.php' ) )
|
||||||
|
|
|
@ -17,8 +17,7 @@ class Test_Activitypub_Activity extends WP_UnitTestCase {
|
||||||
10
|
10
|
||||||
);
|
);
|
||||||
|
|
||||||
$wp_post = get_post( $post );
|
$activitypub_post = \Activitypub\Transformer\Post::transform( get_post( $post ) )->to_object();
|
||||||
$activitypub_post = \Activitypub\Transformer\Transformers_Manager::instance()->get_transformer( $post )->to_object();
|
|
||||||
|
|
||||||
$activitypub_activity = new \Activitypub\Activity\Activity();
|
$activitypub_activity = new \Activitypub\Activity\Activity();
|
||||||
$activitypub_activity->set_type( 'Create' );
|
$activitypub_activity->set_type( 'Create' );
|
||||||
|
|
|
@ -35,15 +35,14 @@ ENDPRE;
|
||||||
array( 'test', 'test' ),
|
array( 'test', 'test' ),
|
||||||
array( '#test', '#test' ),
|
array( '#test', '#test' ),
|
||||||
array( 'hallo #test test', 'hallo #test test' ),
|
array( 'hallo #test test', 'hallo #test test' ),
|
||||||
array( 'hallo #object test', 'hallo <a rel="tag" class="hashtag u-tag u-category" href="%s">#object</a> test' ),
|
array( 'hallo #object test', 'hallo <a rel="tag" class="u-tag u-category" href="%s">#object</a> test' ),
|
||||||
array( '#object test', '<a rel="tag" class="hashtag u-tag u-category" href="%s">#object</a> test' ),
|
array( '#object test', '<a rel="tag" class="u-tag u-category" href="%s">#object</a> test' ),
|
||||||
array( 'hallo <a href="http://test.test/#object">test</a> test', 'hallo <a href="http://test.test/#object">test</a> test' ),
|
array( 'hallo <a href="http://test.test/#object">test</a> test', 'hallo <a href="http://test.test/#object">test</a> test' ),
|
||||||
array( 'hallo <a href="http://test.test/#object">#test</a> test', 'hallo <a href="http://test.test/#object">#test</a> test' ),
|
array( 'hallo <a href="http://test.test/#object">#test</a> test', 'hallo <a href="http://test.test/#object">#test</a> test' ),
|
||||||
array( '<div>hallo #object test</div>', '<div>hallo <a rel="tag" class="hashtag u-tag u-category" href="%s">#object</a> test</div>' ),
|
array( '<div>hallo #object test</div>', '<div>hallo <a rel="tag" class="u-tag u-category" href="%s">#object</a> test</div>' ),
|
||||||
array( '<div>hallo #object</div>', '<div>hallo <a rel="tag" class="hashtag u-tag u-category" href="%s">#object</a></div>' ),
|
array( '<div>hallo #object</div>', '<div>hallo <a rel="tag" class="u-tag u-category" href="%s">#object</a></div>' ),
|
||||||
array( '<div>#object</div>', '<div><a rel="tag" class="hashtag u-tag u-category" href="%s">#object</a></div>' ),
|
array( '<div>#object</div>', '<div>#object</div>' ),
|
||||||
array( '<a>#object</a>', '<a>#object</a>' ),
|
array( '<a>#object</a>', '<a>#object</a>' ),
|
||||||
array( '<!-- #object -->', '<!-- #object -->' ),
|
|
||||||
array( '<div style="color: #ccc;">object</a>', '<div style="color: #ccc;">object</a>' ),
|
array( '<div style="color: #ccc;">object</a>', '<div style="color: #ccc;">object</a>' ),
|
||||||
array( $code, $code ),
|
array( $code, $code ),
|
||||||
array( $style, $style ),
|
array( $style, $style ),
|
||||||
|
|