Skip to content

Commit d087ec1

Browse files
authored
Add Audio, Document, and Video type support to object_to_uri (#2544)
1 parent 24f6cbf commit d087ec1

File tree

3 files changed

+216
-3
lines changed

3 files changed

+216
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: changed
3+
4+
Improve support for media attachments by handling Audio, Document, and Video object types in addition to Images.

includes/functions.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -803,11 +803,13 @@ function object_to_uri( $data ) {
803803

804804
// Return part of Object that makes most sense.
805805
switch ( $type ) {
806-
case 'Image':
807-
// See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-image.
806+
case 'Audio': // See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-audio.
807+
case 'Document': // See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-document.
808+
case 'Image': // See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-image.
809+
case 'Video': // See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-video.
808810
$data = object_to_uri( $data['url'] );
809811
break;
810-
case 'Link':
812+
case 'Link': // See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-link.
811813
$data = $data['href'];
812814
break;
813815
default:

tests/phpunit/tests/includes/class-test-functions.php

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,213 @@ public function object_to_uri_provider() {
231231
),
232232
'https://example.com',
233233
),
234+
// Test Audio with simple string URL.
235+
array(
236+
array(
237+
'type' => 'Audio',
238+
'url' => 'https://example.com/audio.mp3',
239+
),
240+
'https://example.com/audio.mp3',
241+
),
242+
// Test Audio with Link object.
243+
array(
244+
array(
245+
'type' => 'Audio',
246+
'url' => array(
247+
'type' => 'Link',
248+
'href' => 'https://example.com/audio.mp3',
249+
),
250+
),
251+
'https://example.com/audio.mp3',
252+
),
253+
// Test Audio with array of Link objects.
254+
array(
255+
array(
256+
'type' => 'Audio',
257+
'url' => array(
258+
array(
259+
'type' => 'Link',
260+
'href' => 'https://example.com/audio.mp3',
261+
'mediaType' => 'audio/mpeg',
262+
),
263+
array(
264+
'type' => 'Link',
265+
'href' => 'https://example.com/audio.ogg',
266+
'mediaType' => 'audio/ogg',
267+
),
268+
),
269+
),
270+
'https://example.com/audio.mp3',
271+
),
272+
// Test Document with simple string URL.
273+
array(
274+
array(
275+
'type' => 'Document',
276+
'url' => 'https://example.com/document.pdf',
277+
),
278+
'https://example.com/document.pdf',
279+
),
280+
// Test Document with Link object.
281+
array(
282+
array(
283+
'type' => 'Document',
284+
'url' => array(
285+
'type' => 'Link',
286+
'href' => 'https://example.com/document.pdf',
287+
),
288+
),
289+
'https://example.com/document.pdf',
290+
),
291+
// Test Document with array of Link objects.
292+
array(
293+
array(
294+
'type' => 'Document',
295+
'url' => array(
296+
array(
297+
'type' => 'Link',
298+
'href' => 'https://example.com/document.pdf',
299+
'mediaType' => 'application/pdf',
300+
),
301+
array(
302+
'type' => 'Link',
303+
'href' => 'https://example.com/document.docx',
304+
'mediaType' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
305+
),
306+
),
307+
),
308+
'https://example.com/document.pdf',
309+
),
310+
// Test Video with simple string URL.
311+
array(
312+
array(
313+
'type' => 'Video',
314+
'url' => 'https://example.com/video.mp4',
315+
),
316+
'https://example.com/video.mp4',
317+
),
318+
// Test Video with Link object.
319+
array(
320+
array(
321+
'type' => 'Video',
322+
'url' => array(
323+
'type' => 'Link',
324+
'href' => 'https://example.com/video.mp4',
325+
),
326+
),
327+
'https://example.com/video.mp4',
328+
),
329+
// Test Video with array of Link objects.
330+
array(
331+
array(
332+
'type' => 'Video',
333+
'url' => array(
334+
array(
335+
'type' => 'Link',
336+
'href' => 'https://example.com/video.mp4',
337+
'mediaType' => 'video/mp4',
338+
),
339+
array(
340+
'type' => 'Link',
341+
'href' => 'https://example.com/video.webm',
342+
'mediaType' => 'video/webm',
343+
),
344+
),
345+
),
346+
'https://example.com/video.mp4',
347+
),
348+
// Test complex Image with array of Link objects (user's example).
349+
array(
350+
array(
351+
'@context' => 'https://www.w3.org/ns/activitystreams',
352+
'type' => 'Image',
353+
'name' => 'Cat Jumping on Wagon',
354+
'url' => array(
355+
array(
356+
'type' => 'Link',
357+
'href' => 'http://example.org/image.jpeg',
358+
'mediaType' => 'image/jpeg',
359+
),
360+
array(
361+
'type' => 'Link',
362+
'href' => 'http://example.org/image.png',
363+
'mediaType' => 'image/png',
364+
),
365+
),
366+
),
367+
'http://example.org/image.jpeg',
368+
),
369+
// Test complex Audio with full metadata and array of Link objects.
370+
array(
371+
array(
372+
'@context' => 'https://www.w3.org/ns/activitystreams',
373+
'type' => 'Audio',
374+
'name' => 'Podcast Episode',
375+
'duration' => 'PT1H30M',
376+
'attributedTo' => 'https://example.com/users/podcaster',
377+
'url' => array(
378+
array(
379+
'type' => 'Link',
380+
'href' => 'https://example.com/podcast.mp3',
381+
'mediaType' => 'audio/mpeg',
382+
),
383+
array(
384+
'type' => 'Link',
385+
'href' => 'https://example.com/podcast.ogg',
386+
'mediaType' => 'audio/ogg',
387+
),
388+
),
389+
),
390+
'https://example.com/podcast.mp3',
391+
),
392+
// Test complex Document with full metadata and array of Link objects.
393+
array(
394+
array(
395+
'@context' => 'https://www.w3.org/ns/activitystreams',
396+
'type' => 'Document',
397+
'name' => 'Annual Report',
398+
'attributedTo' => 'https://example.com/users/author',
399+
'url' => array(
400+
array(
401+
'type' => 'Link',
402+
'href' => 'https://example.com/report.pdf',
403+
'mediaType' => 'application/pdf',
404+
),
405+
array(
406+
'type' => 'Link',
407+
'href' => 'https://example.com/report.docx',
408+
'mediaType' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
409+
),
410+
),
411+
),
412+
'https://example.com/report.pdf',
413+
),
414+
// Test complex Video with full metadata and array of Link objects.
415+
array(
416+
array(
417+
'@context' => 'https://www.w3.org/ns/activitystreams',
418+
'type' => 'Video',
419+
'name' => 'Conference Talk',
420+
'duration' => 'PT45M',
421+
'attributedTo' => 'https://example.com/users/speaker',
422+
'url' => array(
423+
array(
424+
'type' => 'Link',
425+
'href' => 'https://example.com/talk.mp4',
426+
'mediaType' => 'video/mp4',
427+
'width' => 1920,
428+
'height' => 1080,
429+
),
430+
array(
431+
'type' => 'Link',
432+
'href' => 'https://example.com/talk.webm',
433+
'mediaType' => 'video/webm',
434+
'width' => 1920,
435+
'height' => 1080,
436+
),
437+
),
438+
),
439+
'https://example.com/talk.mp4',
440+
),
234441
);
235442
}
236443

0 commit comments

Comments
 (0)