diff --git a/CHANGELOG.md b/CHANGELOG.md index 754484223..678b2abf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Dev - XXXX-XX-XX + +### Improved + +* Outsource Constants to a separate file + ## 4.2.1 - 2024-11-20 ### Added diff --git a/README.md b/README.md index ec4d33c29..d2c3e37bf 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,10 @@ For reasons of data protection, it is not possible to see the followers of other ## Changelog ## +### Dev ### + +* Improved: Outsource Constants to a separate file + ### 4.2.1 ### * Added: Mastodon Apps status provider diff --git a/activitypub.php b/activitypub.php index d111e3da5..7d7a13693 100644 --- a/activitypub.php +++ b/activitypub.php @@ -19,79 +19,11 @@ use WP_CLI; -require_once __DIR__ . '/includes/compat.php'; -require_once __DIR__ . '/includes/functions.php'; - \define( 'ACTIVITYPUB_PLUGIN_VERSION', '4.2.1' ); -/** - * Initialize the plugin constants. - */ -\defined( 'ACTIVITYPUB_REST_NAMESPACE' ) || \define( 'ACTIVITYPUB_REST_NAMESPACE', 'activitypub/1.0' ); -\defined( 'ACTIVITYPUB_EXCERPT_LENGTH' ) || \define( 'ACTIVITYPUB_EXCERPT_LENGTH', 400 ); -\defined( 'ACTIVITYPUB_NOTE_LENGTH' ) || \define( 'ACTIVITYPUB_NOTE_LENGTH', 400 ); -\defined( 'ACTIVITYPUB_SHOW_PLUGIN_RECOMMENDATIONS' ) || \define( 'ACTIVITYPUB_SHOW_PLUGIN_RECOMMENDATIONS', true ); -\defined( 'ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS' ) || \define( 'ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS', 3 ); -\defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || \define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(?:(?<=\s)|(?<=
)|(?<=
)|^)#([A-Za-z0-9_]+)(?:(?=\s|[[:punct:]]|$))' );
-\defined( 'ACTIVITYPUB_USERNAME_REGEXP' ) || \define( 'ACTIVITYPUB_USERNAME_REGEXP', '(?:([A-Za-z0-9\._-]+)@((?:[A-Za-z0-9_-]+\.)+[A-Za-z]+))' );
-\defined( 'ACTIVITYPUB_URL_REGEXP' ) || \define( 'ACTIVITYPUB_URL_REGEXP', '(https?:|www\.)\S+[\w\/]' );
-\defined( 'ACTIVITYPUB_CUSTOM_POST_CONTENT' ) || \define( 'ACTIVITYPUB_CUSTOM_POST_CONTENT', "[ap_title type=\"html\"]\n\n[ap_content]\n\n[ap_hashtags]" );
-\defined( 'ACTIVITYPUB_AUTHORIZED_FETCH' ) || \define( 'ACTIVITYPUB_AUTHORIZED_FETCH', false );
-\defined( 'ACTIVITYPUB_DISABLE_REWRITES' ) || \define( 'ACTIVITYPUB_DISABLE_REWRITES', false );
-\defined( 'ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS' ) || \define( 'ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS', false );
-// Disable reactions like `Like` and `Announce` by default.
-\defined( 'ACTIVITYPUB_DISABLE_REACTIONS' ) || \define( 'ACTIVITYPUB_DISABLE_REACTIONS', true );
-\defined( 'ACTIVITYPUB_DISABLE_OUTGOING_INTERACTIONS' ) || \define( 'ACTIVITYPUB_DISABLE_OUTGOING_INTERACTIONS', false );
-\defined( 'ACTIVITYPUB_SHARED_INBOX_FEATURE' ) || \define( 'ACTIVITYPUB_SHARED_INBOX_FEATURE', false );
-\defined( 'ACTIVITYPUB_SEND_VARY_HEADER' ) || \define( 'ACTIVITYPUB_SEND_VARY_HEADER', false );
-\defined( 'ACTIVITYPUB_DEFAULT_OBJECT_TYPE' ) || \define( 'ACTIVITYPUB_DEFAULT_OBJECT_TYPE', 'wordpress-post-format' );
-
-/*
- * Mastodon HTML sanitizer.
- *
- * @see https://docs.joinmastodon.org/spec/activitypub/#sanitization
- */
-\define(
- 'ACTIVITYPUB_MASTODON_HTML_SANITIZER',
- array(
- 'p' => array(),
- 'span' => array( 'class' ),
- 'br' => array(),
- 'a' => array( 'href', 'rel', 'class' ),
- 'del' => array(),
- 'pre' => array(),
- 'code' => array(),
- 'em' => array(),
- 'strong' => array(),
- 'b' => array(),
- 'i' => array(),
- 'u' => array(),
- 'ul' => array(),
- 'ol' => array( 'start', 'reversed' ),
- 'li' => array( 'value' ),
- 'blockquote' => array(),
- 'h1' => array(),
- 'h2' => array(),
- 'h3' => array(),
- 'h4' => array(),
- )
-);
-
-// Define Actor-Modes for the plugin.
-\define( 'ACTIVITYPUB_ACTOR_MODE', 'actor' );
-\define( 'ACTIVITYPUB_BLOG_MODE', 'blog' );
-\define( 'ACTIVITYPUB_ACTOR_AND_BLOG_MODE', 'actor_blog' );
-
-// Post visibility constants.
-\define( 'ACTIVITYPUB_CONTENT_VISIBILITY_PUBLIC', '' );
-\define( 'ACTIVITYPUB_CONTENT_VISIBILITY_QUIET_PUBLIC', 'quiet_public' );
-\define( 'ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL', 'local' );
-
-// Plugin related constants.
-\define( 'ACTIVITYPUB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
-\define( 'ACTIVITYPUB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
-\define( 'ACTIVITYPUB_PLUGIN_FILE', ACTIVITYPUB_PLUGIN_DIR . basename( __FILE__ ) );
-\define( 'ACTIVITYPUB_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
+require_once __DIR__ . '/includes/compat.php';
+require_once __DIR__ . '/includes/functions.php';
+require_once __DIR__ . '/includes/constants.php';
/**
* Initialize REST routes.
diff --git a/includes/constants.php b/includes/constants.php
new file mode 100644
index 000000000..a6305f150
--- /dev/null
+++ b/includes/constants.php
@@ -0,0 +1,76 @@
+)|(?<=
)|^)#([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_URL_REGEXP' ) || \define( 'ACTIVITYPUB_URL_REGEXP', '(https?:|www\.)\S+[\w\/]' );
+\defined( 'ACTIVITYPUB_CUSTOM_POST_CONTENT' ) || \define( 'ACTIVITYPUB_CUSTOM_POST_CONTENT', "[ap_title type=\"html\"]\n\n[ap_content]\n\n[ap_hashtags]" );
+\defined( 'ACTIVITYPUB_AUTHORIZED_FETCH' ) || \define( 'ACTIVITYPUB_AUTHORIZED_FETCH', false );
+\defined( 'ACTIVITYPUB_DISABLE_REWRITES' ) || \define( 'ACTIVITYPUB_DISABLE_REWRITES', false );
+\defined( 'ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS' ) || \define( 'ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS', false );
+// Disable reactions like `Like` and `Announce` by default.
+\defined( 'ACTIVITYPUB_DISABLE_REACTIONS' ) || \define( 'ACTIVITYPUB_DISABLE_REACTIONS', true );
+\defined( 'ACTIVITYPUB_DISABLE_OUTGOING_INTERACTIONS' ) || \define( 'ACTIVITYPUB_DISABLE_OUTGOING_INTERACTIONS', false );
+\defined( 'ACTIVITYPUB_SHARED_INBOX_FEATURE' ) || \define( 'ACTIVITYPUB_SHARED_INBOX_FEATURE', false );
+\defined( 'ACTIVITYPUB_SEND_VARY_HEADER' ) || \define( 'ACTIVITYPUB_SEND_VARY_HEADER', false );
+\defined( 'ACTIVITYPUB_DEFAULT_OBJECT_TYPE' ) || \define( 'ACTIVITYPUB_DEFAULT_OBJECT_TYPE', 'wordpress-post-format' );
+
+// The following constants are invariable and define values used throughout the plugin.
+
+/*
+ * Mastodon HTML sanitizer.
+ *
+ * @see https://docs.joinmastodon.org/spec/activitypub/#sanitization
+ */
+\define(
+ 'ACTIVITYPUB_MASTODON_HTML_SANITIZER',
+ array(
+ 'p' => array(),
+ 'span' => array( 'class' ),
+ 'br' => array(),
+ 'a' => array( 'href', 'rel', 'class' ),
+ 'del' => array(),
+ 'pre' => array(),
+ 'code' => array(),
+ 'em' => array(),
+ 'strong' => array(),
+ 'b' => array(),
+ 'i' => array(),
+ 'u' => array(),
+ 'ul' => array(),
+ 'ol' => array( 'start', 'reversed' ),
+ 'li' => array( 'value' ),
+ 'blockquote' => array(),
+ 'h1' => array(),
+ 'h2' => array(),
+ 'h3' => array(),
+ 'h4' => array(),
+ )
+);
+
+// Define Actor-Modes for the plugin.
+\define( 'ACTIVITYPUB_ACTOR_MODE', 'actor' );
+\define( 'ACTIVITYPUB_BLOG_MODE', 'blog' );
+\define( 'ACTIVITYPUB_ACTOR_AND_BLOG_MODE', 'actor_blog' );
+
+// Post visibility constants.
+\define( 'ACTIVITYPUB_CONTENT_VISIBILITY_PUBLIC', '' );
+\define( 'ACTIVITYPUB_CONTENT_VISIBILITY_QUIET_PUBLIC', 'quiet_public' );
+\define( 'ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL', 'local' );
+
+// Plugin related constants.
+\define( 'ACTIVITYPUB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
+\define( 'ACTIVITYPUB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
+\define( 'ACTIVITYPUB_PLUGIN_FILE', ACTIVITYPUB_PLUGIN_DIR . basename( __FILE__ ) );
+\define( 'ACTIVITYPUB_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
diff --git a/readme.txt b/readme.txt
index 87b4b5364..bebc20691 100644
--- a/readme.txt
+++ b/readme.txt
@@ -150,6 +150,10 @@ For reasons of data protection, it is not possible to see the followers of other
== Changelog ==
+= Dev =
+
+* Improved: Outsource Constants to a separate file
+
= 4.2.1 =
* Added: Mastodon Apps status provider