diff --git a/activitypub.php b/activitypub.php index 6ae9dbc..f02c054 100644 --- a/activitypub.php +++ b/activitypub.php @@ -117,6 +117,8 @@ function add_rewrite_rules() { \add_rewrite_rule( '^.well-known/nodeinfo', 'index.php?rest_route=/activitypub/1.0/nodeinfo/discovery', 'top' ); \add_rewrite_rule( '^.well-known/x-nodeinfo2', 'index.php?rest_route=/activitypub/1.0/nodeinfo2', 'top' ); } + + \add_rewrite_endpoint( 'activitypub', EP_AUTHORS | EP_PERMALINK | EP_PAGES ); } \add_action( 'init', '\Activitypub\add_rewrite_rules', 1 ); diff --git a/assets/css/activitypub-admin.css b/assets/css/activitypub-admin.css index a6cc390..cd1808c 100644 --- a/assets/css/activitypub-admin.css +++ b/assets/css/activitypub-admin.css @@ -1,6 +1,7 @@ .settings_page_activitypub .notice { max-width: 800px; - margin: 0 auto; + margin: auto; + margin-top: 10px; } .activitypub-settings-header { diff --git a/includes/class-activitypub.php b/includes/class-activitypub.php index ea3532a..c04aedc 100644 --- a/includes/class-activitypub.php +++ b/includes/class-activitypub.php @@ -13,7 +13,6 @@ class Activitypub { public static function init() { \add_filter( 'template_include', array( '\Activitypub\Activitypub', 'render_json_template' ), 99 ); \add_filter( 'query_vars', array( '\Activitypub\Activitypub', 'add_query_vars' ) ); - \add_action( 'init', array( '\Activitypub\Activitypub', 'add_rewrite_endpoint' ) ); \add_filter( 'pre_get_avatar_data', array( '\Activitypub\Activitypub', 'pre_get_avatar_data' ), 11, 2 ); // Add support for ActivityPub to custom post types @@ -23,7 +22,7 @@ class Activitypub { \add_post_type_support( $post_type, 'activitypub' ); } - \add_action( 'transition_post_status', array( '\Activitypub\Activitypub', 'schedule_post_activity' ), 10, 3 ); + \add_action( 'transition_post_status', array( '\Activitypub\Activitypub', 'schedule_post_activity' ), 33, 3 ); \add_action( 'wp_trash_post', array( '\Activitypub\Activitypub', 'trash_post' ), 1 ); \add_action( 'untrash_post', array( '\Activitypub\Activitypub', 'untrash_post' ), 1 ); } @@ -96,13 +95,6 @@ class Activitypub { return $vars; } - /** - * Add our rewrite endpoint to permalinks and pages. - */ - public static function add_rewrite_endpoint() { - \add_rewrite_endpoint( 'activitypub', EP_AUTHORS | EP_PERMALINK | EP_PAGES ); - } - /** * Schedule Activities. * diff --git a/includes/class-hashtag.php b/includes/class-hashtag.php index fbe2f3d..356cdb9 100644 --- a/includes/class-hashtag.php +++ b/includes/class-hashtag.php @@ -12,8 +12,8 @@ class Hashtag { */ public static function init() { if ( '1' === \get_option( 'activitypub_use_hashtags', '1' ) ) { - \add_filter( 'wp_insert_post', array( '\Activitypub\Hashtag', 'insert_post' ), 99, 2 ); - \add_filter( 'the_content', array( '\Activitypub\Hashtag', 'the_content' ), 99, 2 ); + \add_filter( 'wp_insert_post', array( '\Activitypub\Hashtag', 'insert_post' ), 10, 2 ); + \add_filter( 'the_content', array( '\Activitypub\Hashtag', 'the_content' ), 10, 2 ); } } diff --git a/includes/help.php b/includes/help.php index 16ffbea..f84ccaf 100644 --- a/includes/help.php +++ b/includes/help.php @@ -2,45 +2,21 @@ \get_current_screen()->add_help_tab( array( - 'id' => 'fediverse', - 'title' => \__( 'Fediverse', 'activitypub' ), + 'id' => 'glossar', + 'title' => \__( 'Glossar', 'activitypub' ), 'content' => - '

' . \__( 'What is the Fediverse?', 'activitypub' ) . '

' . + '

' . \__( 'Fediverse', 'activitypub' ) . '

' . '

' . \__( 'The Fediverse is a new word made of two words: "federation" + "universe"', 'activitypub' ) . '

' . '

' . \__( 'It is a federated social network running on free open software on a myriad of computers across the globe. Many independent servers are interconnected and allow people to interact with one another. There\'s no one central site: you choose a server to register. This ensures some decentralization and sovereignty of data. Fediverse (also called Fedi) has no built-in advertisements, no tricky algorithms, no one big corporation dictating the rules. Instead we have small cozy communities of like-minded people. Welcome!', 'activitypub' ) . '

' . - '

' . \__( 'For more informations please visit fediverse.party', 'activitypub' ) . '

', - ) -); - -\get_current_screen()->add_help_tab( - array( - 'id' => 'activitypub', - 'title' => \__( 'ActivityPub', 'activitypub' ), - 'content' => - '

' . \__( 'What is ActivityPub?', 'activitypub' ) . '

' . - '

' . \__( 'ActivityPub is a decentralized social networking protocol based on the ActivityStreams 2.0 data format. ActivityPub is an official W3C recommended standard published by the W3C Social Web Working Group. It provides a client to server API for creating, updating and deleting content, as well as a federated server to server API for delivering notifications and subscribing to content.', 'activitypub' ) . '

', - ) -); - -\get_current_screen()->add_help_tab( - array( - 'id' => 'webfinger', - 'title' => \__( 'WebFinger', 'activitypub' ), - 'content' => - '

' . \__( 'What is WebFinger?', 'activitypub' ) . '

' . + '

' . \__( 'For more informations please visit fediverse.party', 'activitypub' ) . '

' . + '

' . \__( 'ActivityPub', 'activitypub' ) . '

' . + '

' . \__( 'ActivityPub is a decentralized social networking protocol based on the ActivityStreams 2.0 data format. ActivityPub is an official W3C recommended standard published by the W3C Social Web Working Group. It provides a client to server API for creating, updating and deleting content, as well as a federated server to server API for delivering notifications and subscribing to content.', 'activitypub' ) . '

' . + '

' . \__( 'WebFinger', 'activitypub' ) . '

' . '

' . \__( 'WebFinger is used to discover information about people or other entities on the Internet that are identified by a URI using standard Hypertext Transfer Protocol (HTTP) methods over a secure transport. A WebFinger resource returns a JavaScript Object Notation (JSON) object describing the entity that is queried. The JSON object is referred to as the JSON Resource Descriptor (JRD).', 'activitypub' ) . '

' . '

' . \__( 'For a person, the type of information that might be discoverable via WebFinger includes a personal profile address, identity service, telephone number, or preferred avatar. For other entities on the Internet, a WebFinger resource might return JRDs containing link relations that enable a client to discover, for example, that a printer can print in color on A4 paper, the physical location of a server, or other static information.', 'activitypub' ) . '

' . '

' . \__( 'On Mastodon [and other Plattforms], user profiles can be hosted either locally on the same website as yours, or remotely on a completely different website. The same username may be used on a different domain. Therefore, a Mastodon user\'s full mention consists of both the username and the domain, in the form @username@domain. In practical terms, @user@example.com is not the same as @user@example.org. If the domain is not included, Mastodon will try to find a local user named @username. However, in order to deliver to someone over ActivityPub, the @username@domain mention is not enough – mentions must be translated to an HTTPS URI first, so that the remote actor\'s inbox and outbox can be found. (This paragraph is copied from the Mastodon Documentation)', 'activitypub' ) . '

' . - '

' . \__( 'For more informations please visit webfinger.net', 'activitypub' ) . '

', - ) -); - -\get_current_screen()->add_help_tab( - array( - 'id' => 'nodeinfo', - 'title' => \__( 'NodeInfo', 'activitypub' ), - 'content' => - '

' . \__( 'What is NodeInfo?', 'activitypub' ) . '

' . + '

' . \__( 'For more informations please visit webfinger.net', 'activitypub' ) . '

' . + '

' . \__( 'NodeInfo', 'activitypub' ) . '

' . '

' . \__( 'NodeInfo is an effort to create a standardized way of exposing metadata about a server running one of the distributed social networks. The two key goals are being able to get better insights into the user base of distributed social networking and the ability to build tools that allow users to choose the best fitting software and server for their needs.', 'activitypub' ) . '

' . '

' . \__( 'For more informations please visit nodeinfo.diaspora.software', 'activitypub' ) . '

', ) diff --git a/includes/model/class-post.php b/includes/model/class-post.php index 919b511..c881e75 100644 --- a/includes/model/class-post.php +++ b/includes/model/class-post.php @@ -442,12 +442,62 @@ class Post { $excerpt = \apply_filters( 'the_content', $excerpt ); $excerpt = \str_replace( ']]>', ']]>', $excerpt ); - $excerpt_length = \apply_filters( 'excerpt_length', $excerpt_length ); + } + } - /** This filter is documented in wp-includes/formatting.php */ - $excerpt_more = \apply_filters( 'excerpt_more', ' [...]' ); + // Strip out any remaining tags. + $excerpt = \wp_strip_all_tags( $excerpt ); - $excerpt = \wp_trim_words( $excerpt, $excerpt_length, $excerpt_more ); + /** This filter is documented in wp-includes/formatting.php */ + $excerpt_more = \apply_filters( 'excerpt_more', ' [...]' ); + $excerpt_more_len = strlen( $excerpt_more ); + + // We now have a excerpt, but we need to check it's length, it may be longer than we want for two reasons: + // + // * The user has entered a manual excerpt which is longer that what we want. + // * No manual excerpt exists so we've used the content which might be longer than we want. + // + // Either way, let's trim it up if we need too. Also, don't forget to take into account the more indicator + // as part of the total length. + // + + // Setup a variable to hold the current excerpts length. + $current_excerpt_length = strlen( $excerpt ); + + // Setup a variable to keep track of our target length. + $target_excerpt_length = $excerpt_length - $excerpt_more_len; + + // Setup a variable to keep track of the current max length. + $current_excerpt_max = $target_excerpt_length; + + // This is a loop since we can't calculate word break the string after 'the_excpert' filter has run (we would break + // all kinds of html tags), so we have to cut the excerpt down a bit at a time until we hit our target length. + while ( $current_excerpt_length > $target_excerpt_length && $current_excerpt_max > 0 ) { + // Trim the excerpt based on wordwrap() positioning. + // Note: we're using
as the linebreak just in case there are any newlines existing in the excerpt from the user. + // There won't be any
left after we've run wp_strip_all_tags() in the code above, so they're + // safe to use here. It won't be included in the final excerpt as the substr() will trim it off. + $excerpt = substr( $excerpt, 0, strpos( wordwrap( $excerpt, $current_excerpt_max, '
' ), '
' ) ); + + // If something went wrong, or we're in a language that wordwrap() doesn't understand, + // just chop it off and don't worry about breaking in the middle of a word. + if ( strlen( $excerpt ) > $excerpt_length - $excerpt_more_len ) { + $excerpt = substr( $excerpt, 0, $current_excerpt_max ); + } + + // Add in the more indicator. + $excerpt = $excerpt . $excerpt_more; + + // Run it through the excerpt filter which will add some html tags back in. + $excerpt_filtered = apply_filters( 'the_excerpt', $excerpt ); + + // Now set the current excerpt length to this new filtered length. + $current_excerpt_length = strlen( $excerpt_filtered ); + + // Check to see if we're over the target length. + if ( $current_excerpt_length > $target_excerpt_length ) { + // If so, remove 20 characters from the current max and run the loop again. + $current_excerpt_max = $current_excerpt_max - 20; } } diff --git a/templates/settings.php b/templates/settings.php index 23242ae..498c2ac 100644 --- a/templates/settings.php +++ b/templates/settings.php @@ -150,11 +150,11 @@ $thumnail_size = $image_sizes['thumbnail']['width'] . 'x' . $image_sizes['thumbn - +

- +