PluginProbe
ActivityPub / 7.7.0
ActivityPub v7.7.0
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
← All changes | includes/transformer/class-base.php +16 -135 9.3.07.7.0 View file →
@@ -19,14 +19,8 @@
19 19 * WordPress Base Transformer.
20 20 *
21 21 * Transformers are responsible for transforming WordPress objects into different ActivityPub
22 22 * Object-Types or Activities.
23 - *
24 - * @method string|null get_content() Returns the content for the transformed item.
25 - * @method string|array|null get_icon() Returns an icon for the transformed item.
26 - * @method string|null get_id() Returns the ID for the transformed item.
27 - * @method string|null get_name() Returns the name for the transformed item.
28 - * @method string|null get_summary() Returns the summary for the transformed item.
29 23 */
30 24 abstract class Base {
31 25 /**
32 26 * The WP_Post or WP_Comment object.
@@ -39,8 +33,10 @@
39 33
40 34 /**
41 35 * The WP_Post or WP_Comment object.
42 36 *
37 + * @deprecated version 5.0.0
38 + *
43 39 * @var \WP_Post|\WP_Comment
44 40 */
45 41 protected $wp_object;
46 42
@@ -184,9 +180,9 @@
184 180 if ( ! \is_wp_error( $actor ) ) {
185 181 $followers = $actor->get_followers();
186 182 }
187 183
188 - $mentions = \array_values( $this->get_mentions() );
184 + $mentions = array_values( $this->get_mentions() );
189 185
190 186 if ( $this->get_in_reply_to() ) {
191 187 $object = Http::get_remote_object( $this->get_in_reply_to() );
192 188 if ( $object && ! \is_wp_error( $object ) && isset( $object['attributedTo'] ) ) {
@@ -225,21 +221,8 @@
225 221 return $this->get_id();
226 222 }
227 223
228 224 /**
229 - * Returns a Tombstone object for the item.
230 - *
231 - * @return Base_Object The Tombstone object.
232 - */
233 - public function to_tombstone() {
234 - $object = new Base_Object();
235 - $object->set_type( 'Tombstone' );
236 - $object->set_id( $this->to_id() );
237 -
238 - return $object;
239 - }
240 -
241 - /**
242 225 * Transforms the ActivityPub Object to an Activity
243 226 *
244 227 * @param string $type The Activity-Type.
245 228 *
@@ -277,9 +260,9 @@
277 260 * @param mixed $item The post object.
278 261 *
279 262 * @return string The filtered locale of the post.
280 263 */
281 - return \apply_filters( 'activitypub_locale', $lang, $this->item );
264 + return apply_filters( 'activitypub_locale', $lang, $this->item );
282 265 }
283 266
284 267 /**
285 268 * Returns the default media type for an Object.
@@ -346,9 +329,9 @@
346 329
347 330 foreach ( $mentions as $mention => $url ) {
348 331 $tags[] = array(
349 332 'type' => 'Mention',
350 - 'href' => \esc_url_raw( $url ),
333 + 'href' => \esc_url( $url ),
351 334 'name' => \esc_html( $mention ),
352 335 );
353 336 }
354 337
@@ -371,13 +354,13 @@
371 354 */
372 355 protected function get_mentions() {
373 356 $content = '';
374 357
375 - if ( \method_exists( $this, 'get_content' ) ) {
358 + if ( method_exists( $this, 'get_content' ) ) {
376 359 $content = $content . ' ' . $this->get_content();
377 360 }
378 361
379 - if ( \method_exists( $this, 'get_summary' ) ) {
362 + if ( method_exists( $this, 'get_summary' ) ) {
380 363 $content = $content . ' ' . $this->get_summary();
381 364 }
382 365
383 366 /**
@@ -388,9 +371,9 @@
388 371 * @param \WP_Post $post The post object.
389 372 *
390 373 * @return array The filtered mentions.
391 374 */
392 - return \apply_filters(
375 + return apply_filters(
393 376 'activitypub_extract_mentions',
394 377 array(),
395 378 $content,
396 379 $this->item
@@ -496,9 +479,9 @@
496 479
497 480 /**
498 481 * Transforms a WordPress attachment array to ActivityStreams attachment format.
499 482 *
500 - * @param array $media The WordPress attachment array with 'id', optional 'alt', and optional 'icon'.
483 + * @param array $media The WordPress attachment array with 'id' and optional 'alt'.
501 484 *
502 485 * @return array The ActivityStreams attachment array.
503 486 */
504 487 protected function transform_attachment( $media ) {
@@ -527,27 +510,21 @@
527 510
528 511 if ( $thumbnail ) {
529 512 $image = array(
530 513 'type' => 'Image',
531 - 'url' => \esc_url_raw( $thumbnail[0] ),
514 + 'url' => \esc_url( $thumbnail[0] ),
532 515 'mediaType' => \esc_attr( $mime_type ),
533 516 );
534 517
535 518 if ( ! empty( $media['alt'] ) ) {
536 - $image['name'] = \wp_strip_all_tags( $media['alt'] );
519 + $image['name'] = \html_entity_decode( \wp_strip_all_tags( $media['alt'] ), ENT_QUOTES, 'UTF-8' );
537 520 } else {
538 521 $alt = \get_post_meta( $id, '_wp_attachment_image_alt', true );
539 522 if ( $alt ) {
540 - $image['name'] = \wp_strip_all_tags( \html_entity_decode( $alt, ENT_QUOTES, 'UTF-8' ) );
523 + $image['name'] = \html_entity_decode( \wp_strip_all_tags( $alt ), ENT_QUOTES, 'UTF-8' );
541 524 }
542 525 }
543 526
544 - // Add EXIF metadata using Schema.org exifData property (FEP-ee3a).
545 - $exif_data = $this->get_exif_data( $id );
546 - if ( $exif_data ) {
547 - $image['exifData'] = $exif_data;
548 - }
549 -
550 527 $attachment = $image;
551 528 }
552 529 break;
553 530
@@ -556,9 +533,9 @@
556 533 $meta = \wp_get_attachment_metadata( $id );
557 534 $attachment = array(
558 535 'type' => \ucfirst( $media_type ),
559 536 'mediaType' => \esc_attr( $mime_type ),
560 - 'url' => \esc_url_raw( \wp_get_attachment_url( $id ) ),
537 + 'url' => \esc_url( \wp_get_attachment_url( $id ) ),
561 538 'name' => \esc_attr( \get_the_title( $id ) ),
562 539 );
563 540
564 541 // Height and width for videos.
@@ -566,12 +543,9 @@
566 543 $attachment['width'] = \esc_attr( $meta['width'] );
567 544 $attachment['height'] = \esc_attr( $meta['height'] );
568 545 }
569 546
570 - // Use poster image from the block, or fall back to the transformer icon.
571 - if ( ! empty( $media['icon'] ) ) {
572 - $attachment['icon'] = \esc_url_raw( $media['icon'] );
573 - } elseif ( \method_exists( $this, 'get_icon' ) && $this->get_icon() ) {
547 + if ( \method_exists( $this, 'get_icon' ) && $this->get_icon() ) {
574 548 $attachment['icon'] = object_to_uri( $this->get_icon() );
575 549 }
576 550 break;
577 551 }
@@ -617,101 +591,8 @@
617 591 return $image;
618 592 }
619 593
620 594 /**
621 - * Get EXIF metadata for an image attachment using Schema.org exifData property.
622 - *
623 - * Returns an array of PropertyValue objects as defined in FEP-ee3a.
624 - *
625 - * @link https://codeberg.org/fediverse/fep/src/branch/main/fep/ee3a/fep-ee3a.md
626 - *
627 - * @param int $attachment_id The attachment ID.
628 - *
629 - * @return array|null Array of PropertyValue objects or null if no EXIF data available.
630 - */
631 - protected function get_exif_data( $attachment_id ) {
632 - $metadata = \wp_get_attachment_metadata( $attachment_id );
633 -
634 - if ( empty( $metadata['image_meta'] ) ) {
635 - return null;
636 - }
637 -
638 - $image_meta = $metadata['image_meta'];
639 - $exif_data = array();
640 -
641 - // Map WordPress image_meta to FEP-ee3a EXIF field names.
642 - if ( ! empty( $image_meta['created_timestamp'] ) ) {
643 - $exif_data[] = array(
644 - '@type' => 'PropertyValue',
645 - 'name' => 'DateTime',
646 - 'value' => \gmdate( 'Y:m:d H:i:s', (int) $image_meta['created_timestamp'] ),
647 - );
648 - }
649 -
650 - if ( ! empty( $image_meta['shutter_speed'] ) ) {
651 - $shutter_speed = (float) $image_meta['shutter_speed'];
652 - // Format shutter speed as a fraction (e.g., "1/100") for speeds faster than 1 second.
653 - if ( $shutter_speed > 0 && $shutter_speed < 1 ) {
654 - $value = '1/' . \round( 1 / $shutter_speed );
655 - } elseif ( $shutter_speed >= 1 ) {
656 - $value = (string) $shutter_speed;
657 - }
658 - if ( isset( $value ) ) {
659 - $exif_data[] = array(
660 - '@type' => 'PropertyValue',
661 - 'name' => 'ExposureTime',
662 - 'value' => $value,
663 - );
664 - }
665 - }
666 -
667 - if ( ! empty( $image_meta['aperture'] ) ) {
668 - $exif_data[] = array(
669 - '@type' => 'PropertyValue',
670 - 'name' => 'FNumber',
671 - 'value' => 'f/' . (float) $image_meta['aperture'],
672 - );
673 - }
674 -
675 - if ( ! empty( $image_meta['focal_length'] ) ) {
676 - $exif_data[] = array(
677 - '@type' => 'PropertyValue',
678 - 'name' => 'FocalLength',
679 - 'value' => (string) (float) $image_meta['focal_length'],
680 - );
681 - }
682 -
683 - if ( ! empty( $image_meta['iso'] ) ) {
684 - $exif_data[] = array(
685 - '@type' => 'PropertyValue',
686 - 'name' => 'PhotographicSensitivity',
687 - 'value' => (string) (int) $image_meta['iso'],
688 - );
689 - }
690 -
691 - if ( ! empty( $image_meta['camera'] ) ) {
692 - $exif_data[] = array(
693 - '@type' => 'PropertyValue',
694 - 'name' => 'Model',
695 - 'value' => \sanitize_text_field( $image_meta['camera'] ),
696 - );
697 - }
698 -
699 - /**
700 - * Filter the EXIF data for an image attachment.
701 - *
702 - * @param array $exif_data Array of PropertyValue objects for Schema.org exifData.
703 - * @param array $image_meta The WordPress image_meta array.
704 - * @param int $attachment_id The attachment ID.
705 - *
706 - * @return array The filtered EXIF data array.
707 - */
708 - $exif_data = \apply_filters( 'activitypub_image_exif', $exif_data, $image_meta, $attachment_id );
709 -
710 - return ! empty( $exif_data ) ? $exif_data : null;
711 - }
712 -
713 - /**
714 595 * Filter attachments to ensure uniqueness based on their ID.
715 596 *
716 597 * @param array $attachments Array of attachments with 'id' field.
717 598 *
@@ -721,10 +602,10 @@
721 602 $seen_ids = array();
722 603
723 604 return \array_filter(
724 605 $attachments,
725 - static function ( $attachment ) use ( &$seen_ids ) {
726 - if ( isset( $attachment['id'] ) && ! \in_array( $attachment['id'], $seen_ids, true ) ) {
606 + function ( $attachment ) use ( &$seen_ids ) {
607 + if ( isset( $attachment['id'] ) && ! in_array( $attachment['id'], $seen_ids, true ) ) {
727 608 $seen_ids[] = $attachment['id'];
728 609 return true;
729 610 }
730 611 return false;