| @@ -7,9 +7,8 @@ | ||
| 7 | 7 | |
| 8 | 8 | namespace Activitypub\Collection; |
| 9 | 9 | |
| 10 | 10 | use Activitypub\Link; |
| 11 | -use Activitypub\Sanitize; | |
| 12 | 11 | |
| 13 | 12 | use function Activitypub\site_supports_blocks; |
| 14 | 13 | |
| 15 | 14 | /** |
| @@ -39,19 +38,8 @@ | ||
| 39 | 38 | if ( ! $is_blog ) { |
| 40 | 39 | $args['author'] = $user_id; |
| 41 | 40 | } |
| 42 | 41 | |
| 43 | - // Limit to 20 fields to prevent response size issues. | |
| 44 | - if ( ! \is_admin() ) { | |
| 45 | - /** | |
| 46 | - * Filters the number of extra fields to retrieve for an ActivityPub actor. | |
| 47 | - * | |
| 48 | - * @param int $limit The number of extra fields to retrieve. Default 20. | |
| 49 | - */ | |
| 50 | - $args['posts_per_page'] = \apply_filters( 'activitypub_actor_extra_fields_limit', 20 ); | |
| 51 | - $args['nopaging'] = false; | |
| 52 | - } | |
| 53 | - | |
| 54 | 42 | $query = new \WP_Query( $args ); |
| 55 | 43 | $fields = $query->posts ?? array(); |
| 56 | 44 | |
| 57 | 45 | /** |
| @@ -62,9 +50,9 @@ | ||
| 62 | 50 | * |
| 63 | 51 | * @param \WP_Post[] $fields Array of WP_Post objects representing the extra fields. |
| 64 | 52 | * @param int $user_id The ID of the user whose fields are being retrieved. |
| 65 | 53 | */ |
| 66 | - return \apply_filters( 'activitypub_get_actor_extra_fields', $fields, $user_id ); | |
| 54 | + return apply_filters( 'activitypub_get_actor_extra_fields', $fields, $user_id ); | |
| 67 | 55 | } |
| 68 | 56 | |
| 69 | 57 | /** |
| 70 | 58 | * Get formatted content for an extra field. |
| @@ -81,11 +69,12 @@ | ||
| 81 | 69 | } |
| 82 | 70 | $content = \wptexturize( $content ); |
| 83 | 71 | $content = \wp_filter_content_tags( $content ); |
| 84 | 72 | |
| 73 | + // Replace script and style elements. | |
| 74 | + $content = \preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $content ); | |
| 85 | 75 | $content = \strip_shortcodes( $content ); |
| 86 | - $content = Sanitize::clean_html( $content ); | |
| 87 | - $content = Sanitize::strip_whitespace( $content ); | |
| 76 | + $content = \trim( \preg_replace( '/[\n\r\t]/', '', $content ) ); | |
| 88 | 77 | |
| 89 | 78 | /** |
| 90 | 79 | * Filters the content of an extra field. |
| 91 | 80 | * |
| @@ -106,14 +95,17 @@ | ||
| 106 | 95 | $attachments = array(); |
| 107 | 96 | \add_filter( 'activitypub_link_rel', array( self::class, 'add_rel_me' ) ); |
| 108 | 97 | |
| 109 | 98 | foreach ( $fields as $post ) { |
| 110 | - $title = \html_entity_decode( \get_the_title( $post ), \ENT_QUOTES, 'UTF-8' ); | |
| 111 | 99 | $content = self::get_formatted_content( $post ); |
| 112 | 100 | $attachments[] = array( |
| 113 | 101 | 'type' => 'PropertyValue', |
| 114 | - 'name' => $title, | |
| 115 | - 'value' => \html_entity_decode( $content, \ENT_QUOTES, 'UTF-8' ), | |
| 102 | + 'name' => \get_the_title( $post ), | |
| 103 | + 'value' => \html_entity_decode( | |
| 104 | + $content, | |
| 105 | + \ENT_QUOTES, | |
| 106 | + 'UTF-8' | |
| 107 | + ), | |
| 116 | 108 | ); |
| 117 | 109 | |
| 118 | 110 | $attachment = false; |
| 119 | 111 | |
| @@ -130,10 +122,10 @@ | ||
| 130 | 122 | |
| 131 | 123 | if ( 'A' === $tags->get_tag() ) { |
| 132 | 124 | $attachment = array( |
| 133 | 125 | 'type' => 'Link', |
| 134 | - 'name' => $title, | |
| 135 | - 'href' => \esc_url_raw( $tags->get_attribute( 'href' ) ), | |
| 126 | + 'name' => \get_the_title( $post ), | |
| 127 | + 'href' => \esc_url( $tags->get_attribute( 'href' ) ), | |
| 136 | 128 | ); |
| 137 | 129 | |
| 138 | 130 | $rel = $tags->get_attribute( 'rel' ); |
| 139 | 131 | |
| @@ -145,10 +137,14 @@ | ||
| 145 | 137 | |
| 146 | 138 | if ( ! $attachment ) { |
| 147 | 139 | $attachment = array( |
| 148 | 140 | 'type' => 'Note', |
| 149 | - 'name' => $title, | |
| 150 | - 'content' => \html_entity_decode( $content, \ENT_QUOTES, 'UTF-8' ), | |
| 141 | + 'name' => \get_the_title( $post ), | |
| 142 | + 'content' => \html_entity_decode( | |
| 143 | + $content, | |
| 144 | + \ENT_QUOTES, | |
| 145 | + 'UTF-8' | |
| 146 | + ), | |
| 151 | 147 | ); |
| 152 | 148 | } |
| 153 | 149 | |
| 154 | 150 | $attachments[] = $attachment; |
| @@ -216,9 +212,9 @@ | ||
| 216 | 212 | } |
| 217 | 213 | |
| 218 | 214 | \add_filter( |
| 219 | 215 | 'activitypub_link_rel', |
| 220 | - static function ( $rel ) { | |
| 216 | + function ( $rel ) { | |
| 221 | 217 | $rel .= ' me'; |
| 222 | 218 | |
| 223 | 219 | return $rel; |
| 224 | 220 | } |
| @@ -256,10 +252,10 @@ | ||
| 256 | 252 | 'menu_order' => $menu_order, |
| 257 | 253 | ); |
| 258 | 254 | |
| 259 | 255 | $menu_order += 10; |
| 260 | - $extra_field_id = \wp_insert_post( $extra_field ); | |
| 261 | - $extra_fields[] = \get_post( $extra_field_id ); | |
| 256 | + $extra_field_id = wp_insert_post( $extra_field ); | |
| 257 | + $extra_fields[] = get_post( $extra_field_id ); | |
| 262 | 258 | } |
| 263 | 259 | |
| 264 | 260 | $is_blog |
| 265 | 261 | ? \update_option( 'activitypub_default_extra_fields', true ) |