-
Notifications
You must be signed in to change notification settings - Fork 0
/
alexa-briefing.php
65 lines (54 loc) · 1.67 KB
/
alexa-briefing.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
//namespace Alexa_Quote;
class Alexa_Briefing {
public function briefing_request() {
$responses = [];
// This logic could be both abstracted and used with array_map().
foreach (
get_posts( [
'meta_query' => [
[
'key' => 'alexawp_briefing_source',
'compare' => '!=',
'value' => '',
],
],
'no_found_rows' => true,
'post_status' => 'publish',
'post_type' => 'alexawp-briefing',
'posts_per_page' => 1,
'suppress_filters' => false,
] )
as $post
) {
$response = [
'uid' => get_post_meta( $post->ID, 'alexawp_briefing_uuid', true ),
'updateDate' => get_post_modified_time( 'Y-m-d\TH:i:s.\0\Z', true, $post ),
'titleText' => get_the_title( $post ),
'mainText' => '',
'redirectionUrl' => home_url(),
];
switch ( get_post_meta( $post->ID, 'alexawp_briefing_source', true ) ) {
case 'text' :
$response['mainText'] = get_post_meta( $post->ID, 'alexawp_briefing_text', true );
break;
case 'attachment_id' :
$response['streamUrl'] = wp_get_attachment_url( get_post_meta( $post->ID, 'alexawp_briefing_attachment_id', true ) );
break;
case 'audio_url' :
$response['streamUrl'] = get_post_meta( $post->ID, 'alexawp_briefing_audio_url', true );
break;
}
$response['mainText'] = wp_strip_all_tags( strip_shortcodes( $response['mainText'] ) );
if ( isset( $response['streamUrl'] ) ) {
$response['streamUrl'] = esc_url_raw( $response['streamUrl'] );
}
$responses[] = $response;
}
// Unclear whether an array with a single response is acceptable.
if ( count( $responses ) === 1 ) {
$responses = $responses[0];
}
return $responses;
}
}