diff --git a/build/editor-plugin/plugin.asset.php b/build/editor-plugin/plugin.asset.php index 67a3f181..03b3b129 100644 --- a/build/editor-plugin/plugin.asset.php +++ b/build/editor-plugin/plugin.asset.php @@ -1 +1 @@ - array('react', 'wp-components', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-i18n', 'wp-plugins'), 'version' => '88603987940fec29730d'); + array('react', 'wp-components', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-primitives'), 'version' => 'e2a6a535ba308e4dd089'); diff --git a/build/editor-plugin/plugin.js b/build/editor-plugin/plugin.js index c16cd66e..7be5e6c8 100644 --- a/build/editor-plugin/plugin.js +++ b/build/editor-plugin/plugin.js @@ -1 +1 @@ -(()=>{"use strict";const t=window.React,e=window.wp.editor,n=window.wp.plugins,i=window.wp.components,o=window.wp.data,a=window.wp.coreData,r=window.wp.i18n;(0,n.registerPlugin)("activitypub-editor-plugin",{render:()=>{const n=(0,o.useSelect)((t=>t("core/editor").getCurrentPostType()),[]),[w,c]=(0,a.useEntityProp)("postType",n,"meta");return(0,t.createElement)(e.PluginDocumentSettingPanel,{name:"activitypub",title:(0,r.__)("Fediverse","activitypub")},(0,t.createElement)(i.TextControl,{label:(0,r.__)("Content Warning","activitypub"),value:w?.activitypub_content_warning,onChange:t=>{c({...w,activitypub_content_warning:t})},placeholder:(0,r.__)("Optional content warning","activitypub")}))}})})(); \ No newline at end of file +(()=>{"use strict";var e={20:(e,t,i)=>{var n=i(609),o=Symbol.for("react.element"),r=(Symbol.for("react.fragment"),Object.prototype.hasOwnProperty),l=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a={key:!0,ref:!0,__self:!0,__source:!0};t.jsx=function(e,t,i){var n,c={},s=null,p=null;for(n in void 0!==i&&(s=""+i),void 0!==t.key&&(s=""+t.key),void 0!==t.ref&&(p=t.ref),t)r.call(t,n)&&!a.hasOwnProperty(n)&&(c[n]=t[n]);if(e&&e.defaultProps)for(n in t=e.defaultProps)void 0===c[n]&&(c[n]=t[n]);return{$$typeof:o,type:e,key:s,ref:p,props:c,_owner:l.current}}},848:(e,t,i)=>{e.exports=i(20)},609:e=>{e.exports=window.React}},t={};function i(n){var o=t[n];if(void 0!==o)return o.exports;var r=t[n]={exports:{}};return e[n](r,r.exports,i),r.exports}var n=i(609);const o=window.wp.editor,r=window.wp.plugins,l=window.wp.components,a=window.wp.element,c=(0,a.forwardRef)((function({icon:e,size:t=24,...i},n){return(0,a.cloneElement)(e,{width:t,height:t,...i,ref:n})})),s=window.wp.primitives;var p=i(848);const u=(0,p.jsx)(s.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,p.jsx)(s.Path,{d:"M12 3.3c-4.8 0-8.8 3.9-8.8 8.8 0 4.8 3.9 8.8 8.8 8.8 4.8 0 8.8-3.9 8.8-8.8s-4-8.8-8.8-8.8zm6.5 5.5h-2.6C15.4 7.3 14.8 6 14 5c2 .6 3.6 2 4.5 3.8zm.7 3.2c0 .6-.1 1.2-.2 1.8h-2.9c.1-.6.1-1.2.1-1.8s-.1-1.2-.1-1.8H19c.2.6.2 1.2.2 1.8zM12 18.7c-1-.7-1.8-1.9-2.3-3.5h4.6c-.5 1.6-1.3 2.9-2.3 3.5zm-2.6-4.9c-.1-.6-.1-1.1-.1-1.8 0-.6.1-1.2.1-1.8h5.2c.1.6.1 1.1.1 1.8s-.1 1.2-.1 1.8H9.4zM4.8 12c0-.6.1-1.2.2-1.8h2.9c-.1.6-.1 1.2-.1 1.8 0 .6.1 1.2.1 1.8H5c-.2-.6-.2-1.2-.2-1.8zM12 5.3c1 .7 1.8 1.9 2.3 3.5H9.7c.5-1.6 1.3-2.9 2.3-3.5zM10 5c-.8 1-1.4 2.3-1.8 3.8H5.5C6.4 7 8 5.6 10 5zM5.5 15.3h2.6c.4 1.5 1 2.8 1.8 3.7-1.8-.6-3.5-2-4.4-3.7zM14 19c.8-1 1.4-2.2 1.8-3.7h2.6C17.6 17 16 18.4 14 19z"})}),w=(0,p.jsx)(s.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,p.jsx)(s.Path,{d:"M4.67 10.664s-2.09 1.11-2.917 1.582l.494.87 1.608-.914.002.002c.343.502.86 1.17 1.563 1.84.348.33.742.663 1.185.976L5.57 16.744l.858.515 1.02-1.701a9.1 9.1 0 0 0 4.051 1.18V19h1v-2.263a9.1 9.1 0 0 0 4.05-1.18l1.021 1.7.858-.514-1.034-1.723c.442-.313.837-.646 1.184-.977.703-.669 1.22-1.337 1.563-1.839l.002-.003 1.61.914.493-.87c-1.75-.994-2.918-1.58-2.918-1.58l-.003.005a8.29 8.29 0 0 1-.422.689 10.097 10.097 0 0 1-1.36 1.598c-1.218 1.16-3.042 2.293-5.544 2.293-2.503 0-4.327-1.132-5.546-2.293a10.099 10.099 0 0 1-1.359-1.599 8.267 8.267 0 0 1-.422-.689l-.003-.005Z"})}),v=(0,p.jsx)(s.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,p.jsx)(s.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M12 18.5A6.5 6.5 0 0 1 6.93 7.931l9.139 9.138A6.473 6.473 0 0 1 12 18.5Zm5.123-2.498a6.5 6.5 0 0 0-9.124-9.124l9.124 9.124ZM4 12a8 8 0 1 1 16 0 8 8 0 0 1-16 0Z"})}),_=window.wp.data,d=window.wp.coreData,y=window.wp.i18n;(0,r.registerPlugin)("activitypub-editor-plugin",{render:()=>{const e=(0,_.useSelect)((e=>e("core/editor").getCurrentPostType()),[]),[t,i]=(0,d.useEntityProp)("postType",e,"meta"),r={verticalAlign:"middle",gap:"4px",justifyContent:"start",display:"inline-flex",alignItems:"center"},a=(e,t)=>(0,n.createElement)(l.__experimentalText,{style:r},(0,n.createElement)(c,{icon:e}),t);return(0,n.createElement)(o.PluginDocumentSettingPanel,{name:"activitypub",title:(0,y.__)("⁂ Fediverse","activitypub")},(0,n.createElement)(l.TextControl,{label:(0,y.__)("Content Warning","activitypub"),value:t?.activitypub_content_warning,onChange:e=>{i({...t,activitypub_content_warning:e})},placeholder:(0,y.__)("Optional content warning","activitypub")}),(0,n.createElement)(l.RadioControl,{label:(0,y.__)("Visibility","activitypub"),help:(0,y.__)("This adjusts the visibility of a post in the fediverse, but note that it won't affect how the post appears on the blog.","activitypub"),selected:t.activitypub_content_visibility?t.activitypub_content_visibility:"public",options:[{label:a(u,(0,y.__)("Public","activitypub")),value:"public"},{label:a(w,(0,y.__)("Quiet public","activitypub")),value:"followers"},{label:a(v,(0,y.__)("Do not federate","activitypub")),value:"no"}],onChange:e=>{i({...t,activitypub_content_visibility:e})},className:"activitypub-visibility"}))}})})(); \ No newline at end of file diff --git a/includes/class-activitypub.php b/includes/class-activitypub.php index c85a5fb1..35978e66 100644 --- a/includes/class-activitypub.php +++ b/includes/class-activitypub.php @@ -98,7 +98,7 @@ public static function render_json_template( $template ) { $json_template = ACTIVITYPUB_PLUGIN_DIR . '/templates/user-json.php'; } elseif ( is_comment() ) { $json_template = ACTIVITYPUB_PLUGIN_DIR . '/templates/comment-json.php'; - } elseif ( \is_singular() ) { + } elseif ( \is_singular() && ! is_post_disabled( \get_the_ID() ) ) { $json_template = ACTIVITYPUB_PLUGIN_DIR . '/templates/post-json.php'; } elseif ( \is_home() && ! is_user_type_disabled( 'blog' ) ) { $json_template = ACTIVITYPUB_PLUGIN_DIR . '/templates/blog-json.php'; diff --git a/includes/class-blocks.php b/includes/class-blocks.php index c42d2fc6..d4abb796 100644 --- a/includes/class-blocks.php +++ b/includes/class-blocks.php @@ -45,6 +45,16 @@ public static function register_postmeta() { 'sanitize_callback' => 'sanitize_text_field', ) ); + \register_post_meta( + $post_type, + 'activitypub_content_visibility', + array( + 'show_in_rest' => true, + 'single' => true, + 'type' => 'string', + 'sanitize_callback' => 'sanitize_text_field', + ) + ); } } diff --git a/includes/class-scheduler.php b/includes/class-scheduler.php index 0774f296..1cc93cbc 100644 --- a/includes/class-scheduler.php +++ b/includes/class-scheduler.php @@ -113,7 +113,7 @@ public static function deregister_schedules() { public static function schedule_post_activity( $new_status, $old_status, $post ) { $post = get_post( $post ); - if ( ! $post ) { + if ( ! $post || is_post_disabled( $post ) ) { return; } diff --git a/includes/functions.php b/includes/functions.php index 27f50e96..96632c13 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -400,6 +400,31 @@ function is_activitypub_request() { return false; } +/** + * Check if a post is disabled for ActivityPub. + * + * @param mixed $post The post object or ID. + * + * @return boolean True if the post is disabled, false otherwise. + */ +function is_post_disabled( $post ) { + $post = \get_post( $post ); + $return = false; + $visibility = \get_post_meta( $post->ID, 'activitypub_content_visibility', true ); + + if ( 'no' === $visibility ) { + $return = true; + } + + /* + * Allow plugins to disable posts for ActivityPub. + * + * @param boolean $return True if the post is disabled, false otherwise. + * @param \WP_Post $post The post object. + */ + return \apply_filters( 'activitypub_is_post_disabled', $return, $post ); +} + /** * This function checks if a user is disabled for ActivityPub. * diff --git a/includes/transformer/class-post.php b/includes/transformer/class-post.php index 85a8b809..fa1c1c14 100644 --- a/includes/transformer/class-post.php +++ b/includes/transformer/class-post.php @@ -77,6 +77,12 @@ public function to_object() { $object->set_summary_map( null ); } + // Change order if visibility is "Quiet public". + if ( 'followers' === \get_post_meta( $post->ID, 'activitypub_content_visibility', true ) ) { + $object->set_to( $this->get_cc() ); + $object->set_cc( $this->get_to() ); + } + return $object; } @@ -680,6 +686,19 @@ protected function get_type() { return $object_type; } + /** + * Returns the recipient of the post. + * + * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-to + * + * @return array The recipient URLs of the post. + */ + public function get_to() { + return array( + 'https://www.w3.org/ns/activitystreams#Public', + ); + } + /** * Returns a list of Mentions, used in the Post. * @@ -688,7 +707,9 @@ protected function get_type() { * @return array The list of Mentions. */ protected function get_cc() { - $cc = array(); + $cc = array( + $this->get_actor_object()->get_followers(), + ); $mentions = $this->get_mentions(); if ( $mentions ) { @@ -946,20 +967,6 @@ public function get_in_reply_to() { return null; } - /** - * Returns the recipient of the post. - * - * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-to - * - * @return array The recipient URLs of the post. - */ - public function get_to() { - return array( - 'https://www.w3.org/ns/activitystreams#Public', - $this->get_actor_object()->get_followers(), - ); - } - /** * Returns the published date of the post. * diff --git a/src/editor-plugin/block.json b/src/editor-plugin/block.json index a8d510c7..22cf5cc1 100644 --- a/src/editor-plugin/block.json +++ b/src/editor-plugin/block.json @@ -6,4 +6,4 @@ "keywords": [ ], "editorScript": "file:./plugin.js" -} \ No newline at end of file +} diff --git a/src/editor-plugin/plugin.js b/src/editor-plugin/plugin.js index 7e95dcda..d27cb4a1 100644 --- a/src/editor-plugin/plugin.js +++ b/src/editor-plugin/plugin.js @@ -1,6 +1,7 @@ import { PluginDocumentSettingPanel } from '@wordpress/editor'; import { registerPlugin } from '@wordpress/plugins'; -import { TextControl } from '@wordpress/components'; +import { TextControl, RadioControl, __experimentalText as Text } from '@wordpress/components'; +import { Icon, notAllowed, globe, unseen } from '@wordpress/icons'; import { useSelect } from '@wordpress/data'; import { useEntityProp } from '@wordpress/core-data'; import { __ } from '@wordpress/i18n'; @@ -13,10 +14,30 @@ const EditorPlugin = () => { ); const [ meta, setMeta ] = useEntityProp( 'postType', postType, 'meta' ); + const style = { + verticalAlign: 'middle', + }; + + const labelStyling = { + verticalAlign: "middle", + gap: "4px", + justifyContent: + "start", display: + "inline-flex", + alignItems: "center" + } + + const labelWithIcon = ( icon, text ) => ( + + + {text} + + ); + return ( { } } placeholder={ __( 'Optional content warning', 'activitypub' ) } /> + { + setMeta( { ...meta, activitypub_content_visibility: value } ); + } } + className="activitypub-visibility" + /> ); } -registerPlugin( 'activitypub-editor-plugin', { render: EditorPlugin } ); \ No newline at end of file +registerPlugin( 'activitypub-editor-plugin', { render: EditorPlugin } );