-
Notifications
You must be signed in to change notification settings - Fork 1
/
receiver.php
138 lines (117 loc) · 3.76 KB
/
receiver.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
require_once '../../../wp-load.php';
require './twilio.php';
// get settings
$settings = get_option('phonoblogsettings');
$name = get_bloginfo('name');
$url = get_bloginfo('url').'/';
$gather_url = $url.str_replace(ABSPATH, '', __FILE__);
$transcribe_url = $url.dirname(str_replace(ABSPATH, '', __FILE__)).'/transcribe.php';
// check to make sure the number is allowed
if($settings['number'] != $_REQUEST['From']){
header("Content-type: text/xml");
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<Response>
<Reject />
</Response>
<?php
exit;
}
/* Render TwiML */
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response>\n";
switch($_REQUEST['step']) {
case 2: ?>
<pause length="5" />
<Say>Dictate your post then press any key to continue. We're listening.</Say>
<Record transcribe="true" transcribeCallback="<?php echo $transcribe_url.'?type=content'; ?>" maxLength="600" action="<?php echo $gather_url.'?step=3'; ?>" />
<?php
break;
case 3: ?>
<pause length="5" />
<Gather action="<?php echo $gather_url.'?step=4'; ?>" numDigits="1">
<Say>Press 1, to publish your post.</Say>
<Say>Press 2, to save your post as a draft</Say>
</Gather>
<?php
break;
case 4:
if($_REQUEST['Digits'] == 1){
// find post by sid
$sid = $_REQUEST['CallSid'];
$posts = get_posts(array(
'meta_query' => array(
array(
'key' => 'phonoblog_sid',
'value' => $sid,
)
),
'post_status' => 'any',
));
// if the post doesn't exist create one
// and add the post_status meta but leave
// it as a draft since none of the other
// content is in place
if(empty($posts)){
$post = wp_insert_post(array(
'post_title' => 'Pending',
'post_content' => 'Pending',
'post_author' => $settings['user'],
'post_status' => 'draft',
));
add_post_meta($post, 'phonoblog_post_status', 'publish');
add_post_meta($post, 'phonoblog_sid', $sid);
}else{
// if the post exists then get the status
// of the title and content transcriptions
$post = get_object_vars($posts[0]);
$title_status = get_post_meta($post['ID'], 'phonoblog_title_status', true);
$content_status = get_post_meta($post['ID'], 'phonoblog_content_status', true);
// if everything is ready publish the post
if(($title_status && $content_status) && $title_status == 'completed' && $content_status == 'completed'){
$post['post_status'] ='publish';
wp_insert_post($post);
}
// if not add the post status meta so that it can be
// published when everything is ready
add_post_meta($post['ID'], 'phonoblog_post_status', 'publish');
}
}elseif($_REQUEST['Digits'] == 2){
// get post by sid
$sid = $_REQUEST['CallSid'];
$posts = get_posts(array(
'meta_query' => array(
array(
'key' => 'phonoblog_sid',
'value' => $sid,
)
),
'post_status' => 'any',
));
// if post doesn't exist set create it and set
// the status meta
if(empty($posts)){
$post = wp_insert_post(array(
'post_title' => 'Pending',
'post_content' => 'Pending',
'post_author' => $settings['user'],
'post_status' => 'draft',
));
add_post_meta($post, 'phonoblog_post_status', 'publish');
add_post_meta($post, 'phonoblog_sid', $sid);
}else{
// if post exists add the status meta
$post = get_object_vars($posts[0]);
add_post_meta($post['ID'], 'phonoblog_post_status', 'draft');
}
}
break;
default: ?>
<Say>Hello and welcome to <?php echo $name; ?> please tell us the title of your post then press any key to continue.</Say>
<Record transcribe="true" transcribeCallback="<?php echo $transcribe_url.'?type=title'; ?>" maxLength="30" action="<?php echo $gather_url.'?step=2'; ?>" />
<?php
break;
}
?>
</Response>